Flask extension for generating restful apis using type hints to automatically (de)serialize parameters and generate openapi docs.
Project description
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.
Documentation
https://flask-hintful.readthedocs.io/
License
This project is licensed under the MIT License - see the LICENSE file for details
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-hintful-0.0.5.tar.gz.
File metadata
- Download URL: flask-hintful-0.0.5.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00f6940a605be346f10051b9de3e5c5a7f103baf947b63f2d2eb961e98882011
|
|
| MD5 |
678825d6529163311841841fe72cecd5
|
|
| BLAKE2b-256 |
4e456aa6f921968bc09ad976de302ac8dd34057e421140f2087f7221e7b71a99
|
File details
Details for the file flask_hintful-0.0.5-py3-none-any.whl.
File metadata
- Download URL: flask_hintful-0.0.5-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0acd34f9d19b92968660fa44a3944cdf1cc318a5455d0ab54caecf9f285225ee
|
|
| MD5 |
3953e8a1f4d3e8f29827acd4f724c34c
|
|
| BLAKE2b-256 |
1ef005114d993eefa89dd0762fdf18bfd124e35e0a71c385074005f060def79f
|