Skip to main content

Falcon API resources for databases

Project description

Build Status

Falcon API resources for databases. See the fulldocumentation <http://falcon-api.readthedocs.io>.

Installation

Run:

pip install falcon_dbapi

Packages required for specific databases:

  • PostgreSQL or other RDBMS: SQLAlchemy, alchemyjsonschema

  • ElasticSearch: elasticsearch-dsl

  • MongoDB: mongoengine

Usage

Below is an example app with:

  • an index of available resources

  • automapped tables

  • basic authentication using a token

import falcon

from falcon_dbapi.middlewares.auth_middleware import AuthMiddleware
from falcon_dbapi.middlewares.json_middleware import RequireJSON, JSONTranslator, JsonError
from falcon_dbapi.resources.index import IndexResource
from falcon_dbapi.resources.sqlalchemy import CollectionResource, SingleResource

from sqlalchemy.ext.automap import automap_base
from sqlalchemy import create_engine

from wsgiref import simple_server

engine = create_engine("sqlite:///mydatabase.db")
Base = automap_base()
Base.prepare(engine, reflect=True)

app = application = falcon.API(
    middleware=[
        AuthMiddleware('/', {'project-id': 'token-value'}),
        RequireJSON(),
        JSONTranslator(),
    ]
)

for name, model in Base.classes.items():
    app.add_route('/' + name, CollectionResource(model, engine)),
    app.add_route('/' + name + '/{id}', SingleResource(model, engine)),

app.add_route('/', IndexResource(['/' + name for name in Base.classes.keys()]))
app.add_error_handler(Exception, JsonError.handle)

simple_server.make_server('localhost', 8888, app).serve_forever()

Test it using httpie:

http http://localhost:8888/

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

falcon_dbapi-1.2.4.tar.gz (32.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

falcon_dbapi-1.2.4-py2.py3-none-any.whl (40.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file falcon_dbapi-1.2.4.tar.gz.

File metadata

  • Download URL: falcon_dbapi-1.2.4.tar.gz
  • Upload date:
  • Size: 32.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for falcon_dbapi-1.2.4.tar.gz
Algorithm Hash digest
SHA256 a833246c92760d4bf490c1ffd6d6038b946a80dec4bcbc7d60988136334f6532
MD5 c30adef3655a26c29b8edd246e67903b
BLAKE2b-256 5f210d7a100b4e03dbbdb2723bacc6e067b0e9763e2c72bc35d69a04f3d9ba71

See more details on using hashes here.

File details

Details for the file falcon_dbapi-1.2.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for falcon_dbapi-1.2.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 451868f670800a59ae67eaa6b812648974cb216f7f81113df809427ccfb76ebb
MD5 392d6c7c4beac1830a0b7d66d25a21a0
BLAKE2b-256 b03f7d9d5c2aaf1f4b9d84e242631746579907f5aa587a5440ff2c07b104ed37

See more details on using hashes here.

Supported by

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