A library for authenticating with GitHub across different operating systems
Project description
GitHub Authentication Library (githubauthlib)
A Python library for securely retrieving GitHub tokens from system keychains across different operating systems.
versions
health
stats
Features
- Cross-platform support:
- macOS: Uses Keychain Access
- Windows: Uses Credential Manager
- Linux: Uses libsecret
- Secure token retrieval with validation
- Comprehensive exception hierarchy for precise error handling
- Structured logging support
- Token format validation (supports personal, organization, and fine-grained tokens)
- Robust credential parsing and sanitization
Prerequisites
All Platforms
- Python 3.9 or higher
- Git (with credentials configured)
Linux-Specific
# Ubuntu/Debian
sudo apt-get install libsecret-tools
# Fedora
sudo dnf install libsecret
Installation
From PyPI
pip install githubauthlib
From Source
# Clone the repository
git clone https://github.com/GIALaboratory/cloud-platform-engineering.git
# Navigate to the library directory
cd cloud-platform-engineering/githubauthlib
# Install the package
pip install .
Usage
from githubauthlib import (
get_github_token,
GitHubAuthError,
TokenNotFoundError,
InvalidTokenError,
PlatformNotSupportedError,
CredentialHelperError
)
try:
token = get_github_token()
print("Token retrieved successfully!")
print(f"Token: {token[:10]}...") # Show first 10 chars only
except TokenNotFoundError:
print("No GitHub token found in system keychain")
except InvalidTokenError:
print("Invalid token format detected")
except PlatformNotSupportedError:
print("Current platform is not supported")
except CredentialHelperError:
print("Failed to access system credential store")
except GitHubAuthError as e:
print(f"GitHub authentication error: {e}")
Verifying Installation
# Check installed version
pip list | grep githubauthlib
# View package details
pip show githubauthlib
Development Setup
For development, you may want to add the package directory to your PYTHONPATH. See AUXILIARY.md for detailed instructions.
Breaking Changes in v2.0.0
⚠️ Important: Version 2.0.0 introduces breaking changes:
get_github_token()now raises specific exceptions instead of returningNone- All error handling now uses structured logging instead of print statements
- Token validation is now strict and validates format
- Python 3.6, 3.7, and 3.8 support has been removed (EOL)
Migration Guide
Before (v1.x.x):
token = get_github_token()
if token:
print("Success!")
else:
print("Failed!")
After (v2.0.0):
try:
token = get_github_token()
print("Success!")
except TokenNotFoundError:
print("No token found!")
except GitHubAuthError as e:
print(f"Error: {e}")
Troubleshooting
-
Token Not Found
- Verify Git credentials are properly configured
- Check system keychain for GitHub credentials
- Handle
TokenNotFoundErrorexception
-
Permission Issues
- Ensure proper system keychain access
- Verify Python has required permissions
- Handle
CredentialHelperErrorexception
-
Linux Issues
- Confirm libsecret-tools is installed
- Check D-Bus session is running
- Handle
PlatformNotSupportedErrorexception
-
Invalid Token Format
- Verify token starts with
ghp_(personal),gho_(organization), orgithub_pat_(fine-grained) - Handle
InvalidTokenErrorexception
- Verify token starts with
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
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
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 githubauthlib-2.0.1.tar.gz.
File metadata
- Download URL: githubauthlib-2.0.1.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c01638eb75305da0aeb7d569939d23594ec76f73cf184c6010e7322e592515be
|
|
| MD5 |
64caa46081715a15eb8a21617ec812be
|
|
| BLAKE2b-256 |
7128d4718c07674606f23d7d85fd00be2675481fe4881ef485107e57e4a5fd9b
|
Provenance
The following attestation bundles were made for githubauthlib-2.0.1.tar.gz:
Publisher:
workflow.yml on fleXRPL/githubauthlib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
githubauthlib-2.0.1.tar.gz -
Subject digest:
c01638eb75305da0aeb7d569939d23594ec76f73cf184c6010e7322e592515be - Sigstore transparency entry: 600019129
- Sigstore integration time:
-
Permalink:
fleXRPL/githubauthlib@9f0f52410c4d6d00a3d1327411cdc697b6e4d9b8 -
Branch / Tag:
refs/tags/v2.0.1 - Owner: https://github.com/fleXRPL
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@9f0f52410c4d6d00a3d1327411cdc697b6e4d9b8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file githubauthlib-2.0.1-py3-none-any.whl.
File metadata
- Download URL: githubauthlib-2.0.1-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ab9f7b7dadc71a2ebe88f2e0a1ef40610bf5e275ca274b69a1dc047b4682937
|
|
| MD5 |
27e260a64b33d7905fc3fb7b86b28ac4
|
|
| BLAKE2b-256 |
ffd7d524d4a9087688fc1f54c8b0a82800b57fa0fa826df5591ff4d6106e4e37
|
Provenance
The following attestation bundles were made for githubauthlib-2.0.1-py3-none-any.whl:
Publisher:
workflow.yml on fleXRPL/githubauthlib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
githubauthlib-2.0.1-py3-none-any.whl -
Subject digest:
0ab9f7b7dadc71a2ebe88f2e0a1ef40610bf5e275ca274b69a1dc047b4682937 - Sigstore transparency entry: 600019132
- Sigstore integration time:
-
Permalink:
fleXRPL/githubauthlib@9f0f52410c4d6d00a3d1327411cdc697b6e4d9b8 -
Branch / Tag:
refs/tags/v2.0.1 - Owner: https://github.com/fleXRPL
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@9f0f52410c4d6d00a3d1327411cdc697b6e4d9b8 -
Trigger Event:
push
-
Statement type: