Skip to main content

Pydantic extensions

PyPI Python License

English | Русский

Extensions for pydantic.

Installation

Requires Python 3.13 or later.

pip install cloudru-qa-pydantic-extensions

Import the library as the module pydantic_extensions.

Skills for AI agents

This library does not have its own skill yet. If your project uses other libraries from this suite with skills for AI agents, select and enable them from your project root (requires uv):

uvx library-skills

For Claude Code, add --claude.

Usage

The fields module

This module extends fields in pydantic models.

Serialization and deserialization

CamelCaseBaseModel and PascalCaseBaseModel convert field names to camelCase and PascalCase, respectively, when converting pydantic models to and from JSON.

from pydantic_extensions.fields import CamelCaseBaseModel


class User(CamelCaseBaseModel):
    username: str
    last_name: str
    is_active: bool


# Serialization
user = User(username="John", last_name="Smith", is_active=True)
assert user.model_dump_json() == '{"username":"John","lastName":"Smith","isActive":true}'

# Deserialization
json_content = {"username": "Aleksey", "lastName": "Petrov", "isActive": false}
user2 = User.model_validate(json_content)
assert user2.last_name == "Petrov"

The settings module

This module extends pydantic-settings.

Features

JsonBaseSettings, TomlBaseSettings, and YamlBaseSettings share these rules:

  • Custom source order: env -> dotenv -> secrets -> file -> init.
  • Support for a single file or a list of files.
  • All specified files must exist (FileNotFoundError).
  • Unknown file keys are rejected (ValueError).
  • All required model keys must be present in the file or another source (env / dotenv / secrets / init) (ValueError).
  • JSON/YAML files must have a dict root (TypeError).

File key validation

JsonBaseSettings, TomlBaseSettings, and YamlBaseSettings support two SettingsConfigDict flags:

  • validate_unknown_keys (default True): reject unknown file keys.
  • validate_required_keys (default True): check required model keys when reading the source. A key is missing only if it is absent from both the file and all other sources (env / dotenv / secrets / init). Required fields can therefore be set through environment variables without duplicating them in the file.

Strict mode (default):

from pydantic import Field
from pydantic_settings import SettingsConfigDict
from pydantic_extensions.settings import JsonBaseSettings


class MySettings(JsonBaseSettings):
    app_name: str
    debug: bool = Field(default=False)

    model_config = SettingsConfigDict(
        json_file="config.json",
        validate_unknown_keys=True,
        validate_required_keys=True,
    )

Ignore unknown keys:

from pydantic import Field
from pydantic_settings import SettingsConfigDict
from pydantic_extensions.settings import TomlBaseSettings


class MySettings(TomlBaseSettings):
    app_name: str = Field(default="")

    model_config = SettingsConfigDict(
        toml_file="config.toml",
        validate_unknown_keys=False,
    )

With validate_unknown_keys=False, extra keys are filtered out of the file source automatically, so extra="ignore" is not needed.

Disable early validation of required keys:

from pydantic_settings import SettingsConfigDict
from pydantic_extensions.settings import YamlBaseSettings


class MySettings(YamlBaseSettings):
    app_name: str
    debug: bool = False

    model_config = SettingsConfigDict(
        yaml_file="config.yaml",
        validate_required_keys=False,
    )

In this mode, the library does not check required keys when reading the file. Final pydantic model validation still runs.

If a field has a default value, a missing file key does not cause an error; the default is used:

from pydantic import Field
from pydantic_settings import SettingsConfigDict
from pydantic_extensions.settings import YamlBaseSettings


class MySettings(YamlBaseSettings):
    app_name: str = Field(default="my-app")
    debug: bool = Field(default=False)

    model_config = SettingsConfigDict(
        yaml_file="config.yaml",
        validate_required_keys=False,
    )


settings = MySettings()
# If config.yaml has no app_name, settings.app_name == "my-app"

If no default is set, pydantic raises ValidationError:

from pydantic_settings import SettingsConfigDict
from pydantic_extensions.settings import YamlBaseSettings


class MySettings(YamlBaseSettings):
    app_name: str

    model_config = SettingsConfigDict(
        yaml_file="config.yaml",
        validate_required_keys=False,
    )


MySettings()  # ValidationError if app_name is missing from config.yaml

YAML settings

Use YamlBaseSettings to load settings from one or more YAML files:

from pydantic import Field
from pydantic_settings import SettingsConfigDict
from pydantic_extensions.settings import YamlBaseSettings


class MySettings(YamlBaseSettings):
    app_name: str = Field(default="")
    debug: bool = Field(default=False)
    port: int = Field(default=0)

    model_config = SettingsConfigDict(yaml_file="config.yaml")

Install the extra dependency for YAML support:

pip install "cloudru-qa-pydantic-extensions[yaml]"

JSON settings

Use JsonBaseSettings to load settings from one or more JSON files:

from pydantic import Field
from pydantic_settings import SettingsConfigDict
from pydantic_extensions.settings import JsonBaseSettings


class MySettings(JsonBaseSettings):
    app_name: str = Field(default="")
    debug: bool = Field(default=False)
    port: int = Field(default=0)

    model_config = SettingsConfigDict(json_file="config.json")

TOML settings

Use TomlBaseSettings to load settings from one or more TOML files:

from pydantic import Field
from pydantic_settings import SettingsConfigDict
from pydantic_extensions.settings import TomlBaseSettings


class MySettings(TomlBaseSettings):
    app_name: str = Field(default="")
    debug: bool = Field(default=False)
    port: int = Field(default=0)

    model_config = SettingsConfigDict(toml_file="config.toml")

Install the extra dependency for TOML support:

pip install "cloudru-qa-pydantic-extensions[toml]"

Encoding support

For YAML and JSON settings, set the file encoding with *_file_encoding:

model_config = SettingsConfigDict(yaml_file="config.yaml", yaml_file_encoding="windows-1251")

Loading multiple files

All settings classes support loading multiple files. This is useful when each environment has its own file alongside a shared settings file. For example, with YAML:

import os

from pydantic import Field
from pydantic_settings import SettingsConfigDict
from pydantic_extensions.settings import YamlBaseSettings

ENV = os.getenv("ENV")


class MySettings(YamlBaseSettings):
    app_name: str = Field(default="")
    debug: bool = Field(default=False)
    port: int = Field(default=0)

    model_config = SettingsConfigDict(
        yaml_file=[
            "config.common.yaml",
            f"config.{ENV}.yaml",
        ],
    )

If a variable occurs in both files, its value comes from the last file, config.{ENV}.yaml in this example.

YAML, TOML, and JSON configuration files can also be combined with .env files:

from pydantic import Field
from pydantic_settings import SettingsConfigDict
from pydantic_extensions.settings import YamlBaseSettings


class MySettings(YamlBaseSettings):
    app_name: str = Field(default="")
    debug: bool = Field(default=False)
    port: int = Field(default=0)

    # Read configuration from both env and YAML files.
    # Source priority: env -> dotenv -> secrets -> file -> init.
    model_config = SettingsConfigDict(
        env_file=".env",
        yaml_file=f"config.yaml",
    )

Development

This library is developed in the qa-libraries monorepo alongside the other cloudru-qa-* libraries. You need uv, GNU Make and checkmake; run the commands from the repository root:

make sync                            # dependencies and extras for all libraries from uv.lock
make test-pydantic-extensions        # tests for this library
make typecheck-pydantic-extensions   # mypy for this library
make check                           # formatting, Ruff, mypy, and tests for the whole suite

⚠️ Keep the library lightweight and general purpose. Add dependencies only when they are needed by all library users. Make heavy dependencies optional (see the uv documentation).

Tests run on Python 3.13 and 3.14. Each version uses a separate environment: make sync test-pydantic-extensions PYTHON_VERSION=3.14.

Create a release with the Git tag pydantic-extensions/v<version>. The tag version must match the version in packages/pydantic-extensions/pyproject.toml.

Metadata

Release files for cloudru-qa-pydantic-extensions 1.0.0

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

Source distribution (sdist)

Source distribution for cloudru-qa-pydantic-extensions 1.0.0
File Size Uploaded Provenance Actions
cloudru_qa_pydantic_extensions-1.0.0.tar.gz 15.8 kB With provenance Details for cloudru_qa_pydantic_extensions-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cloudru-qa-pydantic-extensions 1.0.0
File Interpreter ABI Platform Actions
cloudru_qa_pydantic_extensions-1.0.0-py3-none-any.whl Python 3 none any Details for cloudru_qa_pydantic_extensions-1.0.0-py3-none-any.whl

Total release size: 33.2 kB

Release files / cloudru_qa_pydantic_extensions-1.0.0.tar.gz

Download URL cloudru_qa_pydantic_extensions-1.0.0.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
aaa897403f20289665d375483f0ef67bf119247ab4f510b94fa0697e071b4727
BLAKE2b-256 checksum
How to use checksums
8182448029a09fa0f73da3a4f51ee8b364a8e87bd4630b42325b8c89920a3b8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Release files / cloudru_qa_pydantic_extensions-1.0.0-py3-none-any.whl

Download URL cloudru_qa_pydantic_extensions-1.0.0-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b4915f3111075499b8665a89df0b39897fcfae685c0ca30b1f6f935c2a4bf9a
BLAKE2b-256 checksum
How to use checksums
14eb5b583e29e24843321caa141c63e5cfaa780f728a6779f5b2a301d54acc67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Security for cloudru-qa-pydantic-extensions 1.0.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cloudru_qa_pydantic_extensions-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

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

1.0.0 This release

2 release files Full 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