Skip to main content

A Quart extension to provide schema validation

Project description

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.

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,

from datetime import datetime
from typing import Optional

from pydantic.dataclasses import dataclass
from quart import Quart
from quart_schema import QuartSchema, validate_request, validate_response

app = Quart(__name__)
QuartSchema(app)

@dataclass
class Todo:
    task: str
    due: Optional[datetime]

@app.route("/", methods=["POST"])
@validate_request(Todo)
@validate_response(Todo, 201)
async def create_todo(data: Todo) -> Todo:
    ... # 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 tot eh OpenAPI standard, or at /docs for a SwaggerUI interface, or /redocs for a redoc interface. Note that there is currently no documentation standard for WebSockets.

Contributing

Quart-Schema is developed on GitLab. If you come across an issue, or have a feature request please open an issue. If you want to contribute a fix or the feature-implementation please do (typo fixes welcome), by proposing a merge request.

Testing

The best way to test Quart-Schema is with Tox,

$ pip install tox
$ tox

this will check the code style and run the tests.

Help

The Quart-Schema documentation is the best places to start, after that try searching stack overflow or ask for help on gitter. If you still can’t find an answer please open an issue.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quart-schema-0.6.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quart_schema-0.6.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file quart-schema-0.6.0.tar.gz.

File metadata

  • Download URL: quart-schema-0.6.0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.2 Linux/5.4.0-1037-aws

File hashes

Hashes for quart-schema-0.6.0.tar.gz
Algorithm Hash digest
SHA256 6ebeaa2e84cee10d6165b84f995651ea717cdb41f4ba95ff3e2ae7d324db98ca
MD5 c391529b296935c57877a2ad979cf29e
BLAKE2b-256 5244d786fc37cf835f7e651a807819e78f028ecccaa8a45d5df35aec3b292da6

See more details on using hashes here.

File details

Details for the file quart_schema-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: quart_schema-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.2 Linux/5.4.0-1037-aws

File hashes

Hashes for quart_schema-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cbe6c2516ee0aba93cd9b3d1795d77ad197b1e103ae306e7a1a2887e7324707b
MD5 0f34db3519e1c3cf38a7920025b065ed
BLAKE2b-256 ed3a6f8c38349610969f5adae0c1f0e8fc18e337c8dd6f0e44d4acb3aa85a71c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page