Skip to main content

keyring backend for GitLab package indexes

Project description

PyPI CI Status MIT License

keyring-gitlab-pypi is a backend for keyring which recognises GitLab package registry URLs.

It is designed for use with uv.

Using it locally

  1. Install keyring with this backend

    uv tool install keyring --with keyring-gitlab-pypi
    
  2. Open the config file for editing:

    macOS
    $HOME/Library/Application Support/gitlab-pypi/gitlab-pypi.toml if directory $HOME/Library/Application Support/gitlab-pypi exists, or $HOME/.config/gitlab-pypi.toml otherwise.
    Linux
    $XDG_CONFIG_HOME/gitlab-pypi.toml if XDG_CONFIG_HOME is set, or $HOME/.config/gitlab-pypi.toml otherwise.
    Windows
    %LOCALAPPDATA%\gitlab-pypi\gitlab-pypi.toml
  3. Create a personal access token with read_api scope and add it to the config file:

    ["https://gitlab.com"]
    token = "<token>"
    
  4. Configure keyring-provider in 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
      
  5. 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 for pyproject.toml as you likely want to use a different username in CI, for example.

  6. Done! keyring-gitlab-pypi will 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

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

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-pypi is 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

keyring_gitlab_pypi-1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

keyring_gitlab_pypi-1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file keyring_gitlab_pypi-1.0.tar.gz.

File metadata

  • Download URL: keyring_gitlab_pypi-1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for keyring_gitlab_pypi-1.0.tar.gz
Algorithm Hash digest
SHA256 3fbc75cbf2bb12e02f406095bfb76926360c2e3001c892ce4d79a443c8ac1359
MD5 08fcc7dcb3d2241667b6eef17fc63fb7
BLAKE2b-256 0cc342d00ca7636d763e8f91ac54be6abd4a70cc7613605e85004879f1fdaa6a

See more details on using hashes here.

Provenance

The following attestation bundles were made for keyring_gitlab_pypi-1.0.tar.gz:

Publisher: python-publish.yml on RazerM/keyring-gitlab-pypi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file keyring_gitlab_pypi-1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for keyring_gitlab_pypi-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ad30a34ec49f7974f553f81d0cf1f7e6230c2ba1b146230f2ffd8e59c383ad1
MD5 1e940a0d6c8a3820f26e23bdc53bb400
BLAKE2b-256 83c5e505f24ae9ff851fa24c75e1a1ebe6198d52e49754cd31a6234ed5852300

See more details on using hashes here.

Provenance

The following attestation bundles were made for keyring_gitlab_pypi-1.0-py3-none-any.whl:

Publisher: python-publish.yml on RazerM/keyring-gitlab-pypi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page