quart-schema


Namequart-schema JSON
Version 0.19.1 PyPI version JSON
download
home_pagehttps://gitlab.com/pgjones/quart-schema/
SummaryA Quart extension to provide schema validation
upload_time2024-02-13 22:22:50
maintainer
docs_urlNone
authorpgjones
requires_python>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Quart-Schema
============

|Build Status| |docs| |pypi| |python| |license|

Quart-Schema is a Quart extension that provides schema validation and
auto-generated API documentation. This is particularly useful when
writing RESTful APIs.

Quart-Schema can use either `msgspec
<https://jcristharif.com/msgspec>`_ or `pydantic
<https://docs.pydantic.dev>`_ to validate.

Quickstart
----------

Quart-Schema can validate an existing Quart route by decorating it
with ``validate_querystring``, ``validate_request``, or
``validate_response``. It can also validate the JSON data sent and
received over websockets using the ``send_as`` and ``receive_as``
methods.

.. code-block:: python

    from dataclasses import dataclass
    from datetime import datetime

    from quart import Quart, websocket
    from quart_schema import QuartSchema, validate_request, validate_response

    app = Quart(__name__)
    QuartSchema(app)

    @dataclass
    class Todo:
        task: str
        due: datetime | None

    @app.post("/")
    @validate_request(Todo)
    @validate_response(Todo, 201)
    async def create_todo(data: Todo) -> tuple[Todo, int]:
        ... # Do something with data, e.g. save to the DB
        return data, 201

    @app.websocket("/ws")
    async def ws() -> None:
        while True:
            data = await websocket.receive_as(Todo)
            ... # Do something with data, e.g. save to the DB
            await websocket.send_as(data, Todo)

The documentation is served by default at ``/openapi.json`` according
to the OpenAPI standard, or at ``/docs`` for a `SwaggerUI
<https://swagger.io/tools/swagger-ui/>`_ interface, or ``/redocs`` for
a `redoc <https://github.com/Redocly/redoc>`_ interface, or
``/scalar`` for a `Scalar <https://github.com/scalar/scalar>`_
interface. Note that there is currently no documentation standard for
WebSockets.

Contributing
------------

Quart-Schema is developed on `GitHub
<https://github.com/pgjones/quart-schema>`_. If you come across an
issue, or have a feature request please open an `issue
<https://github.com/pgjones/quart-schema/issues>`_. If you want to
contribute a fix or the feature-implementation please do (typo fixes
welcome), by proposing a `merge request
<https://github.com/pgjones/quart-schema/merge_requests>`_.

Testing
~~~~~~~

The best way to test Quart-Schema is with `Tox
<https://tox.readthedocs.io>`_,

.. code-block:: console

    $ pip install tox
    $ tox

this will check the code style and run the tests.

Help
----

The Quart-Schema `documentation
<https://quart-schema.readthedocs.io>`_ is the best places to
start, after that try searching `stack overflow
<https://stackoverflow.com/questions/tagged/quart>`_ or ask for help
`on gitter <https://gitter.im/python-quart/lobby>`_. If you still
can't find an answer please `open an issue
<https://github.com/pgjones/quart-schema/issues>`_.


.. |Build Status| image:: https://github.com/pgjones/quart-schema/actions/workflows/ci.yml/badge.svg
   :target: https://github.com/pgjones/quart-schema/commits/main

.. |docs| image:: https://img.shields.io/badge/docs-passing-brightgreen.svg
   :target: https://quart-schema.readthedocs.io

.. |pypi| image:: https://img.shields.io/pypi/v/quart-schema.svg
   :target: https://pypi.python.org/pypi/Quart-Schema/

.. |python| image:: https://img.shields.io/pypi/pyversions/quart-schema.svg
   :target: https://pypi.python.org/pypi/Quart-Schema/

.. |license| image:: https://img.shields.io/badge/license-MIT-blue.svg
   :target: https://github.com/pgjones/quart-schema/blob/main/LICENSE


            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.com/pgjones/quart-schema/",
    "name": "quart-schema",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "pgjones",
    "author_email": "philip.graham.jones@googlemail.com",
    "download_url": "https://files.pythonhosted.org/packages/05/fe/1876770837ae9fa5c08b633edac0e169e57451b2f7e6827b0d6f81a9f3ad/quart_schema-0.19.1.tar.gz",
    "platform": null,
    "description": "Quart-Schema\n============\n\n|Build Status| |docs| |pypi| |python| |license|\n\nQuart-Schema is a Quart extension that provides schema validation and\nauto-generated API documentation. This is particularly useful when\nwriting RESTful APIs.\n\nQuart-Schema can use either `msgspec\n<https://jcristharif.com/msgspec>`_ or `pydantic\n<https://docs.pydantic.dev>`_ to validate.\n\nQuickstart\n----------\n\nQuart-Schema can validate an existing Quart route by decorating it\nwith ``validate_querystring``, ``validate_request``, or\n``validate_response``. It can also validate the JSON data sent and\nreceived over websockets using the ``send_as`` and ``receive_as``\nmethods.\n\n.. code-block:: python\n\n    from dataclasses import dataclass\n    from datetime import datetime\n\n    from quart import Quart, websocket\n    from quart_schema import QuartSchema, validate_request, validate_response\n\n    app = Quart(__name__)\n    QuartSchema(app)\n\n    @dataclass\n    class Todo:\n        task: str\n        due: datetime | None\n\n    @app.post(\"/\")\n    @validate_request(Todo)\n    @validate_response(Todo, 201)\n    async def create_todo(data: Todo) -> tuple[Todo, int]:\n        ... # Do something with data, e.g. save to the DB\n        return data, 201\n\n    @app.websocket(\"/ws\")\n    async def ws() -> None:\n        while True:\n            data = await websocket.receive_as(Todo)\n            ... # Do something with data, e.g. save to the DB\n            await websocket.send_as(data, Todo)\n\nThe documentation is served by default at ``/openapi.json`` according\nto the OpenAPI standard, or at ``/docs`` for a `SwaggerUI\n<https://swagger.io/tools/swagger-ui/>`_ interface, or ``/redocs`` for\na `redoc <https://github.com/Redocly/redoc>`_ interface, or\n``/scalar`` for a `Scalar <https://github.com/scalar/scalar>`_\ninterface. Note that there is currently no documentation standard for\nWebSockets.\n\nContributing\n------------\n\nQuart-Schema is developed on `GitHub\n<https://github.com/pgjones/quart-schema>`_. If you come across an\nissue, or have a feature request please open an `issue\n<https://github.com/pgjones/quart-schema/issues>`_. If you want to\ncontribute a fix or the feature-implementation please do (typo fixes\nwelcome), by proposing a `merge request\n<https://github.com/pgjones/quart-schema/merge_requests>`_.\n\nTesting\n~~~~~~~\n\nThe best way to test Quart-Schema is with `Tox\n<https://tox.readthedocs.io>`_,\n\n.. code-block:: console\n\n    $ pip install tox\n    $ tox\n\nthis will check the code style and run the tests.\n\nHelp\n----\n\nThe Quart-Schema `documentation\n<https://quart-schema.readthedocs.io>`_ is the best places to\nstart, after that try searching `stack overflow\n<https://stackoverflow.com/questions/tagged/quart>`_ or ask for help\n`on gitter <https://gitter.im/python-quart/lobby>`_. If you still\ncan't find an answer please `open an issue\n<https://github.com/pgjones/quart-schema/issues>`_.\n\n\n.. |Build Status| image:: https://github.com/pgjones/quart-schema/actions/workflows/ci.yml/badge.svg\n   :target: https://github.com/pgjones/quart-schema/commits/main\n\n.. |docs| image:: https://img.shields.io/badge/docs-passing-brightgreen.svg\n   :target: https://quart-schema.readthedocs.io\n\n.. |pypi| image:: https://img.shields.io/pypi/v/quart-schema.svg\n   :target: https://pypi.python.org/pypi/Quart-Schema/\n\n.. |python| image:: https://img.shields.io/pypi/pyversions/quart-schema.svg\n   :target: https://pypi.python.org/pypi/Quart-Schema/\n\n.. |license| image:: https://img.shields.io/badge/license-MIT-blue.svg\n   :target: https://github.com/pgjones/quart-schema/blob/main/LICENSE\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Quart extension to provide schema validation",
    "version": "0.19.1",
    "project_urls": {
        "Homepage": "https://gitlab.com/pgjones/quart-schema/",
        "Repository": "https://gitlab.com/pgjones/quart-schema/"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "22106c4c3b51a141f12881bf16acb88a6b4082b43b75a5a5334251572c70a90c",
                "md5": "763b91f36f09fe7be6a896886e9691ab",
                "sha256": "43f76f7ea687464c807eaf1bf18d8aa1e970ec3c3800386f01206a39de86ce9a"
            },
            "downloads": -1,
            "filename": "quart_schema-0.19.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "763b91f36f09fe7be6a896886e9691ab",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 19420,
            "upload_time": "2024-02-13T22:22:49",
            "upload_time_iso_8601": "2024-02-13T22:22:49.016710Z",
            "url": "https://files.pythonhosted.org/packages/22/10/6c4c3b51a141f12881bf16acb88a6b4082b43b75a5a5334251572c70a90c/quart_schema-0.19.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "05fe1876770837ae9fa5c08b633edac0e169e57451b2f7e6827b0d6f81a9f3ad",
                "md5": "7a74f52134c51306179b1808252476ba",
                "sha256": "2c3e6b2d838b220a80dec88c89aa32b2f080c5527ec3eb31a1b5819423753037"
            },
            "downloads": -1,
            "filename": "quart_schema-0.19.1.tar.gz",
            "has_sig": false,
            "md5_digest": "7a74f52134c51306179b1808252476ba",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 17297,
            "upload_time": "2024-02-13T22:22:50",
            "upload_time_iso_8601": "2024-02-13T22:22:50.954740Z",
            "url": "https://files.pythonhosted.org/packages/05/fe/1876770837ae9fa5c08b633edac0e169e57451b2f7e6827b0d6f81a9f3ad/quart_schema-0.19.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-13 22:22:50",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "pgjones",
    "gitlab_project": "quart-schema",
    "lcname": "quart-schema"
}
        
Elapsed time: 0.31664s