Python typing that will raise TypeError at runtime
Project description
madtypes
- 💢 Python class typing that will raise TypeError at runtime
- 📖 Render to dict or json
- 🌐 Json-Schema
Example
from madtypes import Schema
class Item(Schema)
name: str
e = Item()
e.name = 2 # will raise ValueError
Item(name="foo") # ok
Item(name=2) # will raise valueError
repr(Item(name="foo")) == {"name": "foo"}
json.dumps(Item(name="foo")) => '{"name": "foo"}'
json-schema
from madtypes import schema, Schema
class Item(Schema):
name: str
class Basket(Schema):
items: list[Item]
assert schema(Basket) == {
"type": "object",
"properties": {
"items": {
"type": "array",
"items": {
"type": "object",
"properties": {"name": {"type": "string"}},
},
}
},
}
Installation
pip3 install madtypes
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
madtypes-0.0.2.tar.gz
(3.7 kB
view hashes)