Powerful REST API framework for Flask and SQLAlchemy
Project description
Description
Flask-Potion is a powerful Flask extension for building RESTful JSON APIs. Potion features include validation, model resources and routes, relations, object permissions, filtering, sorting, pagination, signals, and automatic API schema generation.
Potion is ships with backends for SQLAlchemy, peewee and MongoEngine models. It is possible to add backends for other data stores, or even to use a subset of Potion without any data store at all.
Versioning
Potion will use semantic versioning from v1.0.0. Until then, the minor version is used for changes known to be breaking.
Features
- Powerful API framework both for data-store-linked and plain resources
- JSON-based and fully self-documenting with JSON Hyper-Schema
- Backend integrations:
- Flask-SQLAlchemy
- Peewee (contributed by Michael Lavers)
- Flask-MongoEngine
- Filtering, sorting, pagination, validation, built right in
- Smart system for handling relations between resources
- Natural keys for extra simple relation querying
- Easy-to-use, yet highly flexible, optional permissions system
- Signals for pre- and post-processing of requests
- Very customizable — everything is just a resource, route, or schema
Example (SQLAlchemy)
from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_potion import Api, ModelResource, fields from flask_potion.routes import ItemRoute app = Flask(__name__) db = SQLAlchemy(app) api = Api(app) class User(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(), nullable=False) db.create_all() class UserResource(ModelResource): class Meta: model = User @ItemRoute.GET def greeting(self, user) -> fields.String(): return "Hello, {}!".format(user.name) api.add_resource(UserResource) if __name__ == '__main__': app.run()
Long-term goals
The web nowadays is increasingly push rather than pull, so Potion is gradually building up to providing a scalable WebSocket service (using asyncio and a message queue). This service will mirror the RESTful API so that every GET request can be done “live”. (In the meantime, you can use the signals module to roll your own solution).
Potion is written in a way that makes it very easy to cache resources. A natural goal is to eventually ship Potion with a built-in server-side caching solution.
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.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size Flask-Potion-0.12.0.tar.gz (39.4 kB) | File type Source | Python version None | Upload date | Hashes View |