GitLab PyPi Repository (PREMIUM)
With the GitLab PyPi Repository, every project can have its own space to store PyPi packages.
The GitLab PyPi Repository works with:
Setting up your development environment
Enabling the PyPi Repository
NOTE: Note: This option is available only if your GitLab administrator has enabled support for the Package Registry. (PREMIUM ONLY)
After the PyPi Repository is enabled, it will be available for all new projects by default. To enable it for existing projects, or if you want to disable it:
- Navigate to your project's Settings > General > Permissions.
- Find the Packages feature and enable or disable it.
- Click on Save changes for the changes to take effect.
You should then be able to see the Packages section on the left sidebar.
Adding the GitLab PyPi Repository as a source
You will need the following:
- A personal access token. You can generate a personal access token with the scope set to
apifor repository authentication.
- A suitable name for your source.
- Your project ID which can be found on the home page of your project.
~/.pypirc file and add the following:
[gitlab] repository = https://gitlab.com/api/v4/projects/<project_id>/packages/pypi username = __token__ password = <your personal access token>
When uploading packages, note that:
- The maximum allowed size is 50 Megabytes.
- If you upload the same package with the same version multiple times, each consecutive upload is saved as a separate file. When installing a package, GitLab will serve the most recent file.
- When uploading packages to GitLab, they will not be displayed in the packages UI of your project immediately. It can take up to 10 minutes to process a package.
Upload packages with Twine
This section assumes that your project is properly built and you already created a PyPi package with setuptools. Upload your package using the following command:
python -m twine upload --repository <source_name> dist/<package_file>
<package_file>is your package filename, ending in
<source_name>is the source name used during setup.
Install the latest version of a package using the following command:
pip install --index-url https://__token__:<personal_access_token>@gitlab.com/api/v4/projects/<project_id>/packages/pypi/simple --no-deps <package_name>
<package_name>is the package name.
<personal_access_token>is your personal access token.
<project_id>is your project id number.