Giter VIP home page Giter VIP logo

django-flyio's Introduction

django-flyio

PyPI - Version PyPI - Python Version


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

  1. Set your DATABASES settings to call get_db_config from django_flyio.db.

    This function reads the PRIMARY_REGION and FLY_REGION environment variables to determine the Fly region the primary database is in and the Fly region the app is currently running in.

  2. Add django_flyio.routers.FlyDBReplicaRouter to your DATABASE_ROUTERS settings.

    This router reads whether the DATABASES setting has a replica 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.

django-flyio's People

Contributors

joshuadavidthomas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.