{"library":"ghapi","title":"GhApi","description":"GhApi is a Python client for the GitHub API, providing 100% always-updated coverage by automatically converting the OpenAPI spec. It allows automation of various GitHub tasks, including managing issues, pull requests, releases, GitHub Actions, and more. The current version is 1.0.13, and it has a regular release cadence with several minor updates in recent months.","status":"active","version":"1.0.13","language":"en","source_language":"en","source_url":"https://github.com/fastai/ghapi","tags":["github","api","client","fastai","automation","rest"],"install":[{"cmd":"pip install ghapi","lang":"bash","label":"PyPI"},{"cmd":"conda install -c fastai ghapi","lang":"bash","label":"Conda"}],"dependencies":[{"reason":"Commonly used in the fast.ai ecosystem for utility functions and object extensions, often implicitly relied upon by users for a more 'Pythonic' experience, especially when using `ghapi.all`.","package":"fastcore","optional":true}],"imports":[{"note":"The primary `GhApi` class and all its sub-APIs are conveniently exposed via `ghapi.all` for a complete interface. Direct imports from submodules (e.g., `ghapi.repos`) are also possible for specific functionality.","wrong":"from ghapi import GhApi","symbol":"GhApi","correct":"from ghapi.all import GhApi"}],"quickstart":{"code":"import os\nfrom ghapi.all import GhApi\n\n# Initialize GhApi. It will automatically use GITHUB_TOKEN from environment if available.\n# For unauthenticated calls, you can initialize without a token if no authenticated endpoints are used.\n# Alternatively, pass a token explicitly: api = GhApi(token=\"YOUR_GITHUB_TOKEN\")\n# Set authenticate=False to explicitly create an unauthenticated client even if GITHUB_TOKEN is set.\napi = GhApi(token=os.environ.get('GITHUB_TOKEN', ''))\n\n# Example: Get user information for a public user (can be unauthenticated)\ntry:\n    user_info = api.users.get_by_username(username='fastai')\n    print(f\"User: {user_info.login}, Public Repos: {user_info.public_repos}\")\nexcept Exception as e:\n    print(f\"Could not retrieve user info: {e}. Ensure username is correct and token (if needed) is valid.\")\n\n# Example: Get a list of repositories for an organization (requires authentication for private repos)\n# Note: 'owner' and 'repo' can also be passed to GhApi constructor for auto-insertion.\nif os.environ.get('GITHUB_TOKEN'):\n    try:\n        # For this example, let's assume we want repos for 'fastai'\n        org_repos = api.repos.list_for_org(org='fastai')\n        print(f\"\\nFirst 3 repos in 'fastai' organization:\")\n        for i, repo in enumerate(org_repos[:3]):\n            print(f\"- {repo.name}\")\n    except Exception as e:\n        print(f\"\\nCould not list organization repos: {e}. Check token scopes and organization name.\")\nelse:\n    print(\"\\nSkipping organization repo listing as GITHUB_TOKEN is not set.\")","lang":"python","description":"Initializes the GhApi client, demonstrating how to fetch public user information and, if authenticated with a `GITHUB_TOKEN` environment variable, list repositories for an organization. `GhApi` dynamically generates methods based on the GitHub API, providing a Pythonic interface."},"warnings":[{"fix":"Set `GITHUB_TOKEN` environment variable or pass `token='YOUR_TOKEN'` to `GhApi()` during initialization.","message":"For authenticated operations, a GitHub Personal Access Token (PAT) is required. GhApi will automatically use the `GITHUB_TOKEN` environment variable if available, otherwise, you must pass it explicitly to the `GhApi` constructor. An `authenticate=False` flag can be used to override this behavior and create an unauthenticated client even if the token is present.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `branch`, `author`, and `committer` are provided in file update calls (e.g., `api.repos.update_file()`).","message":"When updating files via the API, GitHub now explicitly requires `branch`, `author`, and `committer` parameters. Older code that omits these for file updates will fail.","severity":"breaking","affected_versions":"Prior to 1.0.6"},{"fix":"Be aware of the expected return type for non-JSON media types and handle the string output accordingly.","message":"When working with media types that are not JSON (e.g., `application/vnd.github.v3.sha`), `GhApi` might return a raw string instead of a parsed Python object.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Explicitly install `GitPython` (`pip install GitPython`) if your project requires it.","message":"The `GitPython` library was removed as a dependency in `v1.0.8`. If your project implicitly relied on `GhApi` installing `GitPython` as a transitive dependency, you will now need to add `GitPython` as a direct dependency to your project.","severity":"deprecated","affected_versions":"Prior to 1.0.8"},{"fix":"Upgrade to GhApi 1.0.13 or newer to ensure correct decoding of non-binary types and proper handling of binary content.","message":"Previous versions (before 1.0.13) might have incorrectly decoded binary response types, potentially leading to errors or corrupted data when fetching certain content.","severity":"gotcha","affected_versions":"Prior to 1.0.13"}],"env_vars":null,"last_verified":"2026-04-05T00:00:00.000Z","next_check":"2026-07-04T00:00:00.000Z"}