Giter Site home page Giter Site logo

rbw / flask-journey Goto Github PK

View Code? Open in Web Editor NEW
13.0 5.0 0.0 104 KB

Blueprint management and straightforward (de)serialization + validation in Flask

License: MIT License

Python 100.00%
flask blueprint registration routing serialization marshmallow deserialization validation

flask-journey's Introduction

image

image

image

image

Description

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.

Installing

pip install flask-journey

Documentation

The documentation can be found here

Quick taste

Some examples of @route and BlueprintBundle + Journey

@route

# 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)

BlueprintBundle

# 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')

Journey

# 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

Full examples

Working examples can be found here

Will add more shortly

Compatibility

  • Python >= 2.7 or >= 3.4
  • Flask > 0.7

Author

Created by Robert Wikman <[email protected]> in 2018

JetBrains

Thank you Jetbrains for creating pycharm and providing me with free licenses

flask-journey's People

Contributors

rbw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.