Skip to main content

Flask-SQLAlchemy Model to API in one line of code

Project description

https://travis-ci.org/acifani/flask-sqla2api.svg?branch=master https://badge.fury.io/py/Flask-SQLA2api.svg

Flask middleware that creates a simple Flask API CRUD REST endpoint based on a SQLAlchemy model definition.

Basic usage

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/<id>

GET

Get a single entry

/entry/<id>

PUT

Edit existing entry

/entry/<id>

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.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Flask-SQLA2api-0.2.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distributions

Flask_SQLA2api-0.2.1-py2.py3-none-any.whl (6.7 kB view details)

Uploaded Python 2 Python 3

Flask_SQLA2api-0.2.1-py2.7.egg (7.1 kB view details)

Uploaded Source

File details

Details for the file Flask-SQLA2api-0.2.1.tar.gz.

File metadata

File hashes

Hashes for Flask-SQLA2api-0.2.1.tar.gz
Algorithm Hash digest
SHA256 230e36447caaeddd6092a88a7fbeb268a6acaa3093cd7d30643d107fa5eed95f
MD5 09eaf9060fc1c95e86e93abd7586a1a9
BLAKE2b-256 cdc6d31effab52b7eeacc46db93f1433f1a4e9eb091c173a0ad16268c8a86654

See more details on using hashes here.

File details

Details for the file Flask_SQLA2api-0.2.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for Flask_SQLA2api-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ea512d61ae94cadc530475228b2481fc0e356fc64ba9810e8474116d67bf0e8b
MD5 24784149d3b3d2d3f3fab9da7bc603b2
BLAKE2b-256 d292123201727f3703cfbb290b123c649431b639b8975c522eca07d01c29b53b

See more details on using hashes here.

File details

Details for the file Flask_SQLA2api-0.2.1-py2.7.egg.

File metadata

File hashes

Hashes for Flask_SQLA2api-0.2.1-py2.7.egg
Algorithm Hash digest
SHA256 129ed8e5f0af63aa2493f9d8ea624e725a4973ea01a9f38ecea6c6c4465e4fc9
MD5 99e2950916bf4f4409950596b3f2ca7a
BLAKE2b-256 bfca06180cc6c0c82e11baa121b6563d18ec2a7385340d0c25dc7934daa20aab

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page