Skip to main content

djc-ext-pydantic

PyPI - Version PyPI - Python Version PyPI - License PyPI - Downloads GitHub Actions Workflow Status

Validate components' inputs and outputs using Pydantic.

djc-ext-pydantic is a django-component extension that integrates Pydantic for input and data validation.

Example Usage

from django_components import Component, SlotInput
from djc_pydantic import ArgsBaseModel
from pydantic import BaseModel

# 1. Define the Component with Pydantic models
class MyComponent(Component):
    class Args(ArgsBaseModel):
        var1: str

    class Kwargs(BaseModel):
        name: str
        age: int

    class Slots(BaseModel):
        header: SlotInput
        footer: SlotInput

    class TemplateData(BaseModel):
        data1: str
        data2: int

    class JsData(BaseModel):
        js_data1: str
        js_data2: int

    class CssData(BaseModel):
        css_data1: str
        css_data2: int

    ...

# 2. Render the component
MyComponent.render(
    # ERROR: Expects a string
    args=(123,),
    kwargs={
        "name": "John",
        # ERROR: Expects an integer
        "age": "invalid",
    },
    slots={
        "header": "...",
        # ERROR: Expects key "footer"
        "foo": "invalid",
    },
)

Installation

pip install djc-ext-pydantic

Then add the extension to your project:

# settings.py
COMPONENTS = {
    "extensions": [
        "djc_pydantic.PydanticExtension",
    ],
}

or by reference:

# settings.py
from djc_pydantic import PydanticExtension

COMPONENTS = {
    "extensions": [
        PydanticExtension,
    ],
}

Validating args

By default, Pydantic's BaseModel requires all fields to be passed as keyword arguments. If you want to validate positional arguments, you can use a custom subclass ArgsBaseModel:

from pydantic import BaseModel
from djc_pydantic import ArgsBaseModel

class MyTable(Component):
    class Args(ArgsBaseModel):
        a: int
        b: str
        c: float

MyTable.render(
    args=[1, "hello", 3.14],
)

Release notes

Read the Release Notes to see the latest features and fixes.

Development

Tests

To run tests, use:

pytest

Metadata

Release files for djc-ext-pydantic 1.2.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 djc-ext-pydantic 1.2.0
File Size Uploaded Provenance Actions
djc_ext_pydantic-1.2.0.tar.gz 7.8 kB With provenance Details for djc_ext_pydantic-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for djc-ext-pydantic 1.2.0
File Interpreter ABI Platform Actions
djc_ext_pydantic-1.2.0-py3-none-any.whl Python 3 none any Details for djc_ext_pydantic-1.2.0-py3-none-any.whl

Total release size: 14.6 kB

Release files / djc_ext_pydantic-1.2.0.tar.gz

Download URL djc_ext_pydantic-1.2.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5abd28ae95c31e02519a9ea095f42e587c50fa01ffef27b336d4deb3c3183f7d
BLAKE2b-256 checksum
How to use checksums
71dc5038c6cc4f10d02cfc61e3955af284c31ab610f700af5ac568533571e291
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 18, 2026.

Transparency log

Release files / djc_ext_pydantic-1.2.0-py3-none-any.whl

Download URL djc_ext_pydantic-1.2.0-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3afd778496091cb26fe83de7b4b97326a2fd8f4d42e1d103150aa4a9ef1f1579
BLAKE2b-256 checksum
How to use checksums
ae1a2de5fb81a4ea673f46943224d6431a549f2e38ca11344fcec497c9846252
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 18, 2026.

Transparency log

Security for djc-ext-pydantic 1.2.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 djc_ext_pydantic-1.2.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 18, 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.

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