Skip to main content

Schema Sprout connects to a third-party database to dynamically create models and views.

Project description

Django Schema Sprout

Tests Status Coverage Status Flake8 Status

Django Schema Sprout is a django package that helps with generating models, serializers and views dynamically for unmanaged databases. Currently Django Schema Sprout supports only PostgreSQL (>=11.), Django (>=4.0, <5.0)


To install Django Schema Sprout, you can run:

pip install django-schema-sprout


Add django_schema_sprout in installed apps in your and add SchemaSproutDBRouter to your database routers.

    # django_schema_sprout requires rest_framework and drf_yasg to be installed.


Initializing SchemaSprout

from django_schema_sprout.schema_sprout import SchemaSprout

my_db_sprout = SchemaSprout("name_of_unmanaged_db")

SchemaSprout is Singleton based on parameters so initializing SchemaSprout with same database name will return same instance.

Creating models

You can either create all models at once using create_models.

create_models takes one parameter:

  • readonly bool (default: False), specifying if created REST ViewSets should be readonly or not.

To create one model at the time use create_model.

create_model takes 3 parameter:

  • table_name - str, name of the table for which you want to create model.
  • table_nspname - str, schema where the table resides.
  • readonly bool (default: False), specifying if created REST ViewSet should be readonly or not.

Including SchemaSprout ViewSets

In file, include urls from SchemaSprout.router. Make sure that the models that you need were created before.

from django.contrib import admin
from django.urls import path, re_path, include

from django_schema_sprout.schema_sprout import SchemaSprout

urlpatterns = [
    path("api/", include(SchemaSprout("name_of_unmanaged_db").router.urls)),

Accessing created models

You can access created models, serializers and views by accessing SchemaSprout attributes:

table_name = "my_table"
schema_name = "my_schema"

obj_key = f"{schema_name}_{table_name}"

my_model = my_db_sprout.models.get(obj_key, None)

my_model_serializer = my_db_sprout.serializers.get(obj_key, None)

my_model_view = my_db_sprout.views.get(obj_key, None)


Feel free to contriute or open an issue.

For local development:

  • in your venv install dev dependencies pip install -e ".[dev]"
  • for testing install test dependencies pip install -e ".[test]"

Running tests requires to have installed Postgres.


This project is licensed under the Apache License 2.0


For questions feel free to contact me:

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_schema_sprout-0.1.1.tar.gz (21.9 kB view hashes)

Uploaded Source

Built Distribution

django_schema_sprout-0.1.1-py3-none-any.whl (16.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page