Cuddles the Cat
"If it fits, I sits."
I'm writing more and more type-checked code, but I often get a bunch of strings I need to convert (e.g., from docopt
).
pydantic
feels heavy.type-docopt
uses a new syntax.bottle
seems like good inspiration for small, useful libraries.
python -m pip install castfit
Alternatively, you can just download the single file and name it castfit.py
.
from pathlib import Path
from castfit import castfit
class Cat:
name: str
age: int
weight: float
logo: Path
bob = castfit(Cat, dict(name="Bob", age="4", weight="3.2", logo="./bob.png"))
assert bob.name == "Bob"
assert bob.age == 4
assert bob.weight == 3.2
assert bob.logo == Path("./bob.png")