Skip to content

Latest commit

 

History

History
138 lines (89 loc) · 4.4 KB

python-packages.md

File metadata and controls

138 lines (89 loc) · 4.4 KB
title description ms.service ms.topic ms.date monikerRange ms.custom recommendations
Get started with Python packages in Azure Artifacts
Learn how to set up your project and manage your Python packages in Azure Artifacts.
azure-devops-artifacts
quickstart
12/03/2024
<=azure-devops
devx-track-python, py-fresh-zinc, engagement-fy23
true

Get started with Python packages in Azure Artifacts

[!INCLUDE version-gt-eq-azure-devops-2019]

Using Azure Artifacts, you can publish and download packages from feeds and public registries such as PyPi. This quickstart will guide you through creating a feed, configuring your project, and managing Python packages in your Azure Artifacts feed. In this article, you learn how to:

[!div class="checklist"]

  • Create a new feed.
  • Authenticate with your feed.
  • Publish Python packages.
  • Install packages from your feed.

Prerequisites

Get the code

  1. If you don't have your own Python project, you can use the following sample Python project:

    https://github.com/microsoft/python-package-template
    
  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 use this command to build your package:

    python setup.py sdist bdist_wheel
    

Create a feed

[!INCLUDE ]

Connect to a 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. Select twine under the Python section.

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

  5. Add a pypirc file to your home directory and paste the provided snippet. 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 contains credentials for the public PyPI index, we recommend removing the [pypi] section to prevent accidental publication of private packages to PyPI.

  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. Select pip under the Python section.

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

  5. Create a virtual environment.

  6. Add a pip.ini file (Windows) or pip.conf file (Mac/Linux) to your virtual environment and paste the provided snippet into it. Your file should resemble the following:

    [global]
    index-url=https://pkgs.dev.azure.com/ORGANIZATION_NAME/PROJECT_NAME/_packaging/FEED_NAME/pypi/simple/
    

Publish packages

  1. Run this command in your project directory to create source and wheel distributions:

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

    twine upload -r <FEED_NAME> dist/*
    

Install packages

  1. Run this command in your project directory to install your packages:

    pip install
    
  2. To install a specific package, run the following command, replacing the placeholder with the package name from your feed.

    pip install <PACKAGE_NAME>

Next steps

[!div class="nextstepaction"] Use packages from Python package index (PyPI) Set up upstream sources Publish Python packages with Azure Pipelines