Skip to main content

keyring-prompt is a python package that wraps keyring, providing simple interactive GUI or CLI user input for missing credentials to let python apps easily provide a decent user experience for secure credentials entry.

A call to get_password() or get_credential():

  • First attempts to retrieve from keyring.
  • If this fails, attempts to retrieve from environment variables (a typical alternative location for CI).
  • If this fails, requests user entry and saves in keyring.

If the user-provided credentials are invalid, call delete_password() or delete_credential() to clear them for re-entry on next attempt. with_password() is provided as a context manager to do this easily.

This package also provides command-line programs keyring-prompt-run and keyring-prompt-delete to easily supply keyring credentials to other programs via environment variables.

Installation:

pip install keyring-prompt

Usage as a python import

Basic usage example:

from keyring_prompt import with_password

with with_password("MyCoolApp:https://someservice", exc_type=SomeServiceAuthorizationError) as token:
    someservice.login(token)

Advanced usage example:

import os
from keyring_prompt import delete_credential, get_credential

# Change the keyring backend to use gpg/pass instead of the default
import keyring
import keyring_pass  # pip install keyring-pass
keyring.set_keyring(keyring_pass.PasswordStoreBackend())

cred_name = "MyCoolApp:https://someservice"

# Disable prompts if running in a specific Continuous Integration server
# and use the cli prompt instead of the default gui
is_ci = hasattr(os.environ, "TEAMCITY_VERSION")
prompt = None if is_ci else "cli"

# Look for the username and password in specific environment variables
# instead of the default "PY_KEYRING_" + cred_name + "_USER"/"_PASS"
env_vars = ("SOMESERVICE_USER", "SOMESERVICE_TOKEN")

creds = get_credential(cred_name, prompt=prompt, env_vars=env_vars)
try:
    someservice.login(creds.username, creds.password)
except SomeServiceAuthorizationError:
    delete_credential(cred_name)

Commandline usage

keyring-prompt-run

keyring-prompt-run resolves one or more credentials, assigns them to environment variables only in the child process environment, and then replaces itself with that command.

It is useful for running programs that accept credentials only through environment variables.

Basic usage example:

keyring-prompt-run \
  --env FOOBAR_PASSWORD=myprogram:something.com:password \
  -- myprogram

Advanced usage example:

keyring-prompt-run \
  --title "myprogram credentials" \
  --env FOOBAR_USERNAME=myprogram:something.com:username \
  --msg "Extra message that appears before the username prompt" \
  --env FOOBAR_PASSWORD=myprogram:something.com:password \
  --msg "Extra message that appears before the password prompt" \
  -- myprogram

For every credential, the command checks keyring first, then the named environment variable, then shows a prompt and stores the entered value in the keyring.

Use --prompt cli in headless environments to prompt on the commandline instead of gui, or --prompt none in CI environments to fail rather than prompt.

keyring-prompt-delete

Delete entries from the keyring to allow re-entry.

keyring-prompt-delete myprogram:something.com:username myprogram:something.com:password

Metadata

Release files for keyring-prompt 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for keyring-prompt 0.1.0
File Size Uploaded Provenance Actions
keyring_prompt-0.1.0.tar.gz 8.2 kB With provenance Details for keyring_prompt-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for keyring-prompt 0.1.0
File Interpreter ABI Platform Actions
keyring_prompt-0.1.0-py3-none-any.whl Python 3 none any Details for keyring_prompt-0.1.0-py3-none-any.whl

Total release size: 18.0 kB

Release files / keyring_prompt-0.1.0.tar.gz

Download URL keyring_prompt-0.1.0.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
01b6f00f548344d1b876ba008e25d338ea989535c77f81e87d3dd9bd9c86fd53
BLAKE2b-256 checksum
How to use checksums
7ca69e062cce8023fc2b98bad96b431945fd57b977cc754650e28b094d5e177b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / keyring_prompt-0.1.0-py3-none-any.whl

Download URL keyring_prompt-0.1.0-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5cc701a81ff32f5b557cbc03b7d19c642b881ed582e956d024c201cf8f14ae5f
BLAKE2b-256 checksum
How to use checksums
462700a9f686d818c611ed6172e466a40c32ed5a05fc01023869330c7efbe948
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Security for keyring-prompt 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for keyring_prompt-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page