parasite
¶
Member Reference¶
- class parasite.Namespace[source]¶
Abstract base class for all namespace implementations. This class tries to mimic the behavior of a namespace in other programming languages.
Warning
Do not instantiate this class directly. It is only meant to be used as a base class for namespace implementations.
- Inheritance:
- Raises:
TypeError – Always, as this class is not meant to be instantiated.
- class parasite.p[source]¶
sudo-namespace for all
parasite
types. Makes it easier to import and call them. Tries to mimic the behavior of thez
object imported fromzod
library in JavaScript.- Inheritance:
- Raises:
TypeError – Always, as this class is not meant to be instantiated.
- Example usage:
Let’s assume we have the following schema:
from parasite import p schema = p.obj({ "name": p.string().required(), "age": p.number().integer().min(0).optional(), }).strip()
and the following data:
data = { "name": "John Doe", "age": 42, "extra": "This will be stripped", }
The schema will parse the following objects:
>>> schema.parse(data) { "name": "John Doe", "age": 42 } >>> schema.parse({}) ValidationError: key "name" not found, but is required
- Raises:
TypeError – Always, as this class is not meant to be instantiated.
- number¶
alias of
Number