Skip to main content

Flask extension for using "specification first" principle via OpenAPI specification.

Project description

Flask-First

Flask extension for using "specification first" principle.

Features:

  • Application Factory supported.
  • Validating and serializing path parameters from request.view_args to request.first_view_args.
  • Validating and serializing arguments from request.args to request.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


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.9.4.tar.gz (469.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Flask_First-0.9.4-py3-none-any.whl (465.5 kB view details)

Uploaded Python 3

File details

Details for the file Flask-First-0.9.4.tar.gz.

File metadata

  • Download URL: Flask-First-0.9.4.tar.gz
  • Upload date:
  • Size: 469.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.10.0 keyring/23.4.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for Flask-First-0.9.4.tar.gz
Algorithm Hash digest
SHA256 06c6aff23f0b070c0be5914849de1886bd6334f381077bcc099ebb3d548af0b2
MD5 9f8f1ff85bdbbef2c4298fa125641298
BLAKE2b-256 f7afebec4ea6900f2f584091cf80f54246444e01b9fe23e4ae6020e49d23bbb7

See more details on using hashes here.

File details

Details for the file Flask_First-0.9.4-py3-none-any.whl.

File metadata

  • Download URL: Flask_First-0.9.4-py3-none-any.whl
  • Upload date:
  • Size: 465.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.10.0 keyring/23.4.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for Flask_First-0.9.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1a530fbb6050df56375ab0a02141882ddf91066ef3d39ccc89741e770111c58c
MD5 a0a19e9ff0759c7988830872be4a232b
BLAKE2b-256 a775c2c18328367f668c55de802c900a12bffdc32f7d516c971032ceddb0ad2e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page