keyring-gitlab-pypi is a backend for keyring which recognises GitLab package registry URLs.
- ⚡️ Works seamlessly with uv
- 🚀 Zero config needed on GitLab CI
- 🗝️ No more per-index credentials on your machine
-
Install keyring with this backend
uv tool install keyring --with keyring-gitlab-pypi
-
Open the config file for editing:
- macOS
$HOME/Library/Application Support/gitlab-pypi/gitlab-pypi.tomlif directory$HOME/Library/Application Support/gitlab-pypiexists, or$HOME/.config/gitlab-pypi.tomlotherwise.- Linux
$XDG_CONFIG_HOME/gitlab-pypi.tomlifXDG_CONFIG_HOMEis set, or$HOME/.config/gitlab-pypi.tomlotherwise.- Windows
%LOCALAPPDATA%\gitlab-pypi\gitlab-pypi.toml
- macOS
/Library/Application Support/gitlab-pypi/gitlab-pypi.toml- Linux
-
<config_dir>/gitlab-pypi/gitlab-pypi.tomlwhere<config_dir>is any of the paths set in$XDG_CONFIG_DIRSpaths, defaulting to/etc/xdg/etc/gitlab-pypi.tomlis higher priority than the above. - Windows
C:\ProgramData\gitlab-pypi\gitlab-pypi.toml
-
Create a personal access token with
read_apiscope and add it to the config file:["https://gitlab.com"] token = "<token>"
-
Configure
keyring-providerin uv:-
using an environment variable:
export UV_KEYRING_PROVIDER=subprocess -
or in
uv.toml:keyring-provider = "subprocess"
-
or using the option
uv sync --keyring-provider=subprocess
-
-
Configure one or more GitLab package indexes
For example, in
pyproject.toml:[[tool.uv.index]] name = "myindex" url = "https://gitlab.example.com/api/v4/projects/1/packages/pypi/simple" authenticate = "always"
Note
You need
authenticate = "always"for uv to invoke keyring when no username is specified. This option is a good idea anyway!Alternatively, add the username
__token__to the URL, but this is not recommended forpyproject.tomlas you likely want to use a different username in CI, for example. -
Done!
keyring-gitlab-pypiwill return your token for URLs that look like package installs.
$CI_JOB_TOKEN will be used automatically as long as the index URL matches the running GitLab instance.
In principle this is all you need:
variables:
UV_KEYRING_PROVIDER: subprocess
UV_TOOL_BIN_DIR: /usr/local/bin
test:
image: ghcr.io/astral-sh/uv:python3.13-bookworm
before_script:
- uv tool install keyring --with keyring-gitlab-pypi
- uv syncThis assumes that you haven't set UV_INDEX. (uv tool ignores pyproject.toml so you don't need to worry about indexes configured there).
It's recommended to constrain the versions:
printf '%s\n' keyring keyring-gitlab-pypi > keyring-constraints.in
uv pip compile --universal keyring-constraints.in -o keyring-constraints.txtvariables:
UV_KEYRING_PROVIDER: subprocess
UV_TOOL_BIN_DIR: /usr/local/bin
test:
image: ghcr.io/astral-sh/uv:python3.13-bookworm
before_script:
- uv tool install keyring --with keyring-gitlab-pypi -c keyring-constraints.txt
- uv sync- When using multiple GitLab package indexes, it can be cumbersome to configure them with the same token via environment variables or otherwise.
- keyring's keychain backend on macOS does not support
--mode creds - uv will reuse credentials for URLs on the same host, but it feels fragile to just configure one of the indexes and let the credentials cache serve the rest. At the very least,
keyring-gitlab-pypiis set-and-forget across multiple projects.