Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/acifani/flask-sqla2api
⚗️ SQLAlchemy Model to API in one line of code
https://github.com/acifani/flask-sqla2api
flask flask-extensions flask-sqlalchemy python
Last synced: 3 months ago
JSON representation
⚗️ SQLAlchemy Model to API in one line of code
- Host: GitHub
- URL: https://github.com/acifani/flask-sqla2api
- Owner: acifani
- License: bsd-3-clause
- Created: 2017-09-25T17:08:41.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-05-01T04:15:19.000Z (over 2 years ago)
- Last Synced: 2024-08-10T11:18:21.644Z (6 months ago)
- Topics: flask, flask-extensions, flask-sqlalchemy, python
- Language: Python
- Homepage: https://pypi.org/project/Flask-SQLA2api/
- Size: 97.7 KB
- Stars: 10
- Watchers: 3
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- License: LICENSE
Awesome Lists containing this project
README
Flask-SQLA2api
==============.. image:: https://travis-ci.org/acifani/flask-sqla2api.svg?branch=master
:target: https://travis-ci.org/acifani/flask-sqla2api.. image:: https://badge.fury.io/py/Flask-SQLA2api.svg
:target: https://badge.fury.io/py/Flask-SQLA2api.. image:: https://coveralls.io/repos/github/acifani/flask-sqla2api/badge.svg?branch=master
:target: https://coveralls.io/github/acifani/flask-sqla2api?branch=masterFlask middleware that creates a simple Flask API CRUD REST endpoint
based on a SQLAlchemy model definition.Basic usage
-----------.. code-block:: python
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_sqla2api import SQLA2api# Init app and DB
app = Flask(__name__)
db = SQLAlchemy(app)# Setup a simple SQLAlchemy model
class Entry(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80))# Init Flask-sqla2api
api = SQLA2api([Entry], self.db)
api.append_blueprints(app)The previous tiny app will create the following endpoints
=============== =========== =======================
URL HTTP Method Action
=============== =========== =======================
``/entry`` GET Get all entries
``/entry`` POST Create new entry
``/entry/`` GET Get a single entry
``/entry/`` PUT Edit existing entry
``/entry/`` DELETE Delete existing entry
=============== =========== =======================Generate single blueprint
-------------------------If you want more control over your blueprints you can generate it
and append it yourself to your app... code-block:: python
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_sqla2api import generate_blueprint# Init app and DB
app = Flask(__name__)
db = SQLAlchemy(app)# Setup a simple SQLAlchemy model
class Entry(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80))# Generate and register blueprint
blueprint = generate_blueprint(Entry, db)
app.register_blueprint(blueprint, url_endpoint='/')To-Do
------ Input validation
- API docs generation