gh-util


Namegh-util JSON
Version 0.1.13 PyPI version JSON
download
home_pageNone
SummaryMinimal LLM friendly Python client for GitHub API.
upload_time2024-04-06 04:45:36
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords github api client python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```bash
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
```python
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()))
```
<details>
<summary>Output</summary>

```python
# [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)

```
</details>

### Read a GitHub issue and its comments
```python
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())
```

<details>
<summary>Output</summary>

![read issue demo](docs/assets/gifs/gh-util-demo-read-issue.gif)

</details>

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "gh-util",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "github, api, client, python",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/da/df/8f0fc06bd17935cd52f69eb18c9bce18df0aa657de49119dac7843c1f96e/gh_util-0.1.13.tar.gz",
    "platform": null,
    "description": "# gh_util\n\nA minimal Python library for interacting with GitHub's API, using `httpx` and `Pydantic`.\n\n## **NOTE**\nThis library is under active development and will likely change.\n\n\n## Installation\n\n```bash\npip install gh_util\n```\n\nEither 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.\n\n## Usage\n\n### Get the current user's GitHub profile\n```python\nfrom devtools import debug\nfrom gh_util.client import GHClient\nfrom gh_util.types import GitHubUser\n\nasync def get_current_user() -> GitHubUser:\n    async with GHClient() as client:\n        response = await client.get(\"/user\")\n        return GitHubUser.model_validate(response.json())\n\nif __name__ == \"__main__\":\n    import asyncio\n    debug(asyncio.run(get_current_user()))\n```\n<details>\n<summary>Output</summary>\n\n```python\n# [01/22/24 00:23:18] DEBUG    gh_util.client: AUTH: Using GitHub token set in environment via `GH_UTIL_TOKEN`\n<ipython-input-1-8745118bb0ba>:12 <module>\n    asyncio.run(get_current_user()): GitHubUser(\n        login='zzstoatzz',\n        url=Url('https://api.github.com/users/zzstoatzz'),\n        id=31014960,\n        node_id='MDQ6VXNlcjMxMDE0OTYw',\n        avatar_url='https://avatars.githubusercontent.com/u/31014960?v=4',\n        gravatar_id='',\n        html_url='https://github.com/zzstoatzz',\n        followers_url='https://api.github.com/users/zzstoatzz/followers',\n        following_url='https://api.github.com/users/zzstoatzz/following{/other_user}',\n        gists_url='https://api.github.com/users/zzstoatzz/gists{/gist_id}',\n        starred_url='https://api.github.com/users/zzstoatzz/starred{/owner}{/repo}',\n        subscriptions_url='https://api.github.com/users/zzstoatzz/subscriptions',\n        organizations_url='https://api.github.com/users/zzstoatzz/orgs',\n        repos_url='https://api.github.com/users/zzstoatzz/repos',\n        events_url='https://api.github.com/users/zzstoatzz/events{/privacy}',\n        received_events_url='https://api.github.com/users/zzstoatzz/received_events',\n        type='User',\n        site_admin=False,\n        name='nate nowack',\n        company='@PrefectHQ ',\n        blog='askmarvin.ai',\n        location='Chicago, IL',\n        email='nate@prefect.io',\n        hireable=None,\n        bio=(\n            'data + software engineering @ Prefect\\r\\n'\n            '\\r\\n'\n            'building PrefectHQ/marvin'\n        ),\n        twitter_username=None,\n        public_repos=52,\n        public_gists=23,\n        followers=47,\n        following=12,\n        created_at='2017-08-14T18:02:41Z',\n        updated_at='2024-01-17T14:34:54Z',\n        private_gists=15,\n        total_private_repos=6,\n        owned_private_repos=6,\n        disk_usage=179750,\n        collaborators=0,\n        two_factor_authentication=True,\n        plan={\n            'name': 'pro',\n            'space': 976562499,\n            'collaborators': 0,\n            'private_repos': 9999,\n        },\n    ) (GitHubUser)\n\n```\n</details>\n\n### Read a GitHub issue and its comments\n```python\nfrom gh_util.functions import fetch_repo_issue\nfrom gh_util.print import print_repo_issue\n\n\nasync def main():\n    issue = await fetch_repo_issue(\"prefecthq\", \"marvin\", 723, include_comments=True)\n    print_repo_issue(issue)\n\n\nif __name__ == \"__main__\":\n    import asyncio\n\n    asyncio.run(main())\n```\n\n<details>\n<summary>Output</summary>\n\n![read issue demo](docs/assets/gifs/gh-util-demo-read-issue.gif)\n\n</details>\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Minimal LLM friendly Python client for GitHub API.",
    "version": "0.1.13",
    "project_urls": {
        "Code": "https://github.com/zzstoatzz/gh"
    },
    "split_keywords": [
        "github",
        " api",
        " client",
        " python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2b1ecab100558594686d814eb3f559dc47c0fe0e569c0e3e2e8cf44f532f2e6e",
                "md5": "1fcb471bc5e4aec86a572cce569369f6",
                "sha256": "a0fa1e75d57cf4a4dc1ea3ae88fd1843709fea8a5531148f0a7e69f0dd4eecb3"
            },
            "downloads": -1,
            "filename": "gh_util-0.1.13-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1fcb471bc5e4aec86a572cce569369f6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 20080,
            "upload_time": "2024-04-06T04:45:34",
            "upload_time_iso_8601": "2024-04-06T04:45:34.199567Z",
            "url": "https://files.pythonhosted.org/packages/2b/1e/cab100558594686d814eb3f559dc47c0fe0e569c0e3e2e8cf44f532f2e6e/gh_util-0.1.13-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dadf8f0fc06bd17935cd52f69eb18c9bce18df0aa657de49119dac7843c1f96e",
                "md5": "26b3e85a321b7d9dd403eac6f372eeb6",
                "sha256": "0aca64da86f0040b1572706ed53e4e82e5e3409800c47fe5d5472915ac93410f"
            },
            "downloads": -1,
            "filename": "gh_util-0.1.13.tar.gz",
            "has_sig": false,
            "md5_digest": "26b3e85a321b7d9dd403eac6f372eeb6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 10445067,
            "upload_time": "2024-04-06T04:45:36",
            "upload_time_iso_8601": "2024-04-06T04:45:36.203687Z",
            "url": "https://files.pythonhosted.org/packages/da/df/8f0fc06bd17935cd52f69eb18c9bce18df0aa657de49119dac7843c1f96e/gh_util-0.1.13.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-06 04:45:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "zzstoatzz",
    "github_project": "gh",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "gh-util"
}
        
Elapsed time: 0.34394s