Packaging python packages with Poetry

Poetry is a tool for dependency management and packaging in Python. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.


  1. Install with windows powershell

    PS C:\Users> (Invoke-WebRequest -Uri -UseBasicParsing).Content | python -
    Retrieving Poetry metadata
    This installer is deprecated. Poetry versions installed using this script will not be able to use 'self update' command to upgrade to 1.2.0a1 or later.
    # Welcome to Poetry!
    This will download and install the latest version of Poetry,
    a dependency and package manager for Python.
    It will add the `poetry` command to Poetry's bin directory, located at:
    This path will then be added to your `PATH` environment variable by
    modifying the `HKEY_CURRENT_USER/Environment/PATH` registry key.
    You can uninstall at any time by executing this script with the --uninstall option,
    and these changes will be reverted.
    Installing version: 1.1.10
      - Downloading poetry-1.1.10-win32.tar.gz (41.47MB)
    Poetry (1.1.10) is installed now. Great!
    To get started you need Poetry's bin directory (%USERPROFILE%\.poetry\bin) in your `PATH`
    environment variable. Future applications will automatically have the
    correct environment, but you may need to restart your current shell.
  2. Verify

    PS C:\Users> poetry --version
    Poetry version 1.1.10

Basic Usage

  1. Create a new project

    PS E:\> poetry new jenkins-tool
    Created package jenkins_tool in jenkins-tool
    PS E:\> tree .\jenkins-tool\ /F
    文件夹 PATH 列表
    卷序列号为 4428-676B
    │  pyproject.toml
    │  README.rst
  1. Copy script to jenkins_tool/jenkins_tool

  2. Update pyproject.toml

    name = "jenkins-tool"
    version = "0.1.0"
    description = "Manage Jenkins Job"
    authors = ["yongfeiuall <>"]
    python = "^3.6"
    requires = ["poetry-core>=1.0.0"]
    build-backend = "poetry.core.masonry.api"
    jt = "jenkins_tool.client:main"
  3. Build

    PS E:\jenkins-tool> poetry build
    Creating virtualenv jenkins-tool-vo3-Lls6-py3.6 in C:\Users\AppData\Local\pypoetry\Cache\virtualenvs
    Building jenkins-tool (0.1.0)
      - Building sdist
      - Built jenkins-tool-0.1.0.tar.gz
      - Building wheel
      - Built jenkins_tool-0.1.0-py3-none-any.whl


  1. Unzip jenkins-tool-0.1.0.tar.gz

  2. Install PS E:\jenkins-tool\dist\jenkins-tool-0.1.0> python .\ install

  3. Verify

    PS E:\jenkins-tool\dist\jenkins-tool-0.1.0> jt -h
    usage: jt [-h] [-v] [-V VIEW_NAME]
    Manage Jenkins Job
    optional arguments:
      -h, --help            show this help message and exit
      -v, --version         Show version
      -V VIEW_NAME, --view VIEW_NAME
                            Get Jenkins job last build number by view
唐胡璐 wechat