Flask extension for using "specification first" principle via OpenAPI specification.
Project description
Flask-First
Flask extension for using "specification first" principle.
Features:
Application Factorysupported.- Validating and serializing path parameters from
request.view_argstorequest.first_view_args. - Validating and serializing arguments from
request.argstorequest.first_args. - Validating JSON from request.
- Validating JSON from response.
- Provides a Swagger UI.
Limitations
- Full specification in one file.
Installing
Install and update using pip:
$ pip install flask_first
Simple example
OpenAPI 3 specification file openapi.yaml:
openapi: 3.0.3
info:
title: Simple API for Flask-First
version: 1.0.0
paths:
/{name}:
parameters:
- name: name
in: path
required: true
schema:
type: string
get:
operationId: index
summary: Returns a list of items
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
message:
type: string
File with application initialization main.py:
import os
from flask import Flask
from flask_first import First
basedir = os.path.abspath(os.path.dirname(__file__))
path_to_spec = os.path.join(basedir, 'openapi.yaml')
app = Flask(__name__)
app.config['FIRST_RESPONSE_VALIDATION'] = True
first = First(path_to_spec, app=app, swagger_ui_path='/docs')
def index(name):
return {'message': name}
first.add_view_func(index)
if __name__ == '__main__':
app.run()
Run application:
$ python main.py
Check url in browser http://127.0.0.1:5000/username. Check SwaggerUI url in browser http://127.0.0.1:5000/docs.
Settings
FIRST_RESPONSE_VALIDATION - Default: False. Enabling response body validation. Useful when
developing. May be disabled in a production environment.
Additional documentation
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 Flask-First-0.9.2.tar.gz.
File metadata
- Download URL: Flask-First-0.9.2.tar.gz
- Upload date:
- Size: 468.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
660918d9f0a8126759c707f0f4e295f3494152ab94e596c856adec636429c45b
|
|
| MD5 |
280299a4563d396022291b2602fe2c3d
|
|
| BLAKE2b-256 |
66fc719795223c8900864edbd91933e274487f0bd0433cf1a92d6e6fb12924ca
|
File details
Details for the file Flask_First-0.9.2-py3-none-any.whl.
File metadata
- Download URL: Flask_First-0.9.2-py3-none-any.whl
- Upload date:
- Size: 465.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c85aa72709edf9bb04f6e5c2295cd56e7fa0c6c454a66b2b57e36ea56743de85
|
|
| MD5 |
ca62d79f2a78a4f988d897c35628ae5c
|
|
| BLAKE2b-256 |
54f49cc65b3c102eefe058f3c08298e2e4c2713f255841a5f1aaa115d6d7a7cc
|