ghcache
A GitHub API client with thottling logic and file-based caching.
ghcache provides access to the GitHub API while caching the results to the local filesystem. It is aware of API rate limits and has throttling logic to avoid hitting them.
The caching in the filesystem is also helpful for debugging. Only use on endpoints where data wouldn't change (or you might get stale data). Otherwise, disable reading from the cache with cache_r=False.
At the moment, this is better fit for long running scripts that make many requests to GitHub and preventing rate limits is more important than minimizing running time. It might be too slow for anything short of that due to the throttling, which is admittedly naively aggressive.
Features
- File-based Caching: Caches GitHub API responses in a local directory.
- Rate Limit Aware: Includes delays between requests to avoid hitting GitHub's rate limits.
- Automatic Pagination: The
iteratemethod handles paginated API responses automatically. - Simple Interface: Provides
getanditeratemethods for interaction with the GitHub API.
Installation
You can install ghcache from PyPI:
pip install ghcache
Usage
First, make sure you have a GitHub personal access token. You can either pass it to the GithubCache constructor or set it as the GITHUB_TOKEN environment variable.
from ghcache import GithubCache
# It's recommended to set the GITHUB_TOKEN environment variable
gh = GithubCache()
# Get a user's information
user = gh.get("/users/santi-h")
print(user["name"])
# Iterate through a user's repositories
for repo, total, page, last_page in gh.iterate("/users/santi-h/repos"):
print(f"Repo: {repo['name']}, Page: {page}/{last_page}")
Configuration
The GithubCache class can be configured with the following parameters:
github_token(str): Your GitHub personal access token. If not provided, it will be read from theGITHUB_TOKENenvironment variable.cache_directory(str): The directory where cache files will be stored. Defaults to acachedirectory in the current working directory.cache_r(bool): Whether to read from the cache. Defaults toTrue.cache_w(bool): Whether to write to the cache. Defaults toTrue.
License
This project is licensed under the MIT License.
Metadata
Release files for ghcache 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ghcache-0.0.4.tar.gz | 5.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ghcache-0.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.5 kB
Release files / ghcache-0.0.4.tar.gz
| Download URL | ghcache-0.0.4.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7be9e1c294060951216ca6bfaa985e10f821e23b03228a3625fb6653f33b27a9
|
|
BLAKE2b-256 checksum How to use checksums |
e36caa7e53b36f01ddae759244f47ee3bff40ab2b07a89062ab8a14bdce79b0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / ghcache-0.0.4-py3-none-any.whl
| Download URL | ghcache-0.0.4-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5b5f9ab72d527497b26b919fa397034bec64dc8c9c17f0da7823d3ddacabdbd8
|
|
BLAKE2b-256 checksum How to use checksums |
c183af858ec1d528bd9cc1a5ca011802e7aed5c0f998a28b2d1bb37e8f6b299e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|