keyring backend for GitLab package indexes
Project description
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
Using it locally
-
Install keyring with this backend
uv tool install keyring --with keyring-gitlab-pypi
-
Open the config file for editing:
User
- 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
System
- 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
-
Configure a token
Personal Access Token
Create a personal access token with the
read_apiscope and add it to the config file:["gitlab.com"] token = "<token>"
or set environment variables where
<name>is an arbitrary key to group the variables, e.g.MYORGexport KEYRING_GITLAB_PYPI_<name>_INSTANCE=gitlab.com export KEYRING_GITLAB_PYPI_<name>_TOKEN=<token>
Deploy Token
Create a deploy token with the
read_package_registryscope and add it to the config file:["gitlab.com"] username = "<username>" token = "<token>"
or set environment variables where
<name>is an arbitrary key to group the variables, e.g.MYORGexport KEYRING_GITLAB_PYPI_<name>_INSTANCE=gitlab.com export KEYRING_GITLAB_PYPI_<name>_USERNAME=<username> export KEYRING_GITLAB_PYPI_<name>_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 (which is
__token__for personal access tokens) 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.
Using it in GitLab CI
$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 sync
This 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.txt
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 -c keyring-constraints.txt
- uv sync
Motivation
- 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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file keyring_gitlab_pypi-1.2.tar.gz.
File metadata
- Download URL: keyring_gitlab_pypi-1.2.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
048f00715c65b87931c8fc5581fbfd995a62d923abdf83f27df782efb513e979
|
|
| MD5 |
0a6a569b9a55f2610f9a692633b5b456
|
|
| BLAKE2b-256 |
ed3e00bd6760135fc9545c6967226ba2f13a07c5c65d21566293331c4c7b9edb
|
Provenance
The following attestation bundles were made for keyring_gitlab_pypi-1.2.tar.gz:
Publisher:
python-publish.yml on RazerM/keyring-gitlab-pypi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
keyring_gitlab_pypi-1.2.tar.gz -
Subject digest:
048f00715c65b87931c8fc5581fbfd995a62d923abdf83f27df782efb513e979 - Sigstore transparency entry: 1003443488
- Sigstore integration time:
-
Permalink:
RazerM/keyring-gitlab-pypi@6c39f9f93c8cf070485582bd2a2d5064a3a56c7c -
Branch / Tag:
refs/tags/1.2 - Owner: https://github.com/RazerM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@6c39f9f93c8cf070485582bd2a2d5064a3a56c7c -
Trigger Event:
push
-
Statement type:
File details
Details for the file keyring_gitlab_pypi-1.2-py3-none-any.whl.
File metadata
- Download URL: keyring_gitlab_pypi-1.2-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec95fe4c000bfab06b5767e38c3c90a011697484e92f44cc03cfb19587a6ea82
|
|
| MD5 |
c333e0edf9a802ccf34952d48eea2be3
|
|
| BLAKE2b-256 |
a1b8484e7dc0af46a15934a2c94b2e69d10540f2a66042add161d626ebfbc759
|
Provenance
The following attestation bundles were made for keyring_gitlab_pypi-1.2-py3-none-any.whl:
Publisher:
python-publish.yml on RazerM/keyring-gitlab-pypi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
keyring_gitlab_pypi-1.2-py3-none-any.whl -
Subject digest:
ec95fe4c000bfab06b5767e38c3c90a011697484e92f44cc03cfb19587a6ea82 - Sigstore transparency entry: 1003443495
- Sigstore integration time:
-
Permalink:
RazerM/keyring-gitlab-pypi@6c39f9f93c8cf070485582bd2a2d5064a3a56c7c -
Branch / Tag:
refs/tags/1.2 - Owner: https://github.com/RazerM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@6c39f9f93c8cf070485582bd2a2d5064a3a56c7c -
Trigger Event:
push
-
Statement type: