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.
pip install ghapiVerified import paths — ran on the pinned version, not inferred.
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.
Set `GITHUB_TOKEN` environment variable or pass `token='YOUR_TOKEN'` to `GhApi()` during initialization.
Ensure `branch`, `author`, and `committer` are provided in file update calls (e.g., `api.repos.update_file()`).
Be aware of the expected return type for non-JSON media types and handle the string output accordingly.
Explicitly install `GitPython` (`pip install GitPython`) if your project requires it.
Upgrade to GhApi 1.0.13 or newer to ensure correct decoding of non-binary types and proper handling of binary content.
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.
Install the library using pip: `pip install ghapi` or if using conda: `conda install -c fastai ghapi`. Ensure your Python environment is correctly configured.
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.
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.