Bringing FastAPI Developer experience to Flask.
Project description
Flask-Jeroboam
Project Description
Flask-Jeroboam is a thin layer on top of Flask to make request parsing, response serialization and auto-documentation as smooth and easy as in FastAPI.
Motivation
FastAPI has been rapidly gaining ground in Python Web Development since its inception in late 2018 (1). Besides impressive performance improvement , it brings a very compelling API for request parsing and response serialisation that speed up API development by catering for Developer Experience.
While it is often compared to Flask, (1, 2 and 3), the comparaison feels a bit unfair. FastAPI is, in the words of its creator@tiangolo a thin layer on top of Starlette, a lightweight ASGI framework/toolkit, ... for building async web services in Python and Pydantic. To some extend, Flask is more related to Starlette than it is to FastAPI.
Although there are some excellent Flask extensions dealing with request parsing, response serialisation, and auto-documentation, I wanted something closer to FastAPI's DX. Hence Flask - Jeroboam.
Who is it inteded for
For devs who are fond of FastAPI but have perfectly good reasons to stick to Flask, including:
- a large code base build with Flask (although migration could be undertaken)
- being confortable with Flask and not needing the performance of Starlette
- depending on Flask eco-system
Features
Flask-Jeroboam will provide the following features :
- OpenAPI Auto-Documentation based on endpoint type annotations
- Request parsing with pydantic
- Response serialization facilitation with pydantic
Dependency Injection as featured in FastAPI feels like something you don't need in Flask.
Installation
You can install flask-jeroboam via pip, or [poetry] from PyPI:
$ pip install flask-jeroboam
or better yet with poetry:
$ poetry add flask-jeroboam
Example Usage
Our goal is to implement an API similar, if not equivalent, to the one you have with FastAPI. Because we think it's an excellent standard.
First you would need to replace your existing flask.Blueprint with a flask-jeroboam.ApiBlueprint. Note that APIBlueprint are just regular Blueprint with a extra features, but they should not break any endpoint defined the flask way.
from flask-jeroboam import APIBlueprint
router = APIBlueprint("wines", __name__)
@router.get("/wines", response_model=serializers.WineList)
@jwt_required()
def read_example(wines_in: parsers.WineList):
wines = crud.get_wines(wines_in, db.session)
return {"items": wines}
License
Distributed under the terms of the MIT license, Flask-Jeroboam is free and open source software.
Issues
If you encounter any problems, please file an issue along with a detailed description.
Credits
The main inspiration of this project comes from @tiangolo's FastAPI.
The heavy-lifting if performed by Flask and pydantic.
The project was generated from @cjolowicz's Hypermodern Python Cookiecutter template.
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
File details
Details for the file flask-jeroboam-0.0.1a0.tar.gz
.
File metadata
- Download URL: flask-jeroboam-0.0.1a0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b316cdb55b48e83212122b40cfcc936531ee7eb4d141fb5be5099e358c42546 |
|
MD5 | 90ce254591d323bf38f101a3e89157e2 |
|
BLAKE2b-256 | b0a79105449e19850b298e237f48aa3132c0a84315c694fd97cbf6ba9785e131 |
File details
Details for the file flask_jeroboam-0.0.1a0-py3-none-any.whl
.
File metadata
- Download URL: flask_jeroboam-0.0.1a0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97bd9cb0e84bdf7c7f30ed1c15d57a5f79cc123ca7b2c61d5cb5025f9ec39d3e |
|
MD5 | 44cb332f58f4ce756203520fc6231906 |
|
BLAKE2b-256 | 14891c06b4f9674aa1bab6e78a3f69c45ff048a27ce1b2466fd040539c984147 |