Skip to main content

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"}},
            },
        }
    },
}

Test pypi

Installation

pip3 install madtypes

Project details


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)

Uploaded Source

Built Distribution

madtypes-0.0.2-py3-none-any.whl (2.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page