Extension for Flask focusing on three important areas for REST APIs:
- validation
- (de)serialization
- blueprint/route management
Flask-journey makes the process of validating and (de)serializing data to/from python objects simple and elegant with the Journey.route decorator - a drop-in replacement for Flask's Blueprint.route, assisted by the fantastic Marshmallow library.
The extension's other component, BlueprintBundle, helps segregate, group and register blueprints with ease while also providing methods for listing routes, either in basic form or detailed JSON.
pip install flask-journey
The documentation can be found here
Some examples of @route
and BlueprintBundle
+ Journey
# file: api/users/controllers.py
from flask import Blueprint
from flask_journey import route
from .services import create_user, get_user, update_user
from .schemas import user, users, query
bp = Blueprint('users', __name__)
@route(bp, '/', methods=['GET'], _query=query, marshal_with=users)
def get_many(_query):
return get_users(_query.data)
@route(bp, '/', methods=['POST'], _body=user, marshal_with=user)
def create(_body):
return create_user(_body.data)
@route(bp, '/<user_id>', methods=['PUT'], _body=user, marshal_with=user)
def update(user_id, _body):
return update_user(user_id, _body.data)
# file: api/bundles.py
from flask_journey import BlueprintBundle
from .users.controllers import bp as users
from .groups.controllers import bp as groups
v1 = BlueprintBundle(path='/api/v1')
v1.attach_bp(users, description='Users API')
v1.attach_bp(groups, description='Groups API')
# file: api/__init__.py
from flask import Flask
from flask_journey import Journey
from .bundles import v1
def create_app():
app = Flask(__name__)
journey = Journey()
journey.attach_bundle(v1)
journey.init_app(app)
print(journey.routes_simple)
return app
Working examples can be found here
Will add more shortly
- Python >= 2.7 or >= 3.4
- Flask > 0.7
Created by Robert Wikman <[email protected]> in 2018
Thank you Jetbrains for creating pycharm and providing me with free licenses