Skip to main content

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 iterate method handles paginated API responses automatically.
  • Simple Interface: Provides get and iterate methods 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 the GITHUB_TOKEN environment variable.
  • cache_directory (str): The directory where cache files will be stored. Defaults to a cache directory in the current working directory.
  • cache_r (bool): Whether to read from the cache. Defaults to True.
  • cache_w (bool): Whether to write to the cache. Defaults to True.

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)

Source distribution for ghcache 0.0.4
File Size Uploaded
ghcache-0.0.4.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ghcache 0.0.4
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page