A Python library for securely retrieving GitHub tokens from system keychains across different operating systems.
# Ubuntu/Debian
sudo apt-get install libsecret-tools
# Fedora
sudo dnf install libsecret
pip install githubauthlib
# 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 .
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}")
# Check installed version
pip list | grep githubauthlib
# View package details
pip show githubauthlib
For development, you may want to add the package directory to your PYTHONPATH. See AUXILIARY.md for detailed instructions.
⚠️ Important: Version 2.0.0 introduces breaking changes:
get_github_token() now raises specific exceptions instead of returning NoneBefore (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}")
TokenNotFoundError exceptionCredentialHelperError exceptionPlatformNotSupportedError exceptionghp_ (personal), gho_ (organization), or github_pat_ (fine-grained)InvalidTokenError exceptiongit checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.