Tape a REST API with a local database
Project description
Flask Scotch
Tape a REST API with a local database
Key Features
- Represent remote model in the form of a python class to be able to manipuldate easily
- Fetch objects from the database or from the remote API using the attributes of the declared models
- Update/delete/create object on the remote API using the declared models
Install
TODO
Getting started
Firs, you need to register the extension in flask
from flask_scotch import FlaskScotch
from flask import Flask
# Configure the URL of the remote API with the configuration
# SCOTCH_API_URL='https://mysite.com/api/v1'
# Register the sqlAlchemy engine with flask-sqlalchemy, or provide it directly
# in the constructor
scotch = FlaskScotch()
app = Flask()
scotch.init_app(app)
Then, you can declare the "remote model", that is, the model present on the remote server.
from flask_scotch import RemoteModel
class Item(RemoteModel):
__remote_directory__ = 'items'
id: int
name: str
description: str
# You can then use this model to fetch data from the remote api:
all_items = await Item.api.all()
nw_item = Item(name='pen', description='a green pen to write things')
final_item = await Item.api.create(nw_item)
final_item.name = 'green pen'
await final_item.update()
await final_item.delete()
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.
Source Distribution
flask-scotch-0.0.1.tar.gz
(4.2 kB
view hashes)
Built Distribution
Close
Hashes for flask_scotch-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f83fb2e17461b005ec8cf5d52e6dd2a79e85bd317b6a3e9cb4b81e3b5ed22f3 |
|
MD5 | b716ef01714a1b9eb99ca8329dddfbe2 |
|
BLAKE2b-256 | 0fb5652f3b0c644f41fd7dea4164f65fd28053ceb276451d6a4d94c41c4d6ef9 |