Publish and consume Python packages using the command line

Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019 | TFS 2018

Azure Artifacts enables developers publishing and consuming packages from Azure Artifacts feeds and public registries like pypi.org. By following this quickstart guide, you can learn how to use the command line to publish and consume Python packages.

Publish Python packages

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Artifacts and then select your feed from the dropdown menu.

  3. Select Connect to feed and then select twine from the left navigation panel.

  4. If this is your first time using Azure Artifacts with twine, select Get the tools to install the prerequisites.

  5. Download and install Python, and then run the following command to install the latest version of Azure Artifacts keyring.

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

    touch ~/.pypirc
    

    Note

    If you already have a .pypirc file with credentials for the public PyPI index, it is recommended to remove the [pypi] section from your file to prevent unintended publication of private packages.

  7. Paste the following snippet to your .pypirc file:

    [distutils]
    Index-servers =
      <FEED_NAME>
    
    [<FEED_NAME>]
    Repository = https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/PROJECT_NAME/_packaging/<FEED_NAME>/pypi/upload/
    
  8. Create a source and wheel distributions.

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

    twine upload -r <FEED_NAME> dist/*
    

Consume Python packages

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Artifacts and then select your feed from the dropdown menu.

  3. Select Connect to feed and then select pip from the left navigation panel.

  4. If this is your first time using Azure Artifacts with pip, select Get the tools to install the prerequisites.

  5. Download and install Python, and then run the following command to update your Python package installer.

    python -m pip install --upgrade pip
    
  6. Install the latest Azure Artifacts keyring.

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

  8. Add a pip.ini (Windows) or pip.conf (Mac/Linux) configuration file to your virtualenv.

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

    pip install <PACKAGE_NAME>