Publish and consume Python packages from the command line

Azure DevOps Services | Azure DevOps Server 2019 | Azure DevOps Server 2020

With Azure Artifacts, you can publish and consume packages from Azure Artifacts feeds as well as public registries such as pypi.org. Follow this quickstart to learn how to publish and consume Python packages using the command line.

Publish Python packages

To publish a Python package to your feed, follow these steps:

  1. Install the latest version of Azure Artifacts keyring

    pip install twine keyring artifacts-keyring
    
  2. Add a .pypirc configuration file to your home directory

    touch ~/.pypirc
    
  3. Add the following content to your .pypirc file

    [distutils]
    Index-servers =
      <organizationName>
    
    [<organizationName>]
    Repository = https://pkgs.dev.azure.com/<organizationName>/_packaging/<feedName>/pypi/upload
    
  4. Create a source and a wheel distributions

    python setup.py sdist bdist_wheel
    
  5. Run the following command to publish your package

    twine upload -r <organizationName> dist/*
    

Consume Python packages

To install a Python package from the command line, follow these steps:

  1. Update your Python package installer

    python -m pip install --upgrade pip
    
  2. Ensure you have the latest version of Azure Artifacts keyring

    pip install twine keyring artifacts-keyring
    
  3. Create a virtual environment if you don't have one already

  4. Add a pip.ini (Windows) or pip.conf (Mac/Linux) configuration file to your virtual environment

    [global]
    extra-index-url=https://pkgs.dev.azure.com/<organizationName>/_packaging/<feedName>/pypi/simple/
    
  5. Run the following command in your project directory to install your package

    pip install <package>