Skip to main content

asyncPyGithub

Testing Linting Type-Check Python 3.12+ Code style: black Validation: Pydantic v2

A fully asynchronous Python library for the GitHub API.

Install

pip

pip install asyncPyGithub

Manual

git clone https://github.com/sudoDeVinci/asyncPyGithub.git
cd asyncPyGithub
pip install -r requirements.txt

Setup

Create a .env file:

GITHUB_TOKEN=your_token_here

Client Lifecycle

The library uses a shared httpx.AsyncClient under the hood. You have two options for managing it:

Option 1: Let it auto-start (simple)

The client starts automatically on first request. Just remember to close it when done:

import asyncio
from asyncPyGithub import GitHubPortal, GitHubUserPortal

async def main():
    # Client starts automatically on first request
    status, user = await GitHubPortal.authenticate("your_token")
    if status != 200:
        print(f"Auth failed: {user.message}")
        return
    
    print(f"Logged in as {user.login}")
    
    # Do stuff...
    status, other = await GitHubUserPortal.get_by_username("torvalds")
    if status == 200:
        print(f"Found: {other.login}")
    
    # Clean up when done
    await GitHubPortal.close()

asyncio.run(main())

Option 2: Use the context manager (scoped)

For scoped usage where you want automatic cleanup:

import asyncio
from asyncPyGithub import GitHubPortal, GitHubUserPortal

async def main():
    async with GitHubPortal.scoped_client():
        status, user = await GitHubPortal.authenticate("your_token")
        if status != 200:
            return
        
        status, other = await GitHubUserPortal.get_by_username("torvalds")
        # Client closes automatically when exiting the context

asyncio.run(main())

Concurrent Requests

The client uses connection pooling, so concurrent requests share connections efficiently:

import asyncio
from asyncPyGithub import GitHubPortal, GitHubUserPortal, GitHubRepositoryPortal

async def main():
    status, user = await GitHubPortal.authenticate("your_token")
    if status != 200:
        return
    
    # All requests run concurrently over the shared client
    results = await asyncio.gather(
        GitHubUserPortal.get_by_id(user.id),
        GitHubUserPortal.get_by_username(user.login),
        GitHubUserPortal.all(since=0, per_page=5),
        GitHubRepositoryPortal.get_organization_repos("LEGO", per_page=5),
    )
    
    for status, data in results:
        if status == 200:
            print(f"OK: {type(data).__name__}")
        else:
            print(f"Error: {data.message}")
    
    await GitHubPortal.close()

asyncio.run(main())

API

Every method returns tuple[int, Result | ErrorMessage]. Check the status code first.

GitHubPortal

Method What it does
authenticate(token) Auth and get your user info. Starts client if needed.
start() Manually start the HTTP client
close() Close the HTTP client
scoped_client() Context manager that auto-closes on exit

GitHubUserPortal

Method What it does
update(changes) Update your profile
get_by_id(uid) Get user by ID
get_by_username(username) Get user by username
all(since, per_page) List users
get_hovercard(username) Get hovercard info

GitHubRepositoryPortal

Method What it does
get_organization_repos(org, ...) List org repos
create_organization_repo(org, name, ...) Create repo in org
get_user_repo(owner, repo) Get a specific repo
update_repository(owner, repo, ...) Update repo settings
delete_repository(owner, repo) Delete a repo
list_contributors(owner, repo) List contributors
list_repository_languages(owner, repo) Get language breakdown
list_repository_tags(owner, repo) List tags
get_repository_topics(owner, repo) Get topics

Error Handling

status, result = await GitHubUserPortal.get_by_username("doesnt-exist")

if status == 200:
    print(result.login)
else:
    # result is an ErrorMessage
    print(f"Error {result.code}: {result.message}")

Structure

GitHubPortal              # Base - auth, client management
├── GitHubUserPortal      # /user and /users endpoints
└── GitHubRepositoryPortal # /repos and /orgs/.../repos endpoints

All responses are Pydantic models (PrivateUser, SimpleUser, MinimalRepository, etc.).

Testing

pip install -r requirements-dev.txt
pytest

Limitations

  • No rate limit handling
  • No pagination helpers
  • No webhooks

Metadata

Release files for asyncPyGithub 0.1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asyncPyGithub 0.1.0.3
File Size Uploaded Provenance
asyncpygithub-0.1.0.3.tar.gz 28.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for asyncPyGithub 0.1.0.3
File Interpreter ABI Platform
asyncpygithub-0.1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 58.5 kB

Release files / asyncpygithub-0.1.0.3.tar.gz

Download URL asyncpygithub-0.1.0.3.tar.gz
Size 28.2 kB
Tags Source
SHA-256 checksum
How to use checksums
83b96eef1674ef2ac5f4307476dd85c1b06dbfdea8feb66665319c125314422e
BLAKE2b-256 checksum
How to use checksums
09cb72cbeb2d259e652fe98640449ba109d67e9803139555547ee6c0c215b8e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release files / asyncpygithub-0.1.0.3-py3-none-any.whl

Download URL asyncpygithub-0.1.0.3-py3-none-any.whl
Size 30.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68062e4724063b7a27eb34ee2c40461423137af737b7840a27c4506df08eb1f8
BLAKE2b-256 checksum
How to use checksums
e79496abbbf52e9d32e6161a5e56dde8ad2a1304e2d4175954e6010769fa513d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Security for asyncPyGithub 0.1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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