Middleware for integrating Falcon applications with SQLAlchemy.
Project description
The falcon-sqla package provides a middleware component for managing SQLAlchemy sessions. The manager component can also serve as a base building block or a recipe for more complex use cases, such as applications leveraging multiple database binds.
Installation
Until this package is published on PyPi:
$ pip install falcon-sqla
Usage
The falcon_sqla session Manager can be used in two ways:
As a context manager to explicitly provide a database session
Configuration
Create a SQLAlchemy engine.
Pass the engine to the Manager() initializer as its first parameter.
If using the manager as a middleware component, pass its middleware property to the falcon.API() (to be renamed to falcon.App in Falcon 3.0+) initializer:
engine = create_engine('driver+dialect://my/database')
manager = falcon_sqla.Manager(engine)
app = falcon.API(middleware=[manager.middleware])
# The database session will be available as req.context.session
Context Manager
A falcon_sqla.Manager can also explicitly provide a database session using the session_scope() context manager:
# Somewhere inside a responder
with self.manager.session_scope(req, resp) as session:
# Use the session
# <...>
Custom Vertical Partitioning
Simple random selection of read- and write- database replicas is supported out of the box. Use the add_engine() method to instruct the Manager to include the provided engines in the runtime bind selection logic:
manager = falcon_sqla.Manager(engine)
read_replica = create_engine('driver+dialect://my/database.replica')
manager.add_engine(read_replica, 'r')
About Falcon
Falcon is the minimalist web API framework for building reliable, correct, and high-performance REST APIs, microservices, proxies, and app backends in Python.
About SQLAlchemy
SQLAlchemy is the Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL.
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
File details
Details for the file falcon-sqla-0.1.0a1.tar.gz
.
File metadata
- Download URL: falcon-sqla-0.1.0a1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/43.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a83576a3d827fc6040df8878c7e4107e6db0d75de7e86e03e273ec7940dca24 |
|
MD5 | 119c05a9317c45495f2d460c7042022c |
|
BLAKE2b-256 | f17d6a04e80b115e4d334760d5ab8ec11a0d1205b03bedcb0572334f482b8500 |