Skip to content

Latest commit

 

History

History
61 lines (40 loc) · 961 Bytes

README.md

File metadata and controls

61 lines (40 loc) · 961 Bytes

spec

PyPI - Version

A statically typed data structure validator with support for advance features.


Table of Contents

Installation

$ pip install git+https://github.com/zomatree/spec

Usage

A simple class

class MyModel(spec.Model):
    a: int
    b: str

foo = MyModel({"a": 1, "b": "bar"})

print(foo.a)
print(foo.b)

Nested classes

class Inner(spec.Model):
    v: int

class Outer(spec.Model):
    inner: Inner
    other: str

data = Outer({"inner": {"v": 1}, "other": "foo"})

Renaming

from typing import Annotated

class MyModel(spec.Model):
    my_foo = Annotated[int, spec.rename("myFoo")]

data = MyModel({"myFoo": 1})

License

spec is distributed under the terms of the MIT license.