Constrained
Constrained (atlas.constrained) is the package containing the default validation type hints for request DTO fields.
Below are the descriptions of each type hint.
ConstrainedStr
Bases: str
ConstrainedStr is an abstract base class for creating string types with
custom validation rules in Pydantic models. It extends the native str type
and provides utility methods for length validation and serialization.
This class is designed to be subclassed, with subclasses implementing the
validate method to define domain-specific constraints (e.g., format, allowed characters).
Notes
- Subclasses must override
validate()to implement any domain-specific constraints. - This class integrates with Pydantic’s core schema system and serializers, ensuring compatibility with Pydantic models for both validation and serialization.
UuidStr
Bases: ConstrainedStr
UuidStr is a subclass of ConstrainedStr representing a UUID string with strict
format validation according to the standard version 4 UUID format.
This type is intended for use in Pydantic models and DTOs.
Constraints
- Format: canonical UUID v4 pattern (
xxxxxxxx-xxxx-4xxx-[8|9|a|b]xxx-xxxxxxxxxxxx)
UsernameStr
Bases: ConstrainedStr
UsernameStr is a subclass of ConstrainedStr representing a username string.
This type is intended for use in Pydantic models and DTOs.
Constraints
- Allowed characters: letters, digits, underscores (_), dots (.), and hyphens (-)
- Length: between 3 and 20 characters
PersonNameStr
Bases: ConstrainedStr
PersonNameStr is a subclass of ConstrainedStr representing a person's name string.
This type is intended for use in Pydantic models and DTOs.
Constraints
- Allowed characters: letters (including accented), apostrophes ('), spaces, and hyphens (-)
- Length: between 2 and 50 characters
PasswordStr
Bases: ConstrainedStr
PasswordStr is a subclass of ConstrainedStr representing a password string.
This type is intended for use in Pydantic models and DTOs.
Constraints
- Length: between 8 and 50 characters
- No restrictions on characters by default (other validations can be added in subclasses if needed)
EmailStr
Bases: ConstrainedStr
EmailStr is a subclass of ConstrainedStr representing an email address string.
This type is intended for use in Pydantic models and DTOs.
Constraints
- Maximum length: 100 characters
- Format: must follow a valid email address pattern
StateCodeStr
Bases: ConstrainedStr
StateCodeStr is a subclass of ConstrainedStr representing a state or region code.
This type is intended for use in Pydantic models and DTOs.
Constraints
- Format: must be 1 to 3 uppercase letters or digits
CountryCodeStr
Bases: ConstrainedStr
CountryCodeStr is a subclass of ConstrainedStr representing a country code.
This type is intended for use in Pydantic models and DTOs.
Constraints
- Format: must consist of exactly 2 uppercase letters (ISO country code format)
BrazilianDocumentStr
Bases: ConstrainedStr
BrazilianDocumentStr is a subclass of ConstrainedStr representing a Brazilian CPF or CNPJ number.
This type is intended for use in Pydantic models and DTOs.
Constraints
- Format: only numeric characters (non-digits are removed automatically)
- Validates CPF (11 digits) and CNPJ (14 digits) according to official check-digit rules
- Rejects sequences with repeated digits (e.g., '11111111111' or '00000000000000')
BrazilianPhoneStr
Bases: ConstrainedStr
BrazilianPhoneStr is a subclass of ConstrainedStr representing a Brazilian phone number.
This type is intended for use in Pydantic models and DTOs.
Constraints
- Format: must start with '+55' country code
- Valid DDD: two digits between 11 and 99
- Number length: 8 or 9 digits after DDD (allowing for landlines and mobile phones)
- Rejects any phone number that does not match the official Brazilian phone format
BrazilianZipcodeStr
Bases: ConstrainedStr
BrazilianZipcodeStr is a subclass of ConstrainedStr representing a Brazilian postal code (CEP).
This type is intended for use in Pydantic models and DTOs.
Constraints
- Format: five digits, optionally followed by a hyphen, then three digits (e.g., 12345-678 or 12345678)
- Only numeric characters are allowed
- Rejects any string that does not comply with the Brazilian CEP format
ExtraSmallTextStr
Bases: ConstrainedStr
ExtraSmallTextStr is a subclass of ConstrainedStr for very short text fields.
This type is intended for use in Pydantic models and DTOs.
Constraints
- Minimum length: 1 character
- Maximum length: 8 characters
SmallTextStr
Bases: ConstrainedStr
SmallTextStr is a subclass of ConstrainedStr for short text fields.
This type is intended for use in Pydantic models and DTOs.
Constraints
- Minimum length: 1 character
- Maximum length: 64 characters
MediumTextStr
Bases: ConstrainedStr
MediumTextStr is a subclass of ConstrainedStr for medium-length text fields.
This type is intended for use in Pydantic models and DTOs.
Constraints
- Minimum length: 1 character
- Maximum length: 512 characters
LargeTextStr
Bases: ConstrainedStr
LargeTextStr is a subclass of ConstrainedStr for long text fields.
This type is intended for use in Pydantic models and DTOs.
Constraints
- Minimum length: 1 character
- Maximum length: 2048 characters
ExtraLargeTextStr
Bases: ConstrainedStr
ExtraLargeTextStr is a subclass of ConstrainedStr for very long text fields.
This type is intended for use in Pydantic models and DTOs.
Constraints
- Minimum length: 1 character
- Maximum length: 8192 characters