git-credentials

raw JSON →
1.0.0 verified Mon Apr 27 auth: no python

Simple library to interact with Git Credentials. Version 1.0.0 enables reading, storing, and erasing credentials via the Git credential helper protocol. Low release cadence.

pip install git-credentials
error AttributeError: 'GitCredentials' object has no attribute 'approve'
cause Calling approve() without setting username and password (or the object is incomplete).
fix
Ensure you set both username and password before calling approve().
error git: 'credential' is not a git command.
cause Git version < 2.6.0 does not support credential helper protocol.
fix
Upgrade git to version 2.6.0 or later.
gotcha GitCredentials constructor requires exactly one of url, path, or host. Missing required argument raises TypeError.
fix Always pass at least url, path, or host keyword argument.
gotcha Credentials are stored in plaintext by Git; the library does no encryption. Do not store sensitive passwords in shared repositories.
fix Use environment variables or a vault for secrets.

Basic usage: create a GitCredentials object, set username/password, approve, fill, or erase.

from git_credentials import GitCredentials

cred = GitCredentials(url='https://example.com')
# Fill in credentials (typically after a prompt)
cred.username = 'user'
cred.password = 'pass'
# Approve credentials (send to git credential approve)
cred.approve()
# To fetch credentials
stored = cred.fill()
print(stored.username, stored.password)
# Erase credentials
cred.erase()