Pydantic Settings for Django
Project description
pydjantic
Use Pydantic Settings for your Django app.
Introduction
If you are tired of the mess in your Django Settings - I feel your pain:
- Long as Dostoevsky's "Crime and punishment"
settings.py
file from production import *
anti-patterntry: <import> except: ImportError
anti-patternbase.py
,production.py
,local.py
,domain.py
- bunch of modules that override each other- django-environ library, that did even worse...
Pydjantic offers to divide the settings only by their domain:
from typing import List
from pydantic import BaseSettings, Field
from pydantic.fields import Undefined
from pydjantic import to_django
class GeneralSettings(BaseSettings):
SECRET_KEY: str = Field(default=Undefined, env='DJANGO_SECRET_KEY')
DEBUG: bool = Field(default=False, env='DEBUG')
INSTALLED_APPS: List[str] = [
'django.contrib.admin',
'django.contrib.auth',
]
LANGUAGE_CODE: str = 'en-us'
USE_TZ: bool = True
class StaticSettings(BaseSettings):
STATIC_URL: str = '/static/'
STATIC_ROOT: str = 'staticfiles'
class SentrySettings(BaseSettings):
SENTRY_DSN: str = Field(default=Undefined, env='SENTRY_DSN')
class ProjectSettings(GeneralSettings, StaticSettings, SentrySettings):
pass
to_django(ProjectSettings())
You can create as many classes/modules as you want, to achieve perfect settings management.
Just create final ProjectSettings
class, that inherits from these domains, and provide its instance to to_django
function.
That's all, your django settings will work as expected.
Installation
Install using pip install -U pydantic
or poetry add pydjantic
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pydjantic-0.2.0.tar.gz
(3.8 kB
view hashes)
Built Distribution
Close
Hashes for pydjantic-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1227d80fcd8e9dbc32955ee6ecf9b700bf321d162c670731dc9791eedf38cba |
|
MD5 | 6025a99e7b1913d9bb1e87551213e5c8 |
|
BLAKE2b-256 | c0e717cbcfec44e4e9c1691470c7fd3f0b2c9c0eaca3a338386bfed6566edd9e |