All Projects → numberly → flask-stupe

numberly / flask-stupe

Licence: MIT License
💉 a.k.a. « Flask on steroids »

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to flask-stupe

Flasgger
Easy OpenAPI specs and Swagger UI for your Flask API
Stars: ✭ 2,825 (+9316.67%)
Mutual labels:  marshmallow, flask-extensions
Flask-GraphQL-Auth
(UNMAINTAINED. FEEL FREE TO FORK) 🐍A Pythonic way to provide JWT authentication for Flask-GraphQL
Stars: ✭ 64 (+113.33%)
Mutual labels:  flask-extensions
Instant-Face-Unlock
Xposed Module's InstantFaceUnlock Code
Stars: ✭ 23 (-23.33%)
Mutual labels:  marshmallow
EasyPermissions
Request permissions from anywhere as long as you have context.
Stars: ✭ 39 (+30%)
Mutual labels:  marshmallow
marshmallow-validators
Use 3rd-party validators (e.g. from WTForms and colander) with marshmallow
Stars: ✭ 24 (-20%)
Mutual labels:  marshmallow
flask-jwt-login
Flask extension that helps authentication using JWT (for a personal purpose, not maintained now)
Stars: ✭ 12 (-60%)
Mutual labels:  flask-extensions
liquid
A Python engine for the Liquid template language.
Stars: ✭ 40 (+33.33%)
Mutual labels:  pypy3
apiflask
A lightweight Python web API framework.
Stars: ✭ 442 (+1373.33%)
Mutual labels:  marshmallow
unpythonic
Supercharge your Python with parts of Lisp and Haskell.
Stars: ✭ 53 (+76.67%)
Mutual labels:  pypy3
flask-vuejs
Connect Flask application with VueJS
Stars: ✭ 29 (-3.33%)
Mutual labels:  flask-extensions
swagger-marshmallow-codegen
generating marshmallow's schema from swagger definition file
Stars: ✭ 51 (+70%)
Mutual labels:  marshmallow
flask url discovery
Flask extension for discovering urls in a service. Automatically expose urls for a service. Manage urls exposure settings.
Stars: ✭ 13 (-56.67%)
Mutual labels:  flask-extensions
desert
Deserialize to objects while staying DRY
Stars: ✭ 136 (+353.33%)
Mutual labels:  marshmallow
Flask-CSV
Easily render CSVs within any flask application
Stars: ✭ 20 (-33.33%)
Mutual labels:  flask-extensions
flask-funnel
Better asset management for Flask
Stars: ✭ 22 (-26.67%)
Mutual labels:  flask-extensions
MPContribs
Platform for materials scientists to contribute and disseminate their materials data through Materials Project
Stars: ✭ 30 (+0%)
Mutual labels:  marshmallow
flask-diced
Flask-Diced - CRUD views generator for Flask
Stars: ✭ 15 (-50%)
Mutual labels:  flask-extensions
marshmallow-objects
Marshmallow Objects and Models
Stars: ✭ 37 (+23.33%)
Mutual labels:  marshmallow
flask-pwa
A extension to give a PWA experience into your Flask app.
Stars: ✭ 23 (-23.33%)
Mutual labels:  flask-extensions
instant api
Instantly create an HTTP API with automatic type conversions, JSON RPC, and a Swagger UI. Just add methods!
Stars: ✭ 115 (+283.33%)
Mutual labels:  marshmallow
https://raw.githubusercontent.com/numberly/flask-stupe/master/artwork/stupeflask.png

https://readthedocs.org/projects/flask-stupe/badge

a.k.a. « Flask on steroids »

An opinionated Flask extension designed by and for web developers to reduce boilerplate code when working with Marshmallow, MongoDB and/or JSON.

Documentation: https://flask-stupe.readthedocs.io

Features

  • Return any object type in views, and it will be coerced to a flask.Response
  • Validate payloads through Marshmallow schemas
  • Easily add JSON converters for any custom type
  • Fetch all the blueprints from a whole module in one line
  • Native ObjectId support for both Flask and Marshmallow
  • Powerful configuration management
  • Decorators to handle authentication, permissions, and pagination
  • 100% coverage and no dependency

Install

$ pip install flask-stupe

Comparison

Here is a comparison of a bare Flask application and its equivalent Stupeflask version. They both rely on MongoDB, handle input and output in JSON, and allow to create a user and retrieve one or more.

Bare Flask With Stupeflask
from bson import ObjectId
from flask import abort, Flask, jsonify, request
from marshmallow import Schema
from marshmallow.fields import String
from pymongo import MongoClient

app = Flask(__name__)
users = MongoClient().database.users


class UserSchema(Schema):
    username = String(required=True)
    password = String()


@app.route("/user", methods=["POST"])
def post_user():
    json = request.get_json(force=True)
    validation_result = UserSchema().load(json)
    if validation_result.errors:
        abort(400, validation_result.errors)
    result = users.insert_one(validation_result.data)
    inserted_id = str(result.inserted_id)
    validation_result.data.update(_id=inserted_id)
    return jsonify(validation_result.data)


@app.route("/user/<id>")
def get_user(id):
    try:
        id = ObjectId(id)
    except ValueError:
        abort(404)
    user = users.find_one({"_id": id})
    user["_id"] = str(user["_id"])
    return jsonify(user)


@app.route("/users")
def get_users():
    limit = request.args.get("limit", 100, type=int)
    skip = request.args.get("skip", 0, type=int)
    cursor = users.find().limit(limit).skip(skip)
    return jsonify(list(cursor))
from flask import request
from flask_stupe import paginate, schema_required
from flask_stupe.json import Stupeflask
from marshmallow import Schema
from marshmallow.fields import String
from pymongo import MongoClient

app = Stupeflask(__name__)
users = MongoClient().database.users


class UserSchema(Schema):
    username = String(required=True)
    password = String()


@app.route("/user", methods=["POST"])
@schema_required(UserSchema())
def post_user():
    result = users.insert_one(request.schema)
    request.schema.update(_id=result.inserted_id)
    return request.schema


@app.route("/user/<ObjectId:id>")
def get_user(id):
    return users.find_one({"_id": id})


@app.route("/users")
@paginate(limit=100)
def get_users():
    return users.find()

Tests

To run Flask-Stupe tests:

  • install developers requirements with pip install -r requirements.txt;
  • run pytest.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].