How to install private python packages
Warning
This guide is for Business hosting.
Read the Docs uses pip to install your Python packages. If you have private dependencies, you can install them from a private Git repository or a private repository manager.
From a Git repository
Pip supports installing packages from a Git repository using the URI form:
git+https://gitprovider.com/user/project.git@{version}
(public repository)git+https://{token}@gitprovider.com/user/project.git@{version}
(private repository)
Where version
can be a tag, a branch, or a commit, and token
is a personal access token with read only permissions from your provider.
To install a private package from a Git repositories, add the URI to your requirements file. Make sure to use an environment variable for the token, so you don’t have to hard code it in the URI.
Pip automatically expands environment variables in POSIX format: using only uppercase letters and _
, and including a dollar sign and curly brackets around the name, like ${API_TOKEN}
.
See using environment variables in Read the Docs for more information.
GitHub
You need to create a fine-grained personal access token with the Contents
repository permission set to Read-only
.
Follow the GitHub documentation
on how to create a fine-grained personal access token.
URI example:
git+https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/user/project.git@{version}
GitLab
You need to create a deploy token with the read_repository
scope for the repository you want to install the package from.
Follow the GitLab documentation
on how to create a deploy token.
URI example, where GITLAB_TOKEN_USER
is the user from the deploy token you created, not your GitLab user:
git+https://${GITLAB_TOKEN_USER}:${GITLAB_TOKEN}@gitlab.com/user/project.git@{version}
Bitbucket
You need to create an app password with Read repositories
permissions.
Follow the Bitbucket documentation
on how to create an app password.
URI example:
git+https://${BITBUCKET_USER}:${BITBUCKET_APP_PASSWORD}@bitbucket.org/user/project.git@{version}'
Here BITBUCKET_USER
is your Bitbucket user.
Warning
Bitbucket doesn’t support app passwords per repository. An app password will grant read access to all repositories the user has access to. You can create a a machine user to give read access only to the repositories you need.
From a repository manager other than PyPI
By default Pip installs your packages from PyPI.
If you are using a different repository manager like pypiserver, or Nexus Repository,
you need to get the index URL from your repository manager and set the --index-url
option in one of the following ways:
Set the
PIP_INDEX_URL
environment variable in Read the Docs with the index URL. See the Requirements File environment variables reference.Put
--index-url=https://my-index-url.com/
at the top of your requirements file. See Requirements File Format.