Skip to main content

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


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)

Uploaded Source

Built Distribution

flask_scotch-0.0.1-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

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