A packed to help generate documentation automatically for flask endpoints.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flaskdocs-0.0.1.tar.gz.
File metadata
- Download URL: flaskdocs-0.0.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c23da7f1f7371dcc403461d00be52b520a2b6932a7ac55fee3d6bde8c86dbf97
|
|
| MD5 |
f6c25400b4aae59a7cc8befbac854bd7
|
|
| BLAKE2b-256 |
8044afb08bcb9df3e39032031fac8cd32f01ab6a0e3e74c9ffb9e3c27f52e0e2
|
File details
Details for the file flaskdocs-0.0.1-py3-none-any.whl.
File metadata
- Download URL: flaskdocs-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b0c04580060df32f05645a265750ae4dea664f9e1f42210062010ccece6ab25
|
|
| MD5 |
7eab85633712438d6ac12583c0dd47e8
|
|
| BLAKE2b-256 |
91e81c44043c810f61bf84358a8367edbc81ac8f905cd7aaa143a672d35dd01b
|