Skip to main content

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)

Installation

To install Django Schema Sprout, you can run:

pip install django-schema-sprout

Usage

Settings.py

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

INSTALLED_APPS = [
    # django_schema_sprout requires rest_framework and drf_yasg to be installed.
    "rest_framework",
    "drf_yasg",
    ...
     "django_schema_sprout"
]
...

DATABASE_ROUTERS = [
    ...,
    "django_schema_sprout.router.SchemaSproutDBRouter",
]

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.
my_db_sprout.create_models(readonly=True)

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.
my_db_sprout.create_model(
    table_name="my_table"
    table_nspname="my_schema"
    readonly=False
)

Including SchemaSprout ViewSets

In url.py 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)

Contribution

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.

License

This project is licensed under the Apache License 2.0

Contact

For questions feel free to contact me: grumpy.miner.dev@gmail.com

Metadata

Release files for django-schema-sprout 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-schema-sprout 0.1.1
File Size Uploaded Provenance
django_schema_sprout-0.1.1.tar.gz 21.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-schema-sprout 0.1.1
File Interpreter ABI Platform
django_schema_sprout-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 38.0 kB

Release files / django_schema_sprout-0.1.1.tar.gz

Download URL django_schema_sprout-0.1.1.tar.gz
Size 21.9 kB
Tags Source
SHA-256 checksum
How to use checksums
77676c3f9773e4c8abc8341c0dc3ac00ec120b39c8259adbccb44fdf310b8edd
BLAKE2b-256 checksum
How to use checksums
9cc6e7a46a7a3be6eb26ed7e88a83cd77af0150ef0b5a0693faef661bd5b626a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / django_schema_sprout-0.1.1-py3-none-any.whl

Download URL django_schema_sprout-0.1.1-py3-none-any.whl
Size 16.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dd0971711665a2d09da4f101aaf74af8abdbb68c5e6267e6e99c37c078736e4c
BLAKE2b-256 checksum
How to use checksums
82430896b21873fe91dd05edcf800b92522af773f797a3e7b73100d8edfcb3a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Security for django-schema-sprout 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page