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.0.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

dj_pydantic_settings-0.1.0-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dj_pydantic_settings-0.1.0.tar.gz
  • Upload date:
  • Size: 2.7 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.0.tar.gz
Algorithm Hash digest
SHA256 e7a801c2a3f79999f1240df9deeecd7dea2e51374f66ebd5404ba7931de0db3f
MD5 e5454ad0d5527fc322d4fe3b0192f1ba
BLAKE2b-256 53e1cb1ea4637e5ead214703e316643725acdf60cfb2413f1763ce6b28c03a9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dj_pydantic_settings-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 90c748d5e656d448d6e5afe44a9de8ced4d3e41312487e9d8c6530c411ceefe9
MD5 58056e7e5b144a904f8bfd5596d4e4c7
BLAKE2b-256 149d4bda889c463d12a196c53d4498223312467638d549dbb1502571ffde5e2e

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