Skip to main content

aiohttp_validate

https://img.shields.io/pypi/v/aiohttp_validate.svg https://github.com/dchaplinsky/aiohttp_validate/actions/workflows/tests.yml/badge.svg

Simple library that helps you validate your API endpoints requests/responses with jsonschema. Requires Python 3.9+ and aiohttp 3.8+.

Installation

Install from PyPI:

pip install aiohttp_validate

Usage

Complete example of validation for text tokenization microservice:

from aiohttp_validate import validate

@validate(
    request_schema={
        "type": "object",
        "properties": {
            "text": {"type": "string"},
        },
        "required": ["text"],
        "additionalProperties": False
    },
    response_schema={
        "type": "array",
        "items": {
            "type": "array",
            "items": {
                "type": "array",
                "items": {"type": "string"}
            }
        }
    }
)
async def tokenize_text_handler(request, *args):
    return tokenize_text(request["text"])

The wrapped handler receives the parsed and validated JSON body as its first argument and the original aiohttp request object as the second:

async def handler(data, request):
    pool = request.app["redis_pool"]  # the real request is right here
    ...

To respond with a status code other than 200, return a (data, status) tuple:

async def create_handler(data, request):
    return {"id": new_id}, 201

The tuple form is detected by shape (a 2-tuple ending in an int), so if your response data is itself such a tuple, return it as a list instead — JSON has no tuples, the wire format is identical — or return a ready web.json_response.

To also validate string formats (date, email, …), pass a format checker (extra format support follows jsonschema’s rules):

@validate(request_schema=..., format_checker=jsonschema.FormatChecker())

Features

  • The decorator to (optionally) validate the request to your aiohttp endpoint and it’s response.

  • Easily integrates with aiohttp_swaggerify to automatically document your endpoints with swagger.

  • Validation errors are standardized and can be easily parsed by the clients of your service and also human-readable.

Developing

Install with test dependencies and launch tests:

pip install -e .[test]
pytest

Credits

That package is influenced by Tornado-JSON written by Hamza Faran Code to parse errors is written by Ruslan Karalkin

Versioning

This software follows Semantic Versioning

License

  • Free software: MIT license

Release files for aiohttp-validate 2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiohttp-validate 2.0
File Size Uploaded
aiohttp_validate-2.0.tar.gz 7.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aiohttp-validate 2.0
File Interpreter ABI Platform
aiohttp_validate-2.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.1 kB

Release files / aiohttp_validate-2.0.tar.gz

Download URL aiohttp_validate-2.0.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c95cdd099b634011ee57e83bccd12a8e758475f97d968a172635b11909119c07
BLAKE2b-256 checksum
How to use checksums
147f204625eb0f92ce5c852439b636534ffb43bfa5c2a5ba25f3829870c0d292
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

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 Jul 19, 2026.

Transparency log

Release files / aiohttp_validate-2.0-py3-none-any.whl

Download URL aiohttp_validate-2.0-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
be9436814e807f61ac0964c98705a665d8828b8966946912ee9e563b14fcc153
BLAKE2b-256 checksum
How to use checksums
e3939da15770f6c3188e1d04ea02003ffdd8c17caf844524fb22a548e90dd733
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

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 Jul 19, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.0 This release

2 release files

1.1.0

1 release file

1.0.1

1 release file

1.0.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page