Skip to content

Install Python packages from CloudRepo

pip reads CloudRepo like any other Python package index: give it the repository’s index URL, put the token in ~/.netrc, and install. This page covers installing packages from a repository. To upload packages, see Publish Python packages.

You need a Python repository and a repository token that reaches it. If you have neither yet: create a repository and create a token. A token that has Download packages access is enough to install.

Used on this page only, never saved. Never enter a token or password here.

pip finds the credential for the index’s host in ~/.netrc, so the index URL carries none. The login is the email address of the account that created the token, and the password is the token. Keep the file readable by you alone (chmod 600 ~/.netrc):

~/.netrc
machine your-org.mycloudrepo.io
login you@example.com
password YOUR_REPOSITORY_TOKEN

Then give pip the index URL. On Windows the file is pip.ini.

~/.config/pip/pip.conf
[global]
index-url = https://your-org.mycloudrepo.io/repositories/your-repo/simple/

The index URL is https://<organization>.mycloudrepo.io/repositories/<repository>/simple/: your organization’s name, then the repository’s name as the admin portal shows it. Without /simple/ the URL answers the same index.

The pip.conf makes CloudRepo pip’s default index for every install. If a project installs public packages too, do not set index-url globally: use the three-step install below, which names CloudRepo only where it is needed.

To use the index for one command or one shell, or in CI, set PIP_INDEX_URL instead of writing a file. In CI, write the ~/.netrc entry above from your secret store first:

Terminal
export PIP_INDEX_URL="https://your-org.mycloudrepo.io/repositories/your-repo/simple/"
pip install my-package

Expected: pip downloads my-package from your-org.mycloudrepo.io and prints Successfully installed.

Install private and public packages together

Section titled “Install private and public packages together”

Install your private packages from CloudRepo alone. Anyone can publish a package on PyPI under your private package’s name, and an install that can read PyPI as well may install theirs instead.

These steps assume pip’s default index is PyPI, so they do not use the index-url in the pip.conf above, or PIP_INDEX_URL in your shell. Step 2’s requirements file names CloudRepo itself. With a global index-url, step 1 would read CloudRepo instead of PyPI, and a hosted repository holds no public package.

pip cannot tie a package to a specific index. If you give it a second index (--extra-index-url, extra-index-url in pip.conf, or PIP_EXTRA_INDEX_URL), pip checks both together and installs the highest version it finds. An exact == pin does not help when both indexes have that version. Instead, install in three steps, using one index at a time, in this order:

  1. Public packages, from PyPI (pip’s default index).
  2. Private packages, from CloudRepo and nothing else.
  3. Your own project, last, without its dependencies (steps 1 and 2 installed them).
Terminal
pip install -r requirements.txt
pip install -r requirements-private.txt
pip install --no-deps -e .
requirements-private.txt
--index-url https://your-org.mycloudrepo.io/repositories/your-repo/simple/
acme-ml-core==3.2.1
acme-feature-pipeline==2.0.0
  • The --index-url line makes CloudRepo the only index for that command. Use the repository that hosts your private packages, not one that proxies PyPI. pip reads the login for the host from the ~/.netrc entry above, so the file holds no credential and is safe to commit.
  • Nothing step 1 installs may depend on a private package, your own project included: pip would fetch that private package from PyPI in step 1. Keep private package names, and . or -e ., out of requirements.txt.
  • Step 3 builds your project in an isolated environment that pip fills from PyPI. If [build-system] requires names a private package, put it in requirements-private.txt, put the public build requirements (such as setuptools) in requirements.txt, and run step 3 as pip install --no-deps --no-build-isolation -e ..
  • List the public packages that your private packages depend on in requirements.txt. Step 2 then finds them installed. If one is missing, step 2 fails rather than looking for it on PyPI.

Hashes protect something else. With pip install --require-hashes -r requirements.txt, pip installs only files whose SHA-256 you recorded, so a file published later under the same name and version is refused, whichever index serves it. Hashes do not choose the index: with two indexes the install can stop with a hash error instead of installing your copy. Record them from an install that read CloudRepo alone for your private packages, because a hash taken from PyPI’s copy protects PyPI’s copy.

The simplest setup is one index for everything. A PyPI group (early access) gives pip one index URL for your hosted repositories and a proxy repository of PyPI. pip then reads one index for every name, so it has no second index to compare.

A PyPI group gives pip one index URL for several of your Python repositories: your hosted repositories and proxy repositories of PyPI. pip installs packages held by the group’s hosted repositories, and public PyPI packages, from that one URL. PyPI groups are in early access.

See Group repository in the glossary for how a group chooses which repository serves a package.

Create the group. In the admin portal, create a repository with Python as the Format and Group as the Kind. Open the group’s settings and choose Manage Group Members: your hosted and proxy Python repositories are listed. Turn on Is Member for each repository the group should serve. A group holds at most 10 repositories. To install public packages through the group, include a proxy repository of PyPI. If two of your hosted repositories hold the same package name, the one with the lowest Priority number serves it.

Point pip at the group. The group’s index URL is its repository URL with /simple/ added, as the group’s Connect page shows. Use it where the repository’s URL went above. The ~/.netrc entry above covers it, because the host is the same.

~/.config/pip/pip.conf (group)
[global]
index-url = https://your-org.mycloudrepo.io/repositories/pypi-group/simple/

Here the group is named pypi-group; put your group’s name in the URL. Then install, as before:

Terminal
pip install my-package requests

Expected: pip installs my-package from your hosted repository and requests from PyPI, both through the group’s one URL.

A group takes a repository token. Create the token as Repository tokens shows, and tick the group. Through the group’s URL, the token reads the group’s current repositories, read only. A repository’s own address needs that repository ticked too, such as to upload to it.

A group is read only. Upload with twine to one of its repositories, by that repository’s own address. An upload to the group’s URL is refused. Public (unauthenticated) downloads are not served for PyPI groups yet.

When CloudRepo refuses the token in ~/.netrc, pip does not show the 401. It asks for a username instead:

User for your-org.mycloudrepo.io:

Where no one can answer, as in CI, pip stops at that question with EOFError: EOF when reading a line. For the other answers, pip prints the status it received, or No matching distribution found for a package it cannot find. Check these in order:

  • 401 Unauthorized, the User for prompt or the EOFError. The credential was refused. The login in ~/.netrc must be the email address of the account that created the token, as it is written there, and the machine line must name the index’s host. __token__ is refused: that is the convention on pypi.org, and CloudRepo does not use it. The password must be the token itself, and a token that is expired or revoked fails the same way: the Repository Tokens page in the admin portal shows its status. If you’ve set up a second factor, your portal password no longer works for builds. Use a repository token instead.
  • 403 Forbidden. The token does not reach this repository. A token reaches only the repositories ticked when it was created, so use one that includes it.

    For a group, ticking the group is enough to read every repository in it through the group’s URL; a repository’s own address needs that repository ticked too.

  • 404 Not Found, or no matching distribution. The repository does not hold that name and version, or the index URL is wrong. Check the organization and repository names in it. A proxy repository that the token does not reach also answers 404, not 403.

More: Repository tokens, for every client’s credential; Proxy repositories, to install public packages through CloudRepo; Python repositories, for uploading, overwrite protection and the other settings.

View as Markdown