Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Publish to PyPI

on:
push:
tags: ["v*"]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: Build sdist and wheel
run: |
pip install build
python -m build

- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/

publish:
needs: build
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write

steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/

- uses: pypa/gh-action-pypi-publish@release/v1
27 changes: 27 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Tests

on:
push:
branches: [master]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install package with test dependencies
run: pip install -e .[test]

- name: Run tests
run: pytest -v
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

17 changes: 17 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
History
=======

2.0 (2026-07-19)
------------------

* Revived for modern Python: works on Python 3.9-3.13 (the removal of
``asyncio.coroutine`` in Python 3.11 had made the library unusable there).
* Handlers may return a ``(data, status)`` tuple to set the response status.
(Breaking edge case: a handler that previously returned exactly such a
tuple *as response data* must now return a list instead.)
* Optional ``format_checker`` argument to also validate string formats.
* Schema validators are built once at decoration time instead of on
every request.
* Plain (non-async) handlers are still supported.
* Type hints and a ``py.typed`` marker.
* Modern packaging (``pyproject.toml``), tests on GitHub Actions, releases
via PyPI trusted publishing.


1.0.0 (2016-12-12)
------------------

Expand Down
13 changes: 0 additions & 13 deletions MANIFEST.in

This file was deleted.

88 changes: 0 additions & 88 deletions Makefile

This file was deleted.

45 changes: 31 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,11 @@ aiohttp_validate
.. image:: https://img.shields.io/pypi/v/aiohttp_validate.svg
:target: https://pypi.python.org/pypi/aiohttp_validate

.. image:: https://img.shields.io/travis/dchaplinsky/aiohttp_validate.svg
:target: https://travis-ci.org/dchaplinsky/aiohttp_validate
.. image:: https://github.com/dchaplinsky/aiohttp_validate/actions/workflows/tests.yml/badge.svg
:target: https://github.com/dchaplinsky/aiohttp_validate/actions/workflows/tests.yml

.. image:: https://readthedocs.org/projects/aiohttp-validate/badge/?version=latest
:target: https://aiohttp-validate.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

.. image:: https://pyup.io/repos/github/dchaplinsky/aiohttp_validate/shield.svg
:target: https://pyup.io/repos/github/dchaplinsky/aiohttp_validate/
:alt: Updates


Simple library that helps you validate your API endpoints requests/responses with jsonschema_. Documentation is also available here at https://aiohttp-validate.readthedocs.io.
Simple library that helps you validate your API endpoints requests/responses with jsonschema_. Requires Python 3.9+ and aiohttp 3.8+.



Expand Down Expand Up @@ -57,6 +49,31 @@ Complete example of validation for `text tokenization microservice`_::
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())

.. _jsonschema's rules: https://python-jsonschema.readthedocs.io/en/stable/validate/#validating-formats

Features
--------
* The decorator to (optionally) validate the request to your aiohttp endpoint and it's response.
Expand All @@ -67,10 +84,10 @@ Features
Developing
----------

Install requirement and launch tests::
Install with test dependencies and launch tests::

pip install -r requirements-dev.txt
py.test
pip install -e .[test]
pytest


Credits
Expand Down
Loading
Loading