Get started with Python packages in Azure Artifacts

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

This guide will walk you through using Azure Artifacts to publish and consume Python packages to and from your feed.

Create a feed

  1. Select Artifacts, and then select Create Feed.

    Create a feed button

  2. Give your feed a Name and choose its visibility (who can view packages in this feed), upstream sources, and scope (project-scoped or organization-scoped) settings.

    New feed dialog box

  3. Select Create when you're done.

Note

By default, the Project Collection Build Service (org-scoped) and the project-level Build Service (project-scoped) are set to Collaborator when you create a new feed.

Azure Artifacts comes pre-installed in TFS 2018. If this is the first time using your feed, you might be asked to assign a license

  1. Go to Build & Release and select Packages.

    Go to Azure Artifacts TFS

  2. Select + New feed.

    New feed button TFS

  3. Give your feed a Name, a Description, and set up who can read, who can contribute and if you want to Include external packages.

    New feed dialog box TFS

  4. Select Create when you're done.

Connect to feed

There are two primary ways to connect to a feed to publish or consume your Python packages:

  1. Install and use the artifacts-keyring package, which will automatically set up authentication for you.
  2. Manually set up credentials for your pip.ini/pip.conf for pushes, and .pypirc for pulls with a personal access token (PAT).

Note

artifacts-keyring is not supported on newer versions of Ubuntu.

Use artifacts-keyring to set up authentication

The artifacts-keyring package allows you to set up authentication to publish and consume your Python packages to and from your feed. Both pip and twine use the Python keyring library to find credentials.

Important

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

  1. In an elevated command prompt window, run the following command to install the artifacts-keyring package:

    pip install artifacts-keyring
    
  2. To install a package from your feed, run the following command:

    • Project scoped feed:

      pip install <PACKAGE_NAME> --index-url https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/pypi/simple
      
    • Organization scoped feed:

      pip install <PACKAGE_NAME> --index-url https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/_packaging/<FEED_NAME>/pypi/simple
      
  3. To publish a package to your feed, run the following command:

    • Project scoped feed:

      twine upload --repository-url https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/pypi/upload
      
    • Organization scoped feed:

      twine upload --repository-url https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/_packaging/<FEED_NAME>/pypi/upload
      

Note

The artifacts-keyring package is layered on top of the Azure Artifacts Credential Provider. For more advanced configuration options, check out the artifacts-credprovider repository.

Manually configure authentication

  1. Create a Personal access token with Packaging > Read scope to authenticate with Azure DevOps.

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

    A screenshot highlighting the connect to feed button.

  3. Select pip under the Python section.

    A screenshot highlighting the pip package type.

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

  5. Create a virtualenv, if you don't already have one.

  6. Add a pip.ini (Windows) or a pip.conf (Mac/Linux) file to your virtualenv. Make sure you don't check your personal access token into a public repository.

    • Project scoped feed:

      [global]
      extra-index-url=https://<FEED_NAME>:<YOUR_PERSONAL_ACCESS_TOKEN>@pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/pypi/simple/
      
    • Organization scoped feed:

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

    pip install <PACKAGE_NAME>
    

When you connect to Azure DevOps for the first time, you'll be prompted for credentials. Enter your user name(any string) and your personal access token in the appropriate fields. The credentials will be cached locally and used to automatically sign you in the next time you use the service.

Note

If you want to publish or consume your packages using Azure Pipelines, use the Python Pip Authenticate task to authenticate and install packages, or the Python Twine Upload Authenticate task to publish your packages.