Package: pyforgejo
pyforgejoA client library for accessing the Forgejo API.UsageCreate a client:frompyforgejoimportAuthenticatedClientclient=AuthenticatedClient(base_url='https://codeberg.org/api/v1',token='API_TOKEN')Call an endpoint:frompyforgejo.api.userimportuser_get_currentresponse=user_get_current.sync_detailed(client=client)# async versionresponse_async=user_get_current.asyncio_detailed(client=client)response=awaitresponse_asyncprint(response)InstallationpipinstallpyforgejoForgejo APIResources:API Usage | Forgejo – Beyond coding. We forge.: user guide for the Forgejo APIForgejo API | Codeberg: API reference for CodebergForgejo API Swagger spec | Codeberg: Codeberg's Forgejo API Swagger specopenapi-generators/openapi-python-client: repo for the generator library that was used to generatepyforgejoAbout Swagger Specification | Documentation | Swagger: docs for Swagger specThe OpenAPI Specification Explained | OpenAPI Documentation: docs for OpenAPI specThe structure of the import statement for interacting with a specific endpoint follows this pattern:frompyforgejo.api.<root_path>import<operation_id>Here,<tag>is the root path or tag for the endpoint in the Swagger spec, and<operation_id>is theoperationIdfor the specific function you want to call, converted to snake case.For example, for the endpoint/repos/search, the Swagger spec is:"/repos/search":{"tags":["repository"],"operationId":"repoSearch",...}So to hit that endpoint, the import statement will be:frompyforgejo.api.repositoryimportrepo_searchEvery path/operation combo becomes a Python module with four functions:sync: Blocking request that returns parsed data (if successful) orNonesync_detailed: Blocking request that always returns aRequest, optionally withparsedset if the request was successfulasyncio: Likesyncbut async instead of blockingasyncio_detailed: Likesync_detailedbut async instead of blockingAll path/query parameters and bodies become method arguments.Developmentopenapi-python-clientpyforgejois generated withopenapi-python-client, with as of now very little modification.If you run into any issues, please create an issue in this repo.If you want to work on a PR, please consider making a PR toopenapi-python-clientrather than to this repo.openapi-python-clientwas chosen to generate this client overopenapi-generatorandfernbecause of the following reasons:openapi-python-clientis Python-specific, which allows it to leverage specific language features, have a clearer code, and offer a better developer experience, compared toopenapi-generator's one-size-fits-all approachopenapi-python-clientis written in Python, so users ofpyforgejowill be more likely to be able to make contributions and fix bugs in the generator's code itself, whileopenapi-generatoris written in Java, which represents a higher barrier to contributionsopenapi-python-clientsupports more authentication options, including access tokens, thanfernthe documentation is limited, but clearer than foropenapi-generatorGenerating the client withopenapi-python-clientConvert Forgejo'sSwagger specto OpenAPI withswagger-converter, as Swagger is not supported byopenapi-python-client.Installopenapi-python-client:pipinstallopenapi-python-clientCreate aconfig.yamlfile with the following content:project_name_override:"pyforgejo"Generate the client (this will create apyforgejo/dir):openapi-python-clientgenerate--path/path/to/forgejo_openapi.json--config/path/to/config.yamlAlternatively, update the client:gitclonehttps://codeberg.org/harabat/pyforgejo

openapi-python-clientupdate--path/path/to/forgejo_openapi.json--config./pyforgejo/config.yamlNavigate to thepyforgejo/dir and call the API:frompyforgejo.clientimportAuthenticatedClientfrompyforgejo.api.userimportuser_get_currentclient=AuthenticatedClient(base_url='FORGEJO_URL'+'/api/v1',token='ACCESS_TOKEN')response=user_get_current.sync_detailed(client=client)print(response)# Response(status_code=<HTTPStatus.OK: 200>, ...)