gh_util
A minimal Python library for interacting with GitHub's API, using httpx and Pydantic.
NOTE
This library is under active development and will likely change.
Installation
pip install gh_util
Either set GH_UTIL_TOKEN or GITHUB_TOKEN as an env var or in a .env file to enable authenticated requests and increase your rate limit.
Usage
Get the current user's GitHub profile
from devtools import debug
from gh_util.client import GHClient
from gh_util.types import GitHubUser
async def get_current_user() -> GitHubUser:
async with GHClient() as client:
response = await client.get("/user")
return GitHubUser.model_validate(response.json())
if __name__ == "__main__":
import asyncio
debug(asyncio.run(get_current_user()))
Output
# [01/22/24 00:23:18] DEBUG gh_util.client: AUTH: Using GitHub token set in environment via `GH_UTIL_TOKEN`
<ipython-input-1-8745118bb0ba>:12 <module>
asyncio.run(get_current_user()): GitHubUser(
login='zzstoatzz',
url=Url('https://api.github.com/users/zzstoatzz'),
id=31014960,
node_id='MDQ6VXNlcjMxMDE0OTYw',
avatar_url='https://avatars.githubusercontent.com/u/31014960?v=4',
gravatar_id='',
html_url='https://github.com/zzstoatzz',
followers_url='https://api.github.com/users/zzstoatzz/followers',
following_url='https://api.github.com/users/zzstoatzz/following{/other_user}',
gists_url='https://api.github.com/users/zzstoatzz/gists{/gist_id}',
starred_url='https://api.github.com/users/zzstoatzz/starred{/owner}{/repo}',
subscriptions_url='https://api.github.com/users/zzstoatzz/subscriptions',
organizations_url='https://api.github.com/users/zzstoatzz/orgs',
repos_url='https://api.github.com/users/zzstoatzz/repos',
events_url='https://api.github.com/users/zzstoatzz/events{/privacy}',
received_events_url='https://api.github.com/users/zzstoatzz/received_events',
type='User',
site_admin=False,
name='nate nowack',
company='@PrefectHQ ',
blog='askmarvin.ai',
location='Chicago, IL',
email='nate@prefect.io',
hireable=None,
bio=(
'data + software engineering @ Prefect\r\n'
'\r\n'
'building PrefectHQ/marvin'
),
twitter_username=None,
public_repos=52,
public_gists=23,
followers=47,
following=12,
created_at='2017-08-14T18:02:41Z',
updated_at='2024-01-17T14:34:54Z',
private_gists=15,
total_private_repos=6,
owned_private_repos=6,
disk_usage=179750,
collaborators=0,
two_factor_authentication=True,
plan={
'name': 'pro',
'space': 976562499,
'collaborators': 0,
'private_repos': 9999,
},
) (GitHubUser)
Read a GitHub issue and its comments
from gh_util.functions import fetch_repo_issue
from gh_util.print import print_repo_issue
async def main():
issue = await fetch_repo_issue("prefecthq", "marvin", 723, include_comments=True)
print_repo_issue(issue)
if __name__ == "__main__":
import asyncio
asyncio.run(main())
Output
Metadata
Release files for gh-util 0.1.16
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gh_util-0.1.16.tar.gz | 10.4 MB | Without provenance | Details for gh_util-0.1.16.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gh_util-0.1.16-py3-none-any.whl | Python 3 | none | any | Details for gh_util-0.1.16-py3-none-any.whl |
Total release size: 10.5 MB
Release files / gh_util-0.1.16.tar.gz
| Download URL | gh_util-0.1.16.tar.gz |
|---|---|
| Size | 10.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7cfbaca104edf48c7027bfa0c6ad38cbbf7d1d269c005ca297db89fd56973bd9
|
|
BLAKE2b-256 checksum How to use checksums |
289509df6e9e5cc6840f6d85ee984d5ee3ce5b74a290aea0934aa3f481c66b5d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Release files / gh_util-0.1.16-py3-none-any.whl
| Download URL | gh_util-0.1.16-py3-none-any.whl |
|---|---|
| Size | 21.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
21bd1a8b8071d7e987a402608d92b27b194aa04b1fdb8a08c24616f79879d682
|
|
BLAKE2b-256 checksum How to use checksums |
c5b7776397cd912a08b82f7898fdaed6bbd41467b96be27d7645aae3852232d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Security for gh-util 0.1.16
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.