forgejo
Async Python client for the Forgejo REST API. Forgejo keeps API compatibility with Gitea, so this works against Gitea instances too.
The library covers the read-only surface needed to monitor a forge: version, account, unread notifications, repository counters, the latest Actions run, and the tip commit. It has no Home Assistant dependency — if that is what you are after, see HA-Forgejo.
Install
pip install forgejo
Requires Python 3.12+.
Use
import asyncio
from forgejo import ForgejoClient
async def main() -> None:
async with ForgejoClient("https://git.example.com", token="your-api-token") as client:
server = await client.get_version()
print(f"Forgejo {server.version}")
me = await client.get_authenticated_user()
print(f"Signed in as {me.login}")
print(f"{await client.get_new_notification_count()} unread notifications")
repo = await client.get_repository("example-user", "example-repo")
print(f"{repo.full_name}: {repo.open_issues} issues, {repo.open_pull_requests} PRs")
run = await client.get_latest_workflow_run("example-user", "example-repo")
if run is not None:
print(f"Last CI run: {run.name} -> {run.status}")
asyncio.run(main())
Bring your own session
Pass an existing aiohttp.ClientSession and the client will use it and leave it
open. This is what you want inside a larger application that already pools
connections.
async with aiohttp.ClientSession() as session:
client = ForgejoClient("https://git.example.com", token="...", session=session)
Self-signed certificates
Instances on a private network often use a certificate the system trust store does not know about.
client = ForgejoClient("https://git.internal", token="...", verify_ssl=False)
Turning verification off means the connection is encrypted but unauthenticated. Prefer installing the CA certificate where possible.
Getting a token
In the web UI: Settings → Applications → Generate New Token. Read-only scopes are enough:
read:repository— repository counters, Actions runs, commitsread:issue— issue and pull-request countsread:notification— unread notification countread:user— the account the token belongs to
Everything except get_version() needs a token.
API
| Method | Returns |
|---|---|
get_version() |
ServerInfo |
get_authenticated_user() |
User |
get_new_notification_count() |
int |
list_repositories(limit=50) |
list[Repository] |
get_repository(owner, repo) |
Repository |
get_latest_workflow_run(owner, repo) |
WorkflowRun | None |
get_latest_commit(owner, repo) |
Commit | None |
Methods return dataclasses, never raw dictionaries. None means the thing does
not exist — a repository with no workflows, or an empty repository with no
commits — which is different from an error.
Errors
All exceptions derive from ForgejoError:
ForgejoConnectionError— unreachable or timed outForgejoAuthenticationError— token rejected or missing a scopeForgejoNotFoundError— no such repository or endpointForgejoResponseError— answered, but not with usable JSON
A common cause of ForgejoResponseError is an auth proxy in front of the
instance returning its own login page with HTTP 200.
Notes on the API
open_issuesexcludes pull requests. Pull requests are counted separately inopen_pull_requests. This surprises people coming from the GitHub API, where the equivalent field includes both.- A workflow run status is only meaningful once it reaches a terminal state.
TERMINAL_RUN_STATUSESholds the set; anything else means still running, which is not the same as failing.
License
MIT
Metadata
Release files for forgejo 1.0.0
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 |
|---|---|---|---|---|
| forgejo-1.0.0.tar.gz | 11.2 kB | Without provenance | Details for forgejo-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| forgejo-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for forgejo-1.0.0-py3-none-any.whl |
Total release size: 22.2 kB
Release files / forgejo-1.0.0.tar.gz
| Download URL | forgejo-1.0.0.tar.gz |
|---|---|
| Size | 11.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
10a30fdbee06b34ba00dcbff39bfeefa85917387675e8b9b48b577fc516c2d07
|
|
BLAKE2b-256 checksum How to use checksums |
607540468708dc1db5af388619a06c037903c74dabc5d2f1706e55ffa04895cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / forgejo-1.0.0-py3-none-any.whl
| Download URL | forgejo-1.0.0-py3-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
406aa08de6bbc2bcfa368c9442a2b31740b297608cd9679c83b9c6e933be3523
|
|
BLAKE2b-256 checksum How to use checksums |
d1658e3a6807b8aebc219ccf6da2e11fcc51952e8b9e429047fdb647630f5120
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Security for forgejo 1.0.0
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.