Skip to main content

Dynamic GitHub REST API client with optional typed helpers

Project description

Dynamic GitHub API Client

Minimal Python client for GitHub REST API with dynamic endpoints.

Install

pip install paulosoft-api-github

Quick Start

import time
import requests

from api_github import GitHubClient

client = GitHubClient(token="...")

client.api.user.repos(per_page=100)
client.api.search.repositories(q="backend", per_page=50)
client.call("repos/octocat/Hello-World/issues", params={"per_page": 50})
catalogo = client.webservices_list()

Authentication

from api_github import GitHubClient

client = GitHubClient(token="YOUR_GITHUB_TOKEN")

Configuration

from api_github import GitHubClient

client = GitHubClient(
    token="YOUR_GITHUB_TOKEN",
    base_url="https://api.github.com",
    timeout=30,
    raise_for_status=True,
)

List User Repositories with Token (Dynamic API)

from api_github import GitHubClient

token = "YOUR_GITHUB_TOKEN"
client = GitHubClient(token=token)

repos = client.api.users.octocat.repos.paginate(per_page=100)
for repo in repos:
    print(repo["full_name"])

Pagination

GitHub paginates list endpoints and advertises the next page via the Link header. This library provides two helpers:

  • Generator: client.iter_paginated("users/octocat/repos", params={...})
  • Convenience: .paginate(...) on any dynamic API node
from api_github import GitHubClient

client = GitHubClient(token="YOUR_GITHUB_TOKEN")

# Convenience: follow `Link: rel="next"` automatically
repos = client.api.users["octocat"].repos.paginate(per_page=100)
print(len(repos))

# Generator version (useful for streaming large result sets)
for repo in client.iter_paginated("users/octocat/repos", params={"per_page": 100}):
    print(repo["full_name"])

Rate limit helper (optional)

import time
import requests


def call_with_rate_limit(func):
    while True:
        try:
            return func()
        except requests.HTTPError as exc:
            response = exc.response
            if response is None:
                raise
            if response.status_code in (403, 429):
                reset = response.headers.get("X-RateLimit-Reset")
                if reset:
                    sleep_for = max(0, int(reset) - int(time.time()) + 1)
                else:
                    sleep_for = 5
                time.sleep(sleep_for)
                continue
            raise


def iter_pages(fetch_page, max_pages=10):
    page = 1
    while page <= max_pages:
        items = call_with_rate_limit(lambda: fetch_page(page))
        if not items:
            break
        for item in items:
            yield item
        page += 1
        time.sleep(0.2)

Notes:

  • Adjust max_pages based on your expected repo count.
  • For more accurate pagination, you can parse the Link header from responses.

List Organization Repositories with Token (Dynamic API)

from api_github import GitHubClient

token = "YOUR_GITHUB_TOKEN"
client = GitHubClient(token=token)

for repo in iter_pages(
    lambda page: client.api.orgs.myorg.repos(per_page=100, page=page, type="all")
):
    print(repo["full_name"])

List Authenticated User Repositories (Dynamic API)

from api_github import GitHubClient

token = "YOUR_GITHUB_TOKEN"
client = GitHubClient(token=token)

for repo in iter_pages(
    lambda page: client.api.user.repos(
        per_page=100,
        page=page,
        visibility="all",
        affiliation="owner,collaborator,organization_member",
    )
):
    print(repo["full_name"])

Typed Helpers (Optional)

from api_github import TypedGitHubClient

client = TypedGitHubClient(token="...")

client.repos.list(per_page=50)
client.repos.get("octocat", "Hello-World")
client.repos.list_issues("octocat", "Hello-World", state="open")
client.repos.create_issue("octocat", "Hello-World", title="Bug", body="Details")

client.users.get("octocat")
client.users.list(per_page=50)

client.issues.get("octocat", "Hello-World", 1)
client.issues.create_comment("octocat", "Hello-World", 1, body="Thanks!")

Dynamic Format

client.api.<service>.<action>(**params)

Examples:

client.api.search.repositories(q="backend", per_page=100)
client.api.orgs.myorg.repos(per_page=100)
client.api.users.octocat.repos(per_page=100)
client.api.repos["octocat"]["Hello-World"].issues(per_page=50)

Notes:

  • Use bracket access for path segments with hyphens or non-identifier names.
  • The dynamic chain builds the full path and sends params as query or JSON.

POST Calls

For endpoints that require POST (or other verbs), pass http_method:

client.api.user.repos(
    http_method="POST",
    name="my-new-repo",
    private=True,
)

Raw Endpoint

client.call("search/repositories", params={"q": "backend", "per_page": 100})

Error Handling

from api_github import GitHubClient

client = GitHubClient(token="YOUR_GITHUB_TOKEN", raise_for_status=False)
response = client.call("rate_limit")

Webservices List

catalogo = client.webservices_list()

Notes

  • Uses requests under the hood.
  • Non-GET methods send params as JSON body.
  • If the response is JSON, it returns parsed JSON, otherwise text.

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

paulosoft_api_github-0.1.2.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

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

paulosoft_api_github-0.1.2-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file paulosoft_api_github-0.1.2.tar.gz.

File metadata

  • Download URL: paulosoft_api_github-0.1.2.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for paulosoft_api_github-0.1.2.tar.gz
Algorithm Hash digest
SHA256 833182d1f902b7d340534b89e1b35f2088191700acba4ad520e6e7d0fe39235a
MD5 537cb0da4af1d9b8fd61d06ccef5361f
BLAKE2b-256 2a59d7232f08498f162cff6b5bed13bc2a5acbc68ab731b76f2dfd29afaf0cbc

See more details on using hashes here.

File details

Details for the file paulosoft_api_github-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for paulosoft_api_github-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4d26cc3af39629444434a5c391efa5c4b8dd6c87605d78e12826517c463ba20e
MD5 c70e058f04d05333f8067ae00e76c004
BLAKE2b-256 200d2cfc9f73407a0bff038f5da206896861b8668c8e7dd363dcb51e54e04015

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