Skip to main content

Add your description here

Project description

dj-pydantic-settings

Небольшая библиотечка для упрощения конфигурирования django проектов

# settings.py
from dj_pydantic_settings import DjangoModel, Database, DjangoSettings
from pydantic import BaseModel

# удобно собирать конфиг базы
class Databases(BaseModel):
    default: Database = Database(url="sqlite:///...")

# Можно разбивать настройки на группы
class GeneralSettings(BaseModel):
    debug: bool = False
    allowed_hosts: list[str] = ["*"]
    databases: Databases = Databases()
    ...

# можно структурировать конфиг самостоятельно
class TemplateEngine(DjangoModel):
    backend: str
    app_dirs: bool
    dirs: list[str]
    options: dict[str, Any]

class TemplateSettings(BaseModel):
    templates: list[TemplateEngine] = [
        TemplateEngine(
            backend = "django.template.backends.django.DjangoTemplates",
            dirs = [],
            app_dirs = True,
            options = {
                "context_processors": [
                    "django.template.context_processors.debug",
                    "django.template.context_processors.request",
                    "django.contrib.auth.context_processors.auth",
                    "django.contrib.messages.context_processors.messages",
                ],
            },
        ),
    ]

...

class ProjectSettings(
    GeneralSettings,
    TemplateSettings,
    ...,
    DjangoSettings
):
    # можно использовать всю мощь pydantic-settings для переопределения конфига из внешних источников
    model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore", env_prefix="DJANGO_")

ProjectSettings()

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

dj_pydantic_settings-0.1.1.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

dj_pydantic_settings-0.1.1-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file dj_pydantic_settings-0.1.1.tar.gz.

File metadata

  • Download URL: dj_pydantic_settings-0.1.1.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for dj_pydantic_settings-0.1.1.tar.gz
Algorithm Hash digest
SHA256 171462d7b7cfc120110cb91eb99fde9e13bc520d11f6a837b07518377050aa06
MD5 cbb4847ead070a615909c7fb99c2e48c
BLAKE2b-256 bc54d93a9aae815ff580c617a66938ec4880837fb6214849541d8d77a3eda11a

See more details on using hashes here.

File details

Details for the file dj_pydantic_settings-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dj_pydantic_settings-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b9bdd342af15a36f6b9b0ba2d8493f8d489c5c0f306195927a80fb77e8f0575f
MD5 88b17aecd52f47812ca28cadc1096a82
BLAKE2b-256 5820f2e0ae2907a0d958bbfcadb52ef24f0d76a6e0cf770a190ad299a53c8b24

See more details on using hashes here.

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