Chainguard Libraries for Python
Learning Lab for June 2025 on Chainguard Libraries for Python and Supply Chain Security
The configuration for the use of Chainguard Libraries depends on how you’ve set up your build tools and CI/CD workflows. At a high level, adopting the use of Chainguard Libraries in your development, build, and deployment workflows involves the following steps:
These changes must be performed on all workstations of individual developers and other engineers running relevant application builds. They must also be performed on any build tool such as Jenkins, TeamCity, GitHub Actions, or other infrastructure that draws in dependencies.
To configure any build tool, you must first access credentials from your organization’s repository manager or for direct access.
The following steps allow you to determine the URL and authentication details for accessing your organization’s Cloudsmith repository manager.
https://dl.cloudsmith.io/.../exampleorg/python-all/python/simple/
. In the
URL ...
is replaced with a default token or your personal token depending
on your selection and exampleorg
is replaced with the name of your
organization. The URL contains both the name of the repository python-all
as well as python
as an identifier for the format.https://username:{{apiKey}}@dl.cloudsmith.io/basic/exampleorg/python-all/python/simple/
.
Replace username
and exampleorg
with your Cloudsmith details and replace
{{apiKey}}
with the API key from the Personal API Keys section from the
drop down on your username.Note that for use with build tools you must include the simple/
context so that
the package index is used successfully.
The following steps allow you to determine the identity token and URL for accessing your organization’s JFrog Artifactory repository manager.
https://exampleorg.jfrog.io/artifactory/python-all
with
exampleorg
. Note that for use with build tools you must append simple/
to
the URL so that the package index is used successfully -
https://exampleorg.jfrog.io/artifactory/python-all/simple/
.The following steps allow you to determine the URL and authentication details for accessing your organization’s Sonatype Nexus repository group.
https://repo.example.com/repository/python-all/
. Note that for use with
build tools you must append simple/
to the URL so that the package index is
used successfully - https://repo.example.com/repository/python-all/simple/
.The build configuration to retrieve artifacts directly from the Chainguard Libraries for Python repositories requires authentication with username and password from a pull token as detailed in access documentation. Note that there are multiple repositories:
https://libraries.cgr.dev/python/
with the simple index at https://libraries.cgr.dev/python/simple
https://libraries.cgr.dev/python-remediated
with the simple index at https://libraries.cgr.dev/python-remediated/simple
Once you have credentials and the index URL from your organization’s repository manager, you’re ready to set up specific build tools for local development or CI/CD.
pip, uv, poetry, and other Python build and packaging tools have dedicated support for configuring authentication to the repository manager or the Chainguard Libraries for Python directly. As an alternative that works across tools and is often preferred, use .netrc for authentication.
The pip tool is the most widely used utility
for installing Python packages. In this section, we use the credentials from
your organization’s repository manager to configure pip
to ingest dependencies
from Chainguard Libraries.
First, let’s clear your local pip
cache to ensure that packages are sourced
from Chainguard Libraries for Python:
pip cache purge
To update pip
to use our repository manager’s URL globally, create or edit
your ~/.pip/pip.conf
file. You may need to create the ~/.pip
folder as
well. For example:
mkdir -p ~/.pip
nano ~/.pip/pip.conf
Update this configuration file with the following, replacing <repository-url>
with the URL provided by your repository manager including the simple/
context:
[global]
index-url = <repository-url>
Updating this global configuration affects all projects built on the
workstation. Alternately, if your project uses a requirements.txt
file in
projects, you can add the following to it to configure on a project-by-project
basis:
--index-url <repository-url>
package-name==version
Note the different syntax for index-url
in the two files.
Refer to the official documentation for configuring authentication with pip if you are not using .netrc for authentication.
When using direct access to the Chainguard Libraries for
Python repository with pip
, you must ensure the following are set in your
configuration file:
/
in the username value CG_PULLTOKEN_USERNAME
with _
.simple
context is used for the URL.CG_PULLTOKEN_PASSWORD
remains unchanged.Example for requirements.txt
:
--index-url https://CG_PULLTOKEN_USERNAME:CG_PULLTOKEN_PASSWORD@libraries.cgr.dev/python/simple/
Example for ~/.pip/pip.conf
:
[global]
index-url = https://CG_PULLTOKEN_USERNAME:CG_PULLTOKEN_PASSWORD@libraries.cgr.dev/python/simple/
Note that pip
does not support installing Python libraries from multiple
repositories while prioritizing one over another. If you are using pip
and prefer to pull from multiple repositories while prioritizing Chainguard
Libraries for Python, we recommend using a repository manager. Alternatively,
other Python package managers below provide support for index priority
resolution behavior.
Poetry helps you declare, manage, and install dependencies of Python projects, and can be used with Chainguard Libraries for Python."
List the Python package caches used by your Poetry project:
poetry cache list
The following commands clear the default cache, the cache for a repository named
pypi
, and the cache of packages of the repo python-all
from your repository
manager as configured in the global
configuration:
poetry cache clear --all _default_cache
poetry cache clear --all pypi
poetry cache clear --all python-all
Set up HTTP authentication to the repository python-all
on your repository
manager with the username example
and the password secret
in your project
directory:
poetry config http-basic.python-all example secret
The authentication is used for the python-all
repository that you add to the
pyproject.toml
with the following command:
poetry source add python-all https://repo.example.com/../python-all/simple/
Example URLs including the required simple
context:
https://example.jfrog.io/artifactory/api/pypi/python-all/simple/
https://repo.example.com:8443/repository/python-all/simple/
The following configuration is added:
[[tool.poetry.source]]
name = "python-all"
url = "https://repo.example.com/../python-all/simple/"
priority = "primary"
Trigger a new download of the dependencies:
poetry install
If necessary, you can fix or even regenerate your poetry.lock
file:
poetry lock
poetry lock --regenerate
Proceed to build your project:
poetry build
For direct access to Chainguard Libraries for Python with
Poetry, use your username CG_PULLTOKEN_USERNAME
and password
CG_PULLTOKEN_PASSWORD
values from the pull token creation and the URL with the
simple context https://libraries.cgr.dev/python/simple/
:
poetry config http-basic.chainguard CG_PULLTOKEN_USERNAME CG_PULLTOKEN_PASSWORD
The authentication is used for the chainguard
repository that you add to the
pyproject.toml
with the following command:
poetry source add chainguard https://libraries.cgr.dev/python/simple/
The Poetry documentation contains more information about your project build, dependencies, versions, and other aspects.
In order to install Python libraries from multiple repositories with Chainguard Libraries
for Python as the priority, poetry
supports setting a primary package source.
You can use this to configure Chainguard Libraries for Python as the first choice for any
library access, with a fallback to the PyPI public index.
uv is a fast Python package and project manager written in Rust. It uses PyPI by default, but also supports the use of alternative package indexes.
To update your global configuration to use your organization’s repository
manager with uv
, create or edit the ~/.config/uv/uv.toml
configuration file.
You may also need to create the ~/.config/uv/
folder first. For example:
mkdir -p ~/.config/uv
nano ~/.config/uv/uv.toml
Add the following to your uv
global configuration file:
[[tool.uv.index]]
name = "<repository-manager-name>"
url = "<repository-url>"
Add the name for your repository, such as corppypi
, within the quotes.
Replace the <repository-url>
with the URL provided by your repository manager
including the simple/
context.
Note that updating the global configuration affects all projects built on the
workstation. Alternately, you can update each project by adding the same
configuration in pyproject.toml
.
Refer to the official documentation for configuring authentication with uv and using alternative package indexes if you are not using .netrc for authentication.
For direct access to Chainguard Libraries for Python with
uv, use .netrc or your username CG_PULLTOKEN_USERNAME
and password
CG_PULLTOKEN_PASSWORD
values from the pull token creation and the URL with the
simple context https://libraries.cgr.dev/python/simple/
:
Example for pyproject.toml
:
[[tool.uv.index]]
name = "chainguard"
url = "https://CG_PULLTOKEN_USERNAME:CG_PULLTOKEN_PASSWORD@libraries.cgr.dev/python/simple/
Example for uv.toml
:
[[index]]
url = "https://CG_PULLTOKEN_USERNAME:CG_PULLTOKEN_PASSWORD@libraries.cgr.dev/python/simple/
In order to install Python libraries from multiple repositories with Chainguard Libraries
for Python as the priority, uv
supports searching across multiple indexes
while setting a priority index. You can use this to configure Chainguard Libraries for
Python as the first choice for any library access, with a fallback to the PyPI public index.
In addition, if you are consuming from our remediated Python libraries index, we recommend setting the index-strategy setting to unsafe-best-match
. This will ensure that index resolution continues to work when remediated libraries have dependencies on non-remediated libraries.
Last updated: 2025-04-07 14:11