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:

  • 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.
  • Provides a Swagger UI.

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, swagger_ui_path='/docs')


@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. 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.6.0.tar.gz (470.4 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.6.0-py3-none-any.whl (468.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: Flask-First-0.6.0.tar.gz
  • Upload date:
  • Size: 470.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for Flask-First-0.6.0.tar.gz
Algorithm Hash digest
SHA256 8c33aa24a5b2057f6205e08653ad2f03ad0188b41f04bcd49d19e2ac547cfd55
MD5 2a7ea1b56036501098c09fe19102bb8f
BLAKE2b-256 7004ef278eebf68a08074da2f5198344602537db1d4986c1b0db9cddef46f9c3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Flask_First-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 468.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for Flask_First-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 010add1e2aefaf99d3b6b4d82a083832dea122088a3652548701a73685a679c5
MD5 642cc027db43ef8d99dc2ab2d1a04755
BLAKE2b-256 3fa790b1aba07ccbfa754a6a6fd8c402a8b9a80a07edfe9e8e25f73855f792c4

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