Skip to main content

Flask extension for generating restful apis using type hints to automatically (de)serialize parameters and generate openapi docs.

Project description

Build Status codecov Documentation Status

Flask-Hintful

Flask-Hintful helps you write Restful APIs using Flask by taking advantage of Python's type hints.

Includes support for serializing/deserializing parameters according to type hints and automatically generating OpenApi documentation for your registered routes.

Requirements

  • Python 3.7+
  • Flask
  • Marshmallow < 3

Installation

Install using pip

pip install flask-hintful

Quick Start

Construct a FlaskHintful object by passing the Flask application as a parameter, then use the FlaskHintful object @route and .register_blueprint to register routes.

Create your view functions with type hints and FlaskHintful will serialize pass path args, query args and even the request body for you.

from dataclasses import dataclass
from datetime import date, datetime

from flask import Flask

from flask_hintful import FlaskHintful

app = Flask('My API')
api = FlaskHintful(app)


@dataclass
class NestedModel():
    str_field: str


@dataclass
class DataclassModel():
    str_field: str
    int_field: int
    float_field: float
    boolean_field: bool
    list_field: list
    date_field: date
    datetime_field: datetime
    nested_field: NestedModel


@api.route('/<id>/dataclass_test', methods=['POST'])
def dataclass_route(id: str, query_arg: int, model: DataclassModel) -> DataclassModel:
    '''my dataclass route'''
    return model


app.run()

You will be able to access the generated OpenApi on /swagger.

Preview1

Documentation

https://flask-hintful.readthedocs.io/

License

This project is licensed under the MIT License - see the LICENSE file for details

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-hintful-0.0.7.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

flask_hintful-0.0.7-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file flask-hintful-0.0.7.tar.gz.

File metadata

  • Download URL: flask-hintful-0.0.7.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for flask-hintful-0.0.7.tar.gz
Algorithm Hash digest
SHA256 8954d448f488343db0e6882962e47b5639bfdb616b9d7b2b74524b9d58e218f7
MD5 0a4005fe2a103be1b7e3d9e14a298c5c
BLAKE2b-256 69a7e77075d865b063acf209c580649dd8b7c32401c975348c310c4801ba7afc

See more details on using hashes here.

File details

Details for the file flask_hintful-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: flask_hintful-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for flask_hintful-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 32edd98a005e38055d41805273720bbe3d7e6a9cbf301418968526d4bb346c13
MD5 cb234f1a669daa4164b5664fd17dd7b0
BLAKE2b-256 0aac6214f3d931d5b9c3344d1fd6afd02b340d1d0a95671711e8c7286109e8f3

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