Skip to main content

A GitHub API client with thottling logic and file-based caching

Project description

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.

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

ghcache-0.0.4.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ghcache-0.0.4-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file ghcache-0.0.4.tar.gz.

File metadata

  • Download URL: ghcache-0.0.4.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for ghcache-0.0.4.tar.gz
Algorithm Hash digest
SHA256 7be9e1c294060951216ca6bfaa985e10f821e23b03228a3625fb6653f33b27a9
MD5 c78535afd005b34dbe5ea70daafed83a
BLAKE2b-256 e36caa7e53b36f01ddae759244f47ee3bff40ab2b07a89062ab8a14bdce79b0c

See more details on using hashes here.

File details

Details for the file ghcache-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: ghcache-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for ghcache-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5b5f9ab72d527497b26b919fa397034bec64dc8c9c17f0da7823d3ddacabdbd8
MD5 fda63d3d46726396577d8e6273eeb0b9
BLAKE2b-256 c183af858ec1d528bd9cc1a5ca011802e7aed5c0f998a28b2d1bb37e8f6b299e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page