Skip to main content

Scalar Types

Scalar types represent a single value and cannot contain other types. They are used to define simple data types.

None

schema.none

from d42 import schema

sch = schema.none

Bool

schema.bool

from d42 import schema

sch = schema.bool

schema.bool(value)

from d42 import schema

sch = schema.bool(True)

Int

schema.int

from d42 import schema

sch = schema.int

schema.int(value)

from d42 import schema

sch = schema.int(42)

schema.int.min(value)

from d42 import schema

sch = schema.int.min(0)

schema.int.max(value)

from d42 import schema

sch = schema.int.max(0)

Float

schema.float

from d42 import schema

sch = schema.float

schema.float(value)

from d42 import schema

sch = schema.float(3.14)

schema.float.min(value)

from d42 import schema

sch = schema.float.min(0.0)

schema.float.max(value)

from d42 import schema

sch = schema.float.max(0.0)

Str

schema.str

from d42 import schema

sch = schema.str

schema.str(value)

from d42 import schema

sch = schema.str("banana")

schema.str.len(length)

from d42 import schema

sch = schema.str.len(3)

schema.str.len(min_length, ...)

from d42 import schema

sch = schema.str.len(3, ...)

schema.str.len(..., max_length)

from d42 import schema

sch = schema.str.len(..., 3)

schema.str.len(min_length, max_length)

from d42 import schema

sch = schema.str.len(2, 3)

schema.str.alphabet(letters)

from d42 import schema
from string import ascii_letters

sch = schema.str.alphabet(ascii_letters)

schema.str.contains(substr)

from d42 import schema

sch = schema.str.contains("banana")

schema.str.regex(pattern)

from d42 import schema

sch = schema.str.regex(r"^[0-9]{4}$")

Bytes

note

New in version 1.4

schema.bytes

from d42 import schema

sch = schema.bytes

Datetime

note

New in version 1.6

schema.datetime

from d42 import schema

sch = schema.datetime

schema.datetime(value)

from datetime import datetime
from d42 import schema

now = datetime.now()
sch = schema.datetime(now)