Skip to main content

pydantist

AI-DECLARATION: assist Python uv PyPI Downloads

Lightweight and dependency-free alternative to pydantic.

from pydantist import DantistModel

class User(DantistModel):
    name: str
    age: int
    active: bool

    def __init__(self, name: str, age: int):
        self.name = name
        self.age = age
        self.active = True


user = User('Foo', 30)
print(user.name)  # Foo
print(user.age)  # 30
print(user.active)  # True

user = User.from_dict({'name': 'Bar', 'age': '67', 'active': 'no'})
print(user.name)  # Bar
print(user.age)  # 67
print(user.active)  # False

Key features

  • Set your own __init__ - pydantist doesn't touch it
  • Typed containers - list[int] / dict[str, float], nested like list[list[int]]
  • Custom converters registry - you can easily add your own type
  • Lightweight and zero dependencies - whole lib size is less than 10 KB

Custom converters

from pydantist import DantistModel, register_converter


class RGB:
    def __init__(self, r: int, g: int, b: int):
        self.r, self.g, self.b = r, g, b
    
    @classmethod
    def from_hex(cls, value: str) -> "RGB":
        value = value.removeprefix("#")
        return cls(*(int(value[i:i + 2], 16) for i in (0, 2, 4)))

register_converter(str, RGB, RGB.from_hex)

class Theme(DantistModel):
    background: RGB

theme = Theme.from_dict({"background": "#1e1e2e"})
print(theme.background.r)  # 30

To allow format subclasses with your converter, pass subclasses=True:

class RGBA(RGB):
    def __init__(self, r: int, g: int, b: int, a: int):
        super().__init__(r, g, b)
        self.a = a

    @classmethod
    def from_hex(cls, value: str) -> "RGB":
        value = value.removeprefix("#")
        return cls(*(int(value[i:i + 2], 16) for i in (0, 2, 4, 6)))


register_converter(str, RGB, lambda value, target_type: target_type.from_hex(value), subclasses=True)

class Theme(DantistModel):
    background: RGB
    overlay: RGBA

theme = Theme.from_dict({"background": "#1e1e2e", "overlay": "#00000080"})
print(theme.overlay.a)  # 128
print(theme.background.r)  # 30

Installation

Requires Python 3.11+.

uv

uv add pydantist

pip

pip install pydantist

Roadmap

  • to_dict
  • Custom field validators/serializers (like pydantic)
  • Format modes (strict/lossy)
  • Extended and meaningful exceptions

Metadata

Release files for pydantist 0.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 pydantist 0.2.0
File Size Uploaded Provenance Actions
pydantist-0.2.0.tar.gz 6.2 kB Without provenance Details for pydantist-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pydantist 0.2.0
File Interpreter ABI Platform Actions
pydantist-0.2.0-py3-none-any.whl Python 3 none any Details for pydantist-0.2.0-py3-none-any.whl

Total release size: 14.0 kB

Release files / pydantist-0.2.0.tar.gz

Download URL pydantist-0.2.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f4a662ca5d91df20e51fa6bc51f138cab11a7c07a5883e1a4c5a9833f6cc2f14
BLAKE2b-256 checksum
How to use checksums
de01069dbf03f92603d2a652e723cb2bc1ddcab5e34b5d9afe3a4996146a871f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22.3","id":"zena","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / pydantist-0.2.0-py3-none-any.whl

Download URL pydantist-0.2.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c1e0c34f85712b2ef202ca181e9ba423f3d09df30e12bfd91e362794cb2248c6
BLAKE2b-256 checksum
How to use checksums
52b5fc7494ba4c264b5e605b3d6aaae85f8e92a1f425b09b98b313b6959ff8ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22.3","id":"zena","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for pydantist 0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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