Skip to content

Built-ins by role

The API reference lists every name with its signature, and the voluptuous compatibility page maps each name to its status against voluptuous. This page is the third lens: what role each built-in plays, so you can find the right tool by the job you need done rather than by remembering its name.

Everything here splits into four roles:

  • Markers are dictionary keys that carry intent (required, optional, secret).
  • Combinators compose or wrap other validators (All, Any, Maybe).
  • Validators check a value and return it unchanged.
  • Transformers return a changed value.

The line that matters most runs between the last two. A validator is a gate: the value passes through untouched or it raises. A transformer rewrites the value, so the thing that comes out is not the thing that went in. Transformers split again by whether the type changes:

  • A converter changes the type ("5" to 5, "192.0.2.1" to an IPv4Address). Its name says so: As<Type> converts to a named type, From<Source> decodes a source, Coerce is the generic one.
  • A normalizer keeps the type and cleans the value ("ABC" to "abc", a number clamped into a range). Its name reads as an action on the value (Lower, Strip, Clamp).

Knowing the role tells you where a name belongs in a chain. Validators and transformers run left to right inside All, so a converter early in the chain decides the type every later step sees.

Dictionary keys that carry intent. Each compares and hashes by its underlying key, so a marker stands in for the bare key.

NameNote
RequiredThe key must be present.
OptionalThe key may be present; a default fills in.
RemoveDrop matching keys from the output.
ExtraCatch-all key for the rest of a mapping.
InclusiveGroup of keys that must appear together.
ExclusiveGroup of keys of which at most one may appear.
SelfA recursive reference to the schema.
ForbiddenThe key must be absent.
AliasAccept the key under alternate input names.
SecretRedact the key’s value in error output.

Compose or wrap other validators.

NameNote
AllRun each in turn; the output of one feeds the next.
AnyThe first that accepts wins.
AndAlias of All.
OrAlias of Any.
UnionAny with an optional discriminant.
SwitchAlias of Union.
TaggedUnionRoute on one key’s value to the matching schema.
SomeOfBetween min_valid and max_valid must pass.
MaybeAccept None, otherwise the wrapped validator.
MsgOverride a validator’s error message.

Check a value and return it unchanged.

NameNote
LiteralEqual to a literal value.
EqualEqual to a target.
InA member of a container.
NotInNot a member of a container.
ContainsContains a target value.
MatchMatches a regular expression.
IsRegexA compilable regular expression.
ObjectAttributes validated like a mapping.
ExactSequenceA sequence matching a fixed shape.
UnorderedA sequence in any order.
UniqueNo duplicate elements.
SortedAlready in ascending order.
LengthLength within bounds.
NonEmptyNot empty.
NameNote
RangeWithin a numeric range.
NumberA number; yield_decimal=True returns a Decimal.
PositiveGreater than zero.
NegativeLess than zero.
NonNegativeZero or greater.
MultipleOfAn exact multiple of a base.
ByteAn integer from 0 to 255.
SmallFloatA float from 0 to 1.
LatitudeA valid latitude.
LongitudeA valid longitude.
PercentageA number or "NN%" string in 0 to 100.
NameNote
EmailAn email address.
UrlA URL.
FqdnUrlA URL with a fully qualified domain.
SlugA URL slug.
AlphaLetters only.
AlphanumericLetters and digits only.
ASCIIASCII characters only.
PrintableASCIIPrintable ASCII only.
NoWhitespaceNo whitespace characters.
StartsWithBegins with a prefix.
EndsWithEnds with a suffix.
ByteLengthUTF-8 byte length within bounds.
HexColorA hex color; compose Lower/Upper for case.
HexHexadecimal; checks, does not decode.
Base64Base64; checks, does not decode.
JSONStringA JSON string; value via FromJSONString.
ULIDA ULID; compose Upper for canonical case.
DataURIA data: URI.
DatetimeA datetime string; string in, string out.
DateA date string; string in, string out.
TimeA time string; string in, string out.
DurationA duration (also a timedelta, a number of seconds, or a mapping); object via AsTimedelta.
TimeZoneA UTC offset; object via AsTimezone.
TimeZoneInfoAn IANA name; object via Coerce(ZoneInfo).

Check the format and return the string unchanged. The parsed object is opt-in through Coerce, since each of these types constructs from its string.

NameNote
HostnameA hostname.
FqdnA fully qualified domain name.
PortA TCP/UDP port number; returns an int.
MacAddressA MAC address; canonical form via NormalizeMacAddress.
UUIDA UUID; object via Coerce(uuid.UUID).
IPv4AddressObject via Coerce(ipaddress.IPv4Address).
IPv6AddressObject via Coerce(ipaddress.IPv6Address).
IPAddressObject via Coerce(ipaddress.ip_address).
IPNetworkObject via Coerce(lambda v: ipaddress.ip_network(v, strict=False)); plain ip_network rejects host bits.
NameNote
IsDirAn existing directory.
IsFileAn existing file.
PathExistsAn existing path.
IsSymlinkA symbolic link.
IsSocketA socket.
IsFifoA FIFO.
IsBlockDeviceA block device.
NameNote
IsTrueA truthy value.
IsFalseA falsy value.

Run over a whole mapping, usually after a dict schema with All.

NameNote
RequiredWithRequired when another key is present.
RequiredWithoutRequired when another key is absent.
RequiredIfRequired when a condition holds.
CheckAn arbitrary predicate over the value.
AtLeastOneAt least one of a set of keys is present.
AtMostOneAt most one of a set of keys is present.
ExactlyOneExactly one of a set of keys is present.
AllOrNoneAll of a set of keys, or none.
ImmutableRejects a change against the prior value.
WriteOnceRejects a second write.

Return a changed value.

The type changes.

NameResult
Coercetype(value), the generic convert.
BooleanA string to a bool.
SetAn iterable to a set.
EnsureListA scalar to a one-element list.
AsDatetimeA string to a datetime.
AsDateA string to a date.
AsTimeA string to a time.
AsTimedeltaA duration to a timedelta.
AsTimezoneAn offset to a datetime.timezone.
FromEpochA timestamp to a datetime.
FromPercentage"80%" to a float.
HexIntA hex string to an int.
FromJSONStringA JSON string to the decoded value.
DefaultToNone to a default (substitution).
EmptyToNoneAn empty string or container to None.
MapA value to its entry in a lookup table.
SetToAnything to a fixed value (substitution).

The type stays; the value is cleaned.

NameResult
LowerLowercase.
UpperUppercase.
CapitalizeCapitalized.
TitleTitle-cased.
StripWhitespace trimmed.
CollapseWhitespaceWhitespace runs squeezed to one space.
RemovePrefixA leading prefix removed if present.
RemoveSuffixA trailing suffix removed if present.
TruncateCut to at most max_length characters.
ReplaceRegular-expression replace.
ClampA number pinned into a range.
NormalizeMacAddressA MAC address in canonical form.
CreditCardA card number (Luhn), stripped to bare digits.
IBANAn IBAN (mod-97), compacted and upper-cased.
E164An E.164 phone number, grouping stripped.

Compute a new number from the input. The result follows Python’s own arithmetic type, so an integer operation on an int stays an int, while a divisor or a fractional operand yields a float (Divide and Remap always do).

NameResult
MultiplyA number times a factor.
DivideA number divided by a divisor.
OffsetA number plus an amount.
RoundA number rounded to decimals, or to an integer.
RoundUpA number’s ceiling (a whole integer).
RoundDownA number’s floor (a whole integer).
SnapA number rounded to the nearest step.
AbsA number’s absolute value.
ModuloA number reduced modulo n (wrap-around).
RemapA number mapped from one range onto another.
ScaleA number rescaled (factor/divisor/offset).

Reshape a list rather than validate it. Sort and Dedupe are the doing siblings of the Sorted and Unique validators.

NameResult
SplitA delimited string into a list.
JoinA list into a delimited string.
SortA list ordered (a new list).
DedupeA list without duplicates, first-seen order kept.
FirstThe first item of a sequence.
LastThe last item of a sequence.
WithoutA list without the listed values.

CreditCard, IBAN, and E164 normalize by default; pass normalize=False to validate and return the value unchanged.