Fast data struct type with validation + JSON serialization for Python.
- High performance — 5-60x faster than dataclasses, attrs, or pydantic for common operations
- Schema validation — familiar Python type annotations, enforced at decode time
- No runtime dependencies — built on a monolithic C extension based on msgspec
- Rich type support — nested Structs, dataclasses, TypedDicts, enums, UUID, Decimal, datetime, and more
- JSON Schema generation — auto-generate JSON Schema 2020-12 / OpenAPI 3.1 specs
pip install structtypeuv add structtypeRequires Python ≥ 3.10.
from structtype import Struct
class User(Struct):
name: str
groups: set[str] = set()
email: str | None = None
alice = User("alice", groups={"admin", "engineering"})
# Serialize to JSON
alice.struct_dump_json()
# b'{"name":"alice","groups":["admin","engineering"],"email":null}'
# Deserialize and validate
User.struct_validate_json(
b'{"name":"alice","groups":["admin","engineering"],"email":null}'
)
# User(name='alice', groups={"admin", "engineering"}, email=None)Full documentation is available at https://tds333.github.io/structtype/.
The library is in beta phase, interface and features may have breaking changes.
structtype is as fast as msgspec and about 3-5x faster than pydantic. See the benchmarks page for the full numbers.
New BSD. See the License File. Parts of the core are based on the work of Jim Crist-Harif from msgspec.