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.1.1

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.1.1
File Size Uploaded Provenance Actions
pydantist-0.1.1.tar.gz 4.2 kB Without provenance Details for pydantist-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 9.6 kB

Release files / pydantist-0.1.1.tar.gz

Download URL pydantist-0.1.1.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d21f3888cb97ed8085ce8a488787a0fdfeb11affe6b2f239042337596b02f65c
BLAKE2b-256 checksum
How to use checksums
a0598b00c72944df70feab754d8d5e6f5faf347d6771e088aba1f3e57b7f5bcc
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.1.1-py3-none-any.whl

Download URL pydantist-0.1.1-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c05252af8673afd3755683aa2b4871cf1479af6a0eca064db5bbb36ab42f462
BLAKE2b-256 checksum
How to use checksums
b739f1a534e2c9f2095709048599499fdda2ffaf1b5a1cff55e7bb5499683253
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.1.1

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