API schema generation and input validation for aiohttp.web.
Installation
Install from PyPI:
pip install aiohttp-apischema
Developing
Install requirement and launch tests:
pip install -r requirements-dev.txt pytest
Basic usage
First create a SchemaGenerator instance:
from aiohttp_apischema import SchemaGenerator
SCHEMA = SchemaGenerator()
Then decorate endpoint handlers which should be included in the schema:
from aiohttp_apischema import APIResponse
@SCHEMA.api()
async def foo(request: web.Request) -> APIResponse[list[str], Literal[200]]:
return APIResponse(["foo"])
Or for Class Based Views:
@SCHEMA.api_view()
class Handler(web.View):
async def get(self) -> APIResponse[int, Literal[200]] | APIResponse[None, Literal[404]]:
bar_id = int(self.request.match_info["id"])
if bar_id == 1:
return APIResponse(42)
return APIResponse[None, Literal[404]](None, status=404)
Then call the setup method when building your app:
app = web.Application()
app.router.add_get("/foo", foo)
app.router.add_view(r"/bar/{id:\d+}", Handler)
SCHEMA.setup(app)
You can now view the docs under the /swagger/ path.
Validation usage
Validation of the request body is achieved by adding a positional parameter:
async def handler(request: web.Request, body: dict[int, str]) -> APIResponse[int, Literal[200]]:
# body has been validated, so we can be sure the keys are int now.
return APIResponse(sum(body.keys()))
License
aiohttp_apischema is offered under the Apache 2 license.
Release files for aiohttp-apischema 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aiohttp_apischema-0.0.2.tar.gz | 1.2 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aiohttp_apischema-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 2.3 MB
Release files / aiohttp_apischema-0.0.2.tar.gz
| Download URL | aiohttp_apischema-0.0.2.tar.gz |
|---|---|
| Size | 1.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
983cd2a30217e71220caa112694f527afb817446bb8efaada0552216bb843c8f
|
|
BLAKE2b-256 checksum How to use checksums |
63cf7633ce17f1cc4b0f9c1fd1ba4173709baf9821fcd14762660dfc37e0f398
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 23, 2025.
Transparency logRelease files / aiohttp_apischema-0.0.2-py3-none-any.whl
| Download URL | aiohttp_apischema-0.0.2-py3-none-any.whl |
|---|---|
| Size | 1.2 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
00835c79107c41ed019368c9f4cb1cf0b36f35ca36975a6b93dbddd7158b6c82
|
|
BLAKE2b-256 checksum How to use checksums |
e0f78251d389e6f26377b6c69f358e9de17983a97b934cd7e5d19d3d999e4ef2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 23, 2025.
Transparency log