Skip to content

Latest commit

 

History

History
218 lines (148 loc) · 4.95 KB

README.md

File metadata and controls

218 lines (148 loc) · 4.95 KB

Django Ultratenant

Installation info of the django-ultratenant

PyPI name: django-ultratenant https://pypi.org/project/django-ultratenant/

Pythons >=3.7

Operating systems: Linux, Windows, OSX, Unix

Requirements: dj-database-url, django*

Installers: pip

Code repository: https://github.com/HBNetwork/django-ultratenant

Pitch about the main idea of the project (Portuguese)

Context of the origin of the library proposal

What is

This library makes it possible to use tenant strategies in a django project.

In a multi-tenant architecture, multiple instances of an application share the environment. This architecture is able to work because each tenant is physically integrated but logically separate; which means that a single instance of the software will run on a server and then service multiple tenants (clients).

The dango ultratenant library that implements diferent approaches.

Type of the Strategies (Approaches)

  • multi-db
  • multi-schema
  • tenant-id

What is multi-db?

  • Support multiple databases. Suported sqllite and postgresdb.

What is multi-schema?

What is tenant-id?

  • Supported URL approaches: subdomain and path
    • tenant.url.com
    • url.com/tenant/admin/

Objectives

  • In a django project implemented diferent approaches based of the bussiness core

  • Simple API with minimal setup

  • Transparent for the application

  • Supported isolations approaches (multi-db, multi-schema, tenant-id)

How to Use

Installation

pip install django-ultratenant

Configuration

In the settings.py file, install the app that corresponds to the chosen strategy:

...
    INSTALLED_APPS=["test_project.singledb", "test_project.multidb"],
...

Put the information the created databases:

...
     DATABASES={
            "default": config("DATABASE_URL", default="sqlite://:memory:", cast=dburl),
            "t1": config("DATABASE_URL", default="sqlite://:memory:", cast=dburl),
            "t2": config("DATABASE_URL", default="sqlite://:memory:", cast=dburl),
        },
...

API Multi-db

...
    # settings.py
    from ultratenant.multidb import Databases
    ...
    MIDDLEWARE = [
        ...
        'ultratenant.path.Middleware',
    ]
    ...
    DATABASES = Databases(config('DATABASE_URL', cast=dburl))
    DATABASE_ROUTERS = ['ultratenant.multidb.Router']
...

set the urls depending on the chosen strategies

...
    # urls.py
    ...
    from ultimate_tenants.urls import tenants_path

    urlpatterns = tenants_path([
        path('admin/', admin.site.urls),
        path('', index, name='index'),
    ])

    # url.com/tenant/admin
...

Contributors

HBNetwork

HBNetwork is a community of python programmers from Brazil established within the Dev Senior Passport.

Rules to contribute

  • Your contribution is welcome.

  • Setup your development environment and select issues.

Contributing

Clone the code

git clone https://github.com/HBNetwork/django-ultratenant
cd django-ultratenant
git checkout main

Or

git clone [email protected]:HBNetwork/django-ultratenant.git
cd django-ultratenant
git checkout main

Setup the project

python -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install ".[test]"
pre-commit install
pre-commit autoupdate
pytest

Create a new branch

git fetch origin
git checkout -b task/branch-name-you-work-issue

Create a pull request to the branch main

PyPI

Coverage Status

Alternatives

Base projects

MVP

  • setup and pip

  • SQLite3 support

  • multi-db

  • tenant on URL path

  • documetation about how customize manage.py

Roadmap

  • other databases supported by Django: PostgreSQL, MariaDB, MySQL, Oracle

  • multi-schema

  • tenant-id

  • custom [manage.py]{.title-ref} to access different tenants

  • cookiecutter to create a new project

[Unreleased]

[0.0.1] - 2022-07-31

Added

  • First release on PyPI.