Publish and install Python packages (CLI)

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

Azure Artifacts enables developers to manage their dependencies from a single feed. You can publish and install Python packages to and from your feed using the command line. In this article, you learn how to:

  • Create an new feed.
  • Publish Python packages to a feed.
  • Install Python packages from a feed.

Prerequisites

Create a feed

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

  2. Select Artifacts, and then select Create Feed.

  3. Provide a Name for your feed, choose the Visibility option that defines who can view your packages, check Include packages from common public sources if you want to include packages from sources like nuget.org or npmjs.com, and for Scope, decide whether the feed should be scoped to your project or the entire organization.

  4. Select Create when you're done.

    Screenshot that shows selections for creating a new feed in Azure DevOps Services.

  1. Sign in to your Azure DevOps server, and then go to your project.

  2. Select Artifacts, and then select Create Feed.

  3. Provide a Name for your feed, choose the Visibility option that defines who can view your packages, check Include packages from common public sources if you want to include packages from sources like nuget.org or npmjs.com, and for Scope, decide whether the feed should be scoped to your project or the entire organization.

  1. Select Create when you're done.

    Screenshot that shows selections for creating a new feed in Azure DevOps 2022.

  1. Select Create when you're done.

    Screenshot that shows selections for creating a new feed in Azure DevOps 2020.

  1. Sign in to your Azure DevOps server, and then go to your project.

  2. Select Artifacts, and then select New feed.

  3. For Name, enter a descriptive name for your feed.

    For Visibility, select an option to indicate who can view packages within the feed.

    If you want to include packages from public sources, select the Use packages from public sources through this feed option.

  4. Select Create when you're done.

    Screenshot that shows selections for creating a new feed in Azure DevOps 2019.

Note

By default, newly created feeds have their project's Build Service value set to Feed and Upstream Reader (Collaborator).

Publish packages

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

  2. Select Artifacts, and then select Connect to feed.

  3. Select twine from the left navigation area. If this is your first time using Azure Artifacts with twine, make sure to install the prerequisites by selecting Get the tools and following the provided steps.

  4. Add a .pypirc file to your home directory and paste the provided snippet into it. Your file should look similar to the following snippet. If you already have a .pypirc that contains credentials for the public PyPI index, we recommend removing the [pypi] section to avoid accidentally publishing private packages to PyPI.

    [distutils]
    Index-servers =
    FEED_NAME
    
    [FEED_NAME]
    Repository = https://pkgs.dev.azure.com/ORGANIZATION_NAME/PROJECT_NAME/_packaging/FEED_NAME/pypi/upload/
    
  5. Run the following command in your project directory to create source and wheel distributions.

    python setup.py sdist bdist_wheel
    
  6. Run the following command to publish your package. Use the -r REPOSITORY_NAME flag to ensure your private packages are not accidentally published to PyPI.

    twine upload -r REPOSITORY_NAME dist/*
    

Important

You must have twine 1.13.0 or higher to use artifacts-keyring. See Usage requirements for more details.

Install packages

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

  2. Select Artifacts, and then select Connect to feed.

  3. Select pip from the left navigation area. If this is your first time using Azure Artifacts with pip, make sure to install the prerequisites by selecting Get the tools and following the provided steps.

  4. Create a virtual environment.

  5. Add a pip.ini (Windows) or pip.conf (Mac/Linux) file to your virtualenv and paste the provided snippet into it. Your file should look similar to the following snippet:

    [global]
    index-url=https://pkgs.dev.azure.com/ORGANIZATION_NAME/PROJECT_NAME/_packaging/FEED_NAME/pypi/simple/
    
  6. Run this command in your project directory to install your packages:

    pip install
    

Important

You must have pip 19.2 or higher to use artifacts-keyring. See Usage requirements for more details.