A set of simple utilities for Django apps running on Fly.io
Project description
django-flyio
A set of simple utilities for Django apps running on Fly.io.
Note: This package is designed to work with V2 Apps. It has not been tested with V1 Apps.
Installation
pip install django-flyio
Usage
Multi-Region Fly Postgres
-
Set your
DATABASES
settings to callget_db_config
fromdjango_flyio.db
.This function reads the
PRIMARY_REGION
andFLY_REGION
environment variables to determine the Fly region the primary database is in and the Fly region the app is currently running in. -
Add
django_flyio.routers.FlyDBReplicaRouter
to yourDATABASE_ROUTERS
settings.This router reads whether the
DATABASES
setting has areplica
key and, if so, routes reads to the replica database.
# settings.py
from django_flyio.db import get_db_config
DATABASES = get_db_config()
DATABASE_ROUTERS = ["django_flyio.routers.FlyDBReplicaRouter"]
Middleware
To set the Fly-Server
header containing the Fly server and region that served the request, add django_flyio.middleware.FlyResponseMiddleware
to your MIDDLEWARE
settings.
# settings.py
MIDDLEWARE = [
# ...
'django_flyio.middleware.FlyResponseMiddleware',
]
License
django-flyio
is distributed under the terms of the MIT license.
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
Built Distribution
Hashes for django_flyio-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ad00e1752cc1b19896fae027a60224cbbe49ee4bbbfaee3583a357f59c15715 |
|
MD5 | fc08d18dfbe5fcb85b4127677f2c2ff0 |
|
BLAKE2b-256 | e82d3f36f91320b985ba387008d5961c4f522995f4cc28b4d2f28f66cdcda4cf |