Read GPG-encrypted .authinfo credential files
Project description
authinfo-gpg
Read GPG-encrypted .authinfo.gpg credential files in Python.
Features
- Read encrypted
.authinfo.gpgfiles (netrc format) - Cross-platform GPG binary auto-detection
- Support for passphrase input or gpg-agent
- Simple, pythonic API
- No hardcoded paths or version dependencies
- Type-annotated
Installation
pip install authinfo-gpg
Requirements
- Python 3.7+
- GnuPG installed on your system
Quick Start
from authinfo_gpg import get_entry
from getpass import getpass
# Get passphrase from user
passphrase = getpass("Enter your GPG passphrase: ")
# Retrieve credentials
entry = get_entry(machine='example.com', login='myuser', passphrase=passphrase)
if entry:
print(f"Username: {entry.login}")
print(f"Password: {entry.password}")
Usage
Using the convenience function
from authinfo_gpg import get_entry
entry = get_entry('ollama.com', login='default', passphrase='my-gpg-pass')
if entry:
api_key = entry.password
Using the class interface
from authinfo_gpg import AuthInfoGPG
from getpass import getpass
# Initialize
auth = AuthInfoGPG()
# Get a specific entry
passphrase = getpass()
entry = auth.get_entry('example.com', passphrase=passphrase)
# Get all entries
all_entries = auth.get_all_entries(passphrase=passphrase)
for entry in all_entries:
print(f"{entry.machine}: {entry.login}")
Custom authinfo file location
from authinfo_gpg import AuthInfoGPG
auth = AuthInfoGPG(authinfo_path='/custom/path/to/.authinfo.gpg')
entry = auth.get_entry('example.com', passphrase='...')
File Format
The .authinfo.gpg file uses netrc format:
machine example.com login myuser password mypassword
machine api.service.com login admin password secret123 port 8080
Why authinfo-gpg?
The original authinfo package is unmaintained (last updated 2013, Python 2 only) and has compatibility issues with modern GnuPG installations. This package:
- Uses
subprocessto call GPG directly (more reliable) - Auto-detects GPG binary location (no hardcoded paths)
- Supports Python 3.7+
- Handles pinentry correctly with
--pinentry-mode=loopback - Actively maintained
Security Considerations
⚠️ Decrypted credentials and the GPG passphrase are held as plain Python strings in process memory until garbage-collected — Python provides no built-in mechanism to zero memory on deallocation. Avoid long-lived references to AuthEntry.password or the passphrase; retrieve credentials as close to their point of use as possible, and avoid storing them in module-level variables, caches, or data structures with unbounded lifetimes. On shared or multi-tenant systems, consider whether your threat model requires a language or runtime with explicit secure memory primitives.
License
MIT License - see LICENSE file for details
Contributing
Contributions welcome! Please open an issue or submit a pull request on GitHub.
Author
Armin Monecke authinfo-gpg@mnck.ai
Project details
Release history Release notifications | RSS feed
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 authinfo_gpg-0.1.1.tar.gz.
File metadata
- Download URL: authinfo_gpg-0.1.1.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a508aa52c531baae5fa563f9f200c80739b09d73ef633cda3d62782e542bf130
|
|
| MD5 |
30cab00f417b6b6fbb2f46588e79e309
|
|
| BLAKE2b-256 |
5082215948f6a314cfa59b068d591476df7c6a5b7b0a96e0969c8887ca2b7e7b
|
File details
Details for the file authinfo_gpg-0.1.1-py3-none-any.whl.
File metadata
- Download URL: authinfo_gpg-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a976e471ccb7e4b5b02cede4b557d016dfd1ddb9f215091cecf9c5336176b73d
|
|
| MD5 |
5d98b230226ce7f3cd64dc90e808cd7f
|
|
| BLAKE2b-256 |
6d09a13859a28cc70702cc98fe5dd4cc3956adde105e343a26537677c3d2731d
|