Hydraters

raw JSON →
0.1.3 verified Fri May 01 auth: no python

Hydrate Python dictionaries with Rust – provides fast, typed hydration and dehydration of Python dicts using Rust-backed classes. Current version 0.1.3, actively maintained.

pip install hydraters
error AttributeError: 'NoneType' object has no attribute 'hydrate'
cause Hydrate instance was not created correctly, possibly due to wrong import or missing class.
fix
Ensure you use 'from hydraters import Hydrate' and pass a class to the constructor: Hydrate(MyClass)
error TypeError: __init__() missing 1 required positional argument: 'name'
cause The dict does not contain a required field for the class's __init__.
fix
Include all required fields in the dict, matching the class annotations.
error ImportError: cannot import name 'Hydrate' from 'hydraters'
cause Using an old version or wrong import path. Before v0.1.3 the symbol was under nested module.
fix
Upgrade to latest version: pip install --upgrade hydraters. Then use 'from hydraters import Hydrate'.
gotcha Hydrate only works with dataclasses or classes that have __init__ annotated with types. Plain dicts or non-annotated classes will fail.
fix Ensure your class has type annotations on __init__ parameters or is a dataclass.
gotcha The library does not support default values or optional fields in the hydrated class. All fields must be provided.
fix Provide all fields in the dict, or use a custom default handling.
deprecated The old import path 'from hydraters.hydrate import Hydrate' is deprecated and may be removed in a future release.
fix Use 'from hydraters import Hydrate' instead.

Basic usage: create a Hydrate instance with a class, then call .hydrate() on a dict.

from hydraters import Hydrate

# Define a simple class to hydrate
class Person:
    def __init__(self, name: str, age: int):
        self.name = name
        self.age = age

# Create a Hydrate instance
hydrator = Hydrate(Person)

# Hydrate a dict into an instance
data = {"name": "Alice", "age": 30}
person = hydrator.hydrate(data)
print(person.name, person.age)  # Alice 30