Edit

Share via


Publish and download Python packages with Azure Artifacts

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

Using Azure Artifacts, you can publish and download packages from feeds and public registries such as PyPi. This quickstart guides you through creating a feed, configuring your project, and managing Python packages in your Azure Artifacts feed.

Prerequisites

Product Requirements
Azure DevOps - An Azure DevOps organization.
- An Azure DevOps project.
- Download and install Python.

Get the code

  1. If you don't have your own Python project, you can use the following sample Python project. Otherwise, you can skip to the next section:

    https://github.com/Azure-Samples/azure-stack-hub-flask-hello-world
    
  2. To build your wheel and source distribution, run the following commands in your project directory:

    pip install --upgrade build
    python -m build
    
  3. If your Python project has a setup.py file, you can also build your package using:

    python setup.py sdist bdist_wheel
    

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.

Note

By default, the Build Service for the project (for example: projectName Build Service (orgName)) is assigned the Feed and Upstream Reader (Collaborator) role when a new feed is created.

Connect to your feed

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

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

  3. Under the Python section, select twine.

  4. If this is your first time using Azure Artifacts with twine, select Get the tools and follow the instructions to download Python and install Twine and the artifacts keyring.

  5. Create a pypirc file in your home directory and paste the snippet provided in the Project setup section. Your file should look like this:

    [distutils]
    Index-servers =
        FEED_NAME
    
    [FEED_NAME]
    Repository = https://pkgs.dev.azure.com/ORGANIZATION_NAME/PROJECT_NAME/_packaging/FEED_NAME/pypi/upload/
    

Note

If your .pypirc file already includes credentials for the public PyPI index, we recommend removing the [pypi] section to avoid accidentally publishing private packages to PyPI.

Publish packages to your feed

  1. In your project directory, run the following command to create source and wheel distributions:

    python setup.py sdist bdist_wheel
    
    
  2. To publish your package, use the command below. Be sure to use the -r FEED_NAME flag to avoid accidentally publishing to PyPI:

    twine upload -r <FEED_NAME> dist/*
    

Install packages from your feed

  1. To install packages from your feed, run the following command in your project directory:

    pip install
    
  2. To install a specific package, replace the placeholder with the package name from your feed:

    pip install <PACKAGE_NAME>