All Projects → JBKahn → Django Sharding

JBKahn / Django Sharding

Licence: bsd-3-clause
A sharding library for Django

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects

Projects that are alternatives of or similar to Django Sharding

Usaspending Api
Server application to serve U.S. federal spending data via a RESTful API
Stars: ✭ 166 (-9.78%)
Mutual labels:  database, postgresql, django
Citus
Distributed PostgreSQL as an extension
Stars: ✭ 5,580 (+2932.61%)
Mutual labels:  sharding, database, postgresql
Django Migration Linter
🚀 Detect backward incompatible migrations for your django project
Stars: ✭ 231 (+25.54%)
Mutual labels:  database, postgresql, django
Psycopg2
PostgreSQL database adapter for the Python programming language
Stars: ✭ 2,425 (+1217.93%)
Mutual labels:  database, postgresql
Collector
pganalyze statistics collector for gathering PostgreSQL metrics and log data
Stars: ✭ 181 (-1.63%)
Mutual labels:  database, postgresql
Database To Plantuml
Compile PostgreSQL and MySQL table information into a PlantUML description.
Stars: ✭ 157 (-14.67%)
Mutual labels:  database, postgresql
Doctrine Postgis
Spatial and Geographic Data with PostGIS and Doctrine.
Stars: ✭ 161 (-12.5%)
Mutual labels:  database, postgresql
Postgres Migrations
🐦 A Stack Overflow-inspired PostgreSQL migration library with strict ordering and immutable migrations
Stars: ✭ 161 (-12.5%)
Mutual labels:  database, postgresql
Pg hashids
Short unique id generator for PostgreSQL, using hashids
Stars: ✭ 164 (-10.87%)
Mutual labels:  database, postgresql
Old Rustorm
An ORM for rust
Stars: ✭ 168 (-8.7%)
Mutual labels:  database, postgresql
Postgres
Postgres.js - The Fastest full featured PostgreSQL client for Node.js
Stars: ✭ 2,193 (+1091.85%)
Mutual labels:  database, postgresql
Docker Django
A project to get you started with Docker and Django.
Stars: ✭ 170 (-7.61%)
Mutual labels:  postgresql, django
Nut
Advanced, Powerful and easy to use ORM for Qt
Stars: ✭ 181 (-1.63%)
Mutual labels:  database, postgresql
Querybuilder
SQL query builder, written in c#, helps you build complex queries easily, supports SqlServer, MySql, PostgreSql, Oracle, Sqlite and Firebird
Stars: ✭ 2,111 (+1047.28%)
Mutual labels:  database, postgresql
Postgresdbsamples
Sample databases for postgres
Stars: ✭ 161 (-12.5%)
Mutual labels:  database, postgresql
Postgres Meta
A RESTful API for managing your Postgres. Fetch tables, add roles, and run queries
Stars: ✭ 146 (-20.65%)
Mutual labels:  database, postgresql
Dapper.fsharp
Lightweight F# extension for StackOverflow Dapper with support for MSSQL, MySQL and PostgreSQL
Stars: ✭ 145 (-21.2%)
Mutual labels:  database, postgresql
Ocaml Caqti
Cooperative-threaded access to relational data
Stars: ✭ 175 (-4.89%)
Mutual labels:  database, postgresql
Pgproxy
PostgreSQL proxy server.
Stars: ✭ 140 (-23.91%)
Mutual labels:  database, postgresql
Laravel Scout Postgres
PostgreSQL Full Text Search Engine for Laravel Scout
Stars: ✭ 140 (-23.91%)
Mutual labels:  database, postgresql

Django Sharding

Django Sharding is a library and part-framework for sharding Django applications.

Note: Does not support Django 1.10.3 due to a bug in the release.

It helps you to scale your applications by sharding your data across multiple databases in a consistent way.

Build Status PyPI version PyPi downloads Coverage Status

What is Sharding?

Sharding is a way of horizontally partitioning your data by storing different rows of the same table in multiple tables across multiple databases. This helps to increase the number of connections to a given resource as well as improves read performance of your application.

Read The Documentation

For information about how to setup sharding in your application, read the documentation.

Developer Experience

I wrote this library after working on this problem for Wave and not being able to find a library that suited our needs. What we were looking for was something that was powerful, extensible and customizable. This library was created for just that purpose and includes at least one implementation of each part of the pipeline with room to replace any individual components.

Influences

The package was influenced by my experiences at Wave as well as the help and code of my co-workers.

Installation

Check out the installation section of the docs for basic package setup.

Basis Setup & Usage

Sharding by User

Select a model to shard by and open up the models.py file. Here we'll use the user model:

from django.contrib.auth.models import AbstractUser

from django_sharding_library.decorators import shard_storage_config
from django_sharding_library.models import ShardedByMixin


@shard_storage_config()
class User(AbstractUser, ShardedByMixin):
    pass

Add that custom User to your settings file using the string class path:

AUTH_USER_MODEL = '<app_with_user_model>.User'

Create Your First Sharded Model

Define your new model, eg:

from django.db import models

from django_sharding_library.decorators import model_config
from django_sharding_library.fields import TableShardedIDField
from django_sharding_library.models import TableStrategyModel


@model_config(database='default')
class ShardedCarIDs(TableStrategyModel):
    pass


@model_config(sharded=True)
class Car(models.Model):
    id = TableShardedIDField(primary_key=True, source_table_name='app.ShardedCarIDs')
    ignition_type = models.CharField(max_length=120)
    company = models.ForeignKey('companies.Company')

    def get_shard(self):
        return self.company.user.shard

Running migrations

Run them as normal, for example:

./manage.py makemigrations <app_name>

# To let django run the migrations in all the right places.
./manage.py migrate <app>

# To specify the database to run it on
./manage.py migrate <app> --database=<database_alias>

Acccessing sharded data

# TODO: Update this with methods.
shard = User.shard
Car.objects.using(shard).get(id=123)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].