Skip to main content

JSON request validation for Flask applications using a JSON Schema specified in a OpenAPI Specification (also know as OAS and Swagger).

Validating schema of passed object provides a level of confidence of correctness of data directly proportional to schema strictness. With a good schema, it maybe be possible to use JSON-dict like object as first order models without having to convert them into trusted python objects. Reducing amount of code that needs to be maintained.

The tests provide a succinct example of usage as well as an example OAS schema file. But at high level usage looks as follows:

from flask import Flask
from flask_oasschema import OASSchema, validate_request

# Configure application
app = Flask(__name__)

# Specify path to the OAS schema file, in this case schemas/oas.json of
# project firectory
app.config['OAS_FILE'] = os.path.join(
    app.root_path,
    'schemas',
    'oas.json'
)

# Initialize validator
jsonschema = OASSchema(app)

# Decorate endpoint with @validate_request()
@app.route('/books/<isbn>', methods=['POST'])
@validate_request()
def books(isbn):
    return 'success'

Installation

This library is available through PyPI as Flask-OASSchema and as such can be installed with:

pip install Flask-OASSchema

Credit

This project is a fork of Matt Wright’s project Flask-JsonSchema and thus borrows ideas and code. Difference being that Flask-OASSchema works only with OAS (Swagger) style schema spec as opposed to raw json-schema. This allows Flask-OASSchema to locate schema corresponding to endpoint and method without explicit per endpoint configuration.

Authors: Dan Baumann Thanavath Jaroenvanit

Metadata

Release files for Flask-OASSchema 0.9.14

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

Source distribution (sdist)

Source distribution for Flask-OASSchema 0.9.14
File Size Uploaded
Flask-OASSchema-0.9.14.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Flask-OASSchema 0.9.14
File Interpreter ABI Platform
Flask_OASSchema-0.9.14-py3-none-any.whl Python 3 none any Details

Total release size: 9.1 kB

Release files / Flask-OASSchema-0.9.14.tar.gz

Download URL Flask-OASSchema-0.9.14.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d3a700904cd7160f74911c74846629bec788de449bbf321955ae97ec18cdb056
BLAKE2b-256 checksum
How to use checksums
4bfcc40e8eaf26f61018a34ee8823a363f974dd1ba7e24a178b20b591024c552
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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

Release files / Flask_OASSchema-0.9.14-py3-none-any.whl

Download URL Flask_OASSchema-0.9.14-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba31144e0194563c6df7dd525c47b357fa1379676254aa288c824759ba44019d
BLAKE2b-256 checksum
How to use checksums
c21c12a993eafc389e288d9aac672871918bea02fa41cc02ac25ce38aa36b8f7
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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

Release history Release notifications | RSS feed

This release

0.9.14 This release

2 release files

0.9.13

2 release files

0.9.12

2 release files

0.9.11

1 release file

0.9.10

1 release file

0.9.9

1 release file

0.9.8

2 release files

0.9.7

2 release files

0.9.6

2 release files

0.9.5

1 release file

0.9.4

1 release file

0.9.2

1 release file

0.9.1

2 release files

0.9.0

1 release file

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