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.3.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.3.0
File Size Uploaded Provenance Actions
pydantist-0.3.0.tar.gz 6.2 kB Without provenance Details for pydantist-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 14.0 kB

Release files / pydantist-0.3.0.tar.gz

Download URL pydantist-0.3.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5e23d3b7b9890e2180eb2ee546a72714c81cc05c498db5db94016ceba62b621b
BLAKE2b-256 checksum
How to use checksums
9562b4b204fd5ebbb1adbb0812d1657b0ac2b5ca6aa4eba5a3ac08930529f410
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.3.0-py3-none-any.whl

Download URL pydantist-0.3.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4020314fc3b286a7ae128b2a24b7b3ce815d71556bc36ff7918593121bb71001
BLAKE2b-256 checksum
How to use checksums
9ac4d577212310c4134132f29f54d8d4d914f781626da7c5f7c03b0ccbd996cb
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.3.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