GitLab Package Registry

You can also publish your distribution packages in the package registry of your GitLab project and use them with both Pip and twine.

Authentication

To authenticate to the GitLab Package Registry, you can use one of the following methods:

… with a personal access token

To authenticate yourself with a personal access token, you can add the following to the ~/.pypirc file, for example:

[distutils]
index-servers=
    gitlab

[gitlab]
repository = https://ce.cusy.io/api/v4/projects/{PROJECT_ID}/packages/pypi
username = {NAME}
password = {YOUR_PERSONAL_ACCESS_TOKEN}

… with a deploy token

[distutils]
index-servers =
    gitlab

[gitlab]
repository = https://ce.cusy.io/api/v4/projects/{PROJECT_ID}/packages/pypi
username = {DEPLOY_TOKEN_USERNAME}
password = {DEPLOY_TOKEN}

… with a job token

image: python:latest

- name: Setup cached uv
  uses: hynek/setup-cached-uv@v2
- name: Create venv and install twine
  run: |
    uv venv
    echo "$PWD/.venv/bin" >> $GITHUB_PATH
    uv add --upgrade twine
- name: Build
  run: |
    uv build
- name: Retrieve and publish
  - TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*

… for access to packages within a group

Use the GROUP_URL instead of the PROJECT_ID.

Publishing the distribution package

You can publish your package with the help of twine:

$ uv run twine upload -r gitlab dist/*

Note

If you try to publish a package that already exists with the same name and version, you will get the error 400 Bad Request; you will have to delete the existing package first.

Installing the package

You can install the latest version of your package for example with

uv add -i https://{NAME}:{PERSONAL_ACCESS_TOKEN}@ce.cusy.io/api/v4/projects/{PROJECT_ID}/packages/pypi/simple --no-deps {PACKAGE_NAME}

… or from the group level with

uv add -i https://{NAME}:{PERSONAL_ACCESS_TOKEN}@ce.cusy.io/api/v4/groups/{GROUP_ID}/-/packages/pypi/simple --no-deps {PACKAGE_NAME}

… or in the pyproject.toml file with

pyproject.toml
[tool.uv]
extra-index-url = ["https://ce.cusy.io/api/v4/projects/{PROJECT_ID}/packages/pypi/simple {PACKAGE_NAME}"]