Install & Compatibility
Where this runs
tested against v0.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.632s · 18.9MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.536s · 19MB
17MB installed
● package 17MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Store
✓ from dockerpycreds import Store
✗ from dockerpycreds import Store
This quickstart demonstrates how to instantiate a credential store and use it to store and list Docker credentials. It assumes a `docker-credential` helper for your platform is installed and configured. Storing credentials might trigger a system-level prompt for keyring access depending on the backend.
import dockerpycreds
import os
# Configure the credential store backend. Common options include:
# 'secretservice' (Linux), 'osxkeychain' (macOS), 'wincred' (Windows)
# If you have a custom credential helper, use its name (e.g., 'ecr-login')
# Ensure the corresponding 'docker-credential-<backend>' executable is in your PATH.
store_backend = os.environ.get('DOCKER_CREDS_STORE_BACKEND', 'secretservice')
store = dockerpycreds.Store(store_backend)
# Define credentials from environment variables for security in examples
server_url = os.environ.get('DOCKER_SERVER_URL', 'https://index.docker.io/v1/')
username = os.environ.get('DOCKER_USERNAME', 'testuser')
secret = os.environ.get('DOCKER_SECRET', 'testpassword')
print(f"Attempting to store credentials for {username} on {server_url} using '{store_backend}'...")
try:
store.store(
server=server_url,
username=username,
secret=secret
)
print("Credentials stored successfully. Note: This might have prompted for system keyring access.")
except Exception as e:
print(f"Failed to store credentials: {e}. Ensure the credential helper is correctly configured and accessible.")
print("\nListing all known Docker credential servers:")
try:
creds_list = store.list()
if creds_list:
for server, user in creds_list.items():
print(f" Server: {server}, Username: {user}")
else:
print(" No credentials found.")
except Exception as e:
print(f"Failed to list credentials: {e}. Listing may require user interaction or specific backend support.")
# Example of getting credentials (often requires explicit interaction with the helper)
# This is commented out as it frequently requires external CLI calls or user prompts
# which are hard to automate in a simple quickstart.
# try:
# retrieved_username, retrieved_secret = store.get(server_url)
# print(f"\nRetrieved credentials for {server_url}: Username: {retrieved_username}, Secret: {'*' * len(retrieved_secret)}")
# except Exception as e:
# print(f"Failed to retrieve credentials: {e}. This often requires direct Docker CLI interaction or specific credential helper setup.")
Upgrade
Version history
0.4.0latest on PyPI · released Nov 29, 2018
Audit
Dependencies
sixrequiredCompatibility layer for Python 2 and 3.
docker-credential-helpersrequiredRequires a platform-specific Docker credential helper executable (e.g., docker-credential-secretservice for Linux, docker-credential-osxkeychain for macOS, or docker-credential-wincred for Windows) to be installed and available in the system's PATH. This is a crucial system-level dependency.