{"id":1100,"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":"python","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,"search_vec":"'1.0.13':44 '100':12 'action':37 'allow':24 'alway':14 'always-upd':13 'api':10,60 'autom':25,63 'automat':18 'cadenc':51 'client':6,61 'convert':19 'coverag':16 'current':41 'fastai':62 'ghapi':1,2 'github':9,28,36,59 'includ':30 'issu':32 'manag':31 'minor':54 'month':58 'openapi':21 'provid':11 'pull':33 'python':5 'recent':57 'regular':49 'releas':35,50 'request':34 'rest':64 'sever':53 'spec':22 'task':29 'updat':15,55 'various':27 'version':42","created_at":"2026-04-05T13:05:42.434871+00:00","updated_at":"2026-04-16T15:16:02.126135+00:00","problems":[{"fix":"Ensure you are using a valid GitHub Personal Access Token (PAT) with the necessary scopes enabled for the API operation you are trying to perform. You can create a PAT in your GitHub settings under Developer settings > Personal access tokens. Initialize `GhApi` with `api = GhApi(token='YOUR_GITHUB_TOKEN')` or ensure the `GITHUB_TOKEN` environment variable is correctly set.","cause":"This error, or a `401 Client Error: Unauthorized`, indicates that the GitHub API token provided is invalid, has insufficient scopes (permissions), or has expired.","error":"{ \"message\": \"Bad credentials\", \"documentation_url\": \"https://docs.github.com/rest\" }"},{"fix":"Install the library using pip: `pip install ghapi` or if using conda: `conda install -c fastai ghapi`. Ensure your Python environment is correctly configured.","cause":"The `ghapi` library is not installed in your current Python environment, or your Python interpreter cannot find the installed package.","error":"ModuleNotFoundError: No module named 'ghapi'"},{"fix":"Consult the `ghapi` documentation or the GitHub API reference to find the correct operation name and its group (e.g., `api.repos.create_commit` instead of `api.repo.make_commit`). You can also inspect the `api` object (e.g., `api.git.` and press Tab in an interactive console) to discover available methods.","cause":"You are trying to call an API endpoint or access a property that does not exist or is misspelled within the `ghapi` object structure. `ghapi` dynamically generates its API methods from the OpenAPI spec, so the method names must exactly match the GitHub API operations.","error":"AttributeError: 'GhApi' object has no attribute 'some_nonexistent_method'"},{"fix":"This often points to an underlying authentication or authorization issue. Ensure your GitHub API token has the correct `repo` scopes and permissions to access the specific private resource. Double-check that the token is correctly passed and is not expired.","cause":"When accessing private GitHub resources (like a private repository or private issue), GitHub's API returns a `404 Not Found` error instead of `403 Forbidden` if authentication is missing or insufficient. This is a security measure to prevent information leakage about private assets.","error":"404 Not Found (for an existing resource)"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.0.13","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/fastai/ghapi","docs":"https://ghapi.fast.ai/","changelog":null,"pypi":"https://pypi.org/project/ghapi/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":"verified"}}