Skip to main content

flaskdocs is a lightweight wrapper around a flask app which aims to centralize both validation and documentation of an API. Declare the schemas you're accept/return, and flaskdocs will let you generate an openapi.json file, as well as validating incoming requests and returning errors to the client if a request doesn't match the given schema.

Example usage:

Declare a flask app and pass it to a flaskdocs API as follows:

from flask import Flask, jsonify

from flaskdocs import API
from flaskdocs.schema import (
    JsonSchema,
    QueryParameterSchema,
    Literal,
    Use,
)

app = Flask(__name__)

api = API(
    title="example",
    version="0.0.1",
    description="Here's an example API",
    app=app,
)

@api.route(
    name="Add Numbers",
    path="/add",
    methods=["GET"],
    description="Add two numbers together and return the sum",
    query_parameter_schema=QueryParameterSchema({
        # use "Use" here to tell the parser try calling float, rather
        # than doing a type check, because queryParameters always come
        # in as strings
        Literal("x", description="The first number to add"): Use(float),
        Literal("y", description="The second number to add"): Use(float),
    }),
    response_schema={200: JsonSchema({
        Literal("sum", description="The sum x + y"): float
    })},
)
def add(x: float, y: float):
    return jsonify({"sum": x + y})

api.output_openapi("example/openapi-spec.json")

To run a more complete example (found in the example folder) run FLASK_APP=example/server.py python -m flask run from this directory.

Metadata

Release files for flaskdocs 0.0.1

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

Source distribution (sdist)

Source distribution for flaskdocs 0.0.1
File Size Uploaded
flaskdocs-0.0.1.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flaskdocs 0.0.1
File Interpreter ABI Platform
flaskdocs-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / flaskdocs-0.0.1.tar.gz

Download URL flaskdocs-0.0.1.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c23da7f1f7371dcc403461d00be52b520a2b6932a7ac55fee3d6bde8c86dbf97
BLAKE2b-256 checksum
How to use checksums
8044afb08bcb9df3e39032031fac8cd32f01ab6a0e3e74c9ffb9e3c27f52e0e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.5

Release files / flaskdocs-0.0.1-py3-none-any.whl

Download URL flaskdocs-0.0.1-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b0c04580060df32f05645a265750ae4dea664f9e1f42210062010ccece6ab25
BLAKE2b-256 checksum
How to use checksums
91e81c44043c810f61bf84358a8367edbc81ac8f905cd7aaa143a672d35dd01b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.5

Release history Release notifications | RSS feed

This release

0.0.1 This release

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