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:

Inheritance diagram of parasite.Namespace

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 the z object imported from zod library in JavaScript.

Inheritance:

Inheritance diagram of parasite.p

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.

any

alias of Any_

null

alias of Null

number

alias of Number

string

alias of String

boolean

alias of Boolean

never

alias of Never

variant

alias of Variant

obj

alias of Object

array

alias of Array