Manage Django settings with Pydantic.
Project description
django-pydantic-settings
Use pydantic settings management to simplify configuration of Django settings.
Very much a work in progress, but reads the standard DJANGO_SETTINGS_MODULE environment variable (defaulting to pydantic_settings.Settings) to load a sub-class of pydantic_settings.Settings. All settings (that have been defined in pydantic_settings.Settings) can be overridden with environment variables. A special DatabaseSettings class is used to allow multiple databases to be configured simply with DSNs.
Database configuration
By defining multiple DjangoDsn
attributes of the DatabaseSettings
class, you can easily configure one or more database connections with environment variables. DSNs are parsed using dj-database-url.
class DatabaseSettings(BaseSettings):
default: DjangoDsn = Field(env="DATABASE_URL")
secondary: DjangoDsn = Field(env="SECONDARY_DATABASE_URL")
❯ DATABASE_URL=sqlite:///foo SECONDARY_DATABASE_URL=sqlite:///bar ./settings_test/manage.py shell
Python 3.9.1 (default, Jan 8 2021, 17:17:43)
[Clang 12.0.0 (clang-1200.0.32.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.conf import settings
...
>>> pp.pprint(settings.DATABASES)
{ 'default': { 'ATOMIC_REQUESTS': False,
'AUTOCOMMIT': True,
'CONN_MAX_AGE': 0,
'ENGINE': 'django.db.backends.sqlite3',
'HOST': '',
'NAME': 'foo',
'OPTIONS': {},
'PASSWORD': '',
'PORT': '',
'TEST': { 'CHARSET': None,
'COLLATION': None,
'MIGRATE': True,
'MIRROR': None,
'NAME': None},
'TIME_ZONE': None,
'USER': ''},
'secondary': { 'CONN_MAX_AGE': 0,
'ENGINE': 'django.db.backends.sqlite3',
'HOST': '',
'NAME': 'bar',
'PASSWORD': '',
'PORT': '',
'USER': ''}}
>>>
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
Built Distribution
Hashes for django-pydantic-settings-0.1.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e355c8fa37ae8ca7daa8ef8c1907d886b764b51ec2bbc17fff647fd4108dc1c |
|
MD5 | 3d290f60e9c5b8181d1673c0db92974d |
|
BLAKE2b-256 | 774696ac108f7286dda6a6d00fd1c41a5a3a188923cf547f35386d0efe5197b5 |
Hashes for django_pydantic_settings-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa7a7cdbfbf48779f121a0865388205449c98e5e41b776ea594f53fb0e25c514 |
|
MD5 | 33d8476e7ecfcfcb315785ba468025fe |
|
BLAKE2b-256 | 39cb2548f7ccace508cdef07f1d067c6fa47aa881e29302e2aba10f163fd136a |