Flask extension for using "specification first" principle via OpenAPI specification.
Project description
Flask-First
Flask extension for using "specification first" principle.
Features:
- Decorator for mapping routes from OpenAPI specification on Python's view functions via Flask.
Application Factory
supported.- Validating path parameters from url.
- Validating arguments from url.
- Validating JSON from request.
- Validating JSON from response.
Limitations
- All specification in one file.
- Not supported
Encoding Object
. - Not supported
Discriminator Object
. - Not supported
XML Object
. - Not supported
Specification Extensions
. - Not supported
OAuthFlowsObject
.
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(path_to_spec, app)
@app.specification
def index(name):
return {'message': name}
if __name__ == '__main__':
app.run()
Run application:
$ python main.py
Check url in browser http://127.0.0.1:5000/username
.
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
Flask-First-0.5.1.tar.gz
(9.2 kB
view hashes)
Built Distribution
Close
Hashes for Flask_First-0.5.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b58afb50aac753ce319e2abdef85018b0d5d665bd4ff30ca641bbc054fa88a5 |
|
MD5 | ebc1fe523d95af3b78520cf1fb124cf0 |
|
BLAKE2b-256 | b94f604ee2c3e647eb54ee1d34876ea1651159c087cb205a9ee655227d088e2b |