Types
plateforme.core.types.binaries
This module provides utilities for managing binary types within the Plateforme framework leveraging Pydantic schemas for validation and serialization, and compatibility with SQLAlchemy's data type system.
StrictBinary
module-attribute
A binary that must be validated strictly.
BinaryFactory
Bases: BaseTypeFactory[bytes]
A binary type factory.
It extends the built-in bytes
class with additional validation and schema
methods.
plateforme.core.types.datetimes
This module provides utilities for managing datetime types within the Plateforme framework leveraging Pydantic schemas for validation and serialization, and compatibility with SQLAlchemy's data type system.
StrictDate
module-attribute
A date that must be validated strictly.
PastDateTime
module-attribute
A date time that must be in the past.
FutureDateTime
module-attribute
A date time that must be in the future.
AwareDateTime
module-attribute
A date time that must be timezone aware.
NaiveDateTime
module-attribute
A date time that must be timezone naive.
StrictDateTime
module-attribute
A date time that must be validated strictly.
StrictTime
module-attribute
A time that must be validated strictly.
StrictTimeDelta
module-attribute
A time delta that must be validated strictly.
DateFactory
Bases: BaseTypeFactory[date]
A date type factory.
It extends the built-in datetime.date
class with additional validation
and schema methods.
DateTimeFactory
Bases: BaseTypeFactory[datetime]
A date time type factory.
It extends the built-in datetime.datetime
class with additional
validation and schema methods.
TimeFactory
Bases: BaseTypeFactory[time]
A time type factory.
It extends the built-in datetime.time
class with additional validation
and schema methods.
TimeDeltaFactory
Bases: BaseTypeFactory[timedelta]
A time delta type factory.
It extends the built-in datetime.timedelta
class with additional
validation and schema methods.
plateforme.core.types.enums
This module provides utilities for managing enum types within the Plateforme framework leveraging Pydantic schemas for validation and serialization, and compatibility with SQLAlchemy's data type system.
StrictEnum
module-attribute
An enum that must be validated strictly.
EnumFactory
Bases: BaseTypeFactory[Enum]
An enum type factory.
It extends the built-in enum.Enum
class with additional validation and
schema methods.
plateforme.core.types.json
This module provides utilities for managing JSON type within the Plateforme framework leveraging Pydantic schemas for validation and serialization, and compatibility with SQLAlchemy's data type system.
Json
Bases: BaseType
A special type wrapper which loads JSON before parsing.
The Json
data type makes Pydantic first load a raw JSON string before
validating the loaded data into the parametrized type:
When the model is dumped using model_dump
or model_dump_json
, the
dumped value will be the result of validation, not the original JSON
string. However, the argument round_trip=True
can be used to get the
original JSON string back.
validate
classmethod
validate(
__value: Any, info: ValidationInfo | None = None
) -> Self
Validate value and return a new instance of the type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__value
|
Any
|
Value to validate. |
required |
info
|
ValidationInfo | None
|
Addition information to pass to the validator.
Defaults to |
None
|
Returns:
Type | Description |
---|---|
Self
|
A type initialized with validated |
Examples:
>>> class MyType(BaseType, int):
... @classmethod
... def validate(cls, value: Any) -> Self:
... if value < 0:
... raise ValueError('Value must be positive.')
... return cls(value)
>>> MyType(1)
1
>>> MyType(-1)
ValueError: Value must be positive.
Note
Override and add validation logic here, if necessary. The
validation is performed after the schema validation. For more
complex logic, you may want to override the
__get_pydantic_core_schema__
and __get_pydantic_json_schema__
methods directly.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/types/base.py
serialize
classmethod
serialize(
__value: Self, info: SerializationInfo | None = None
) -> Any
Return the serialized instance of the type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__value
|
Self
|
Value to serialize. |
required |
info
|
SerializationInfo | None
|
Additional information to pass to the serializer.
Defaults to |
None
|
Returns:
Type | Description |
---|---|
Any
|
A serialized instance. |
Examples:
>>> class MyType(BaseType, int):
... @classmethod
... def serialize(cls, value: Self) -> str:
... return f"Serialized {self!r}"
Note
Override and add serialization logic here, if necessary. The
serialization to be invoked is set up in the schema. For more
complex logic, you may want to override the
__get_pydantic_core_schema__
and __get_pydantic_json_schema__
methods directly.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/types/base.py
plateforme.core.types.networks
This module provides utilities for managing network types within the Plateforme framework leveraging Pydantic schemas for validation and serialization, and compatibility with SQLAlchemy's data type system.
DEFAULT_DRIVERS
module-attribute
DEFAULT_DRIVERS = {
"oracle": "oracledb",
"postgresql": "asyncpg",
"mariadb": "asyncmy",
"mssql": "aioodbc",
"mysql": "asyncmy",
"sqlite": "aiosqlite",
}
The default database drivers for the supported database engines.
IPvAddressFactoryAlias
module-attribute
IPvAddressFactoryAlias = Union[
IPv4Address | IPv6Address | PydanticIPvAnyAddress
]
A type alias for the IP address factory type.
IPvAnyAddress
module-attribute
IPvAnyAddress = Annotated[PydanticIPvAnyAddress, ...]
The IP address proxy.
IPvInterfaceFactoryAlias
module-attribute
IPvInterfaceFactoryAlias = Union[
IPv4Interface | IPv6Interface | PydanticIPvAnyInterface
]
A type alias for the IP interface factory type.
IPvAnyInterface
module-attribute
IPvAnyInterface = Annotated[PydanticIPvAnyInterface, ...]
The IP interface proxy.
IPv4Interface
module-attribute
IPv4Interface = Annotated[IPv4Interface, ...]
An IPv4 interface proxy.
IPv6Interface
module-attribute
IPv6Interface = Annotated[IPv6Interface, ...]
An IPv6 interface proxy.
IPvNetworkFactoryAlias
module-attribute
IPvNetworkFactoryAlias = Union[
IPv4Network | IPv6Network | PydanticIPvAnyNetwork
]
A type alias for the IP network factory type.
IPvAnyNetwork
module-attribute
IPvAnyNetwork = Annotated[PydanticIPvAnyNetwork, ...]
The IP network proxy.
AnyHttpUrl
module-attribute
AnyHttpUrl = Annotated[PydanticUrl, ...]
A URL that must implement the HTTP scheme.
HttpUrl
module-attribute
HttpUrl = Annotated[PydanticUrl, ...]
A URL that must implement the HTTP scheme with 2083 max length.
FileUrl
module-attribute
FileUrl = Annotated[PydanticUrl, ...]
A URL that must implement the file scheme.
AnyMultiHostUrl
module-attribute
AnyMultiHostUrl = Annotated[PydanticMultiHostUrl, ...]
The multi host URL proxy.
PostgresDsn
module-attribute
PostgresDsn = Annotated[PydanticMultiHostUrl, ...]
A PostgreSQL DSN URL.
UrlConstraints
dataclass
UrlConstraints(
max_length: int | None = None,
allowed_schemes: list[str] | None = None,
host_required: bool | None = None,
default_host: str | None = None,
default_port: int | None = None,
default_path: str | None = None,
)
Bases: PydanticMetadata
Url constraints.
Attributes:
Name | Type | Description |
---|---|---|
max_length |
int | None
|
The maximum length of the url. Defaults to |
allowed_schemes |
list[str] | None
|
The allowed schemes. Defaults to |
host_required |
bool | None
|
Whether the host is required. Defaults to |
default_host |
str | None
|
The default host. Defaults to |
default_port |
int | None
|
The default port. Defaults to |
default_path |
str | None
|
The default path. Defaults to |
Email
Bases: BaseType
A plain email address type.
It validates an email address as specified by RFC 5322.
Examples:
>>> from plateforme import BaseModel
... from plateforme.types import Email
>>> class User(BaseModel):
... email: Email
>>> user = User(email='jane.bloggs@example.com')
serialize
classmethod
serialize(
__value: Self, info: SerializationInfo | None = None
) -> Any
Return the serialized instance of the type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__value
|
Self
|
Value to serialize. |
required |
info
|
SerializationInfo | None
|
Additional information to pass to the serializer.
Defaults to |
None
|
Returns:
Type | Description |
---|---|
Any
|
A serialized instance. |
Examples:
>>> class MyType(BaseType, int):
... @classmethod
... def serialize(cls, value: Self) -> str:
... return f"Serialized {self!r}"
Note
Override and add serialization logic here, if necessary. The
serialization to be invoked is set up in the schema. For more
complex logic, you may want to override the
__get_pydantic_core_schema__
and __get_pydantic_json_schema__
methods directly.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/types/base.py
NameEmail
Bases: BaseType
, Representation
A formatted name and email address type.
It validates a name and email address combination as specified by
RFC 5322. The
type has two properties: name
and email
. If the name
is not provided,
it's inferred from the email address.
Examples:
>>> from plateforme import BaseModel
... from plateforme.types import NameEmail
>>> class User(BaseModel):
... email: NameEmail
>>> user = User(email='Jane Bloggs <jane.bloggs@example.com>')
Inialize a formatted name and email address.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/types/networks.py
serialize
classmethod
serialize(
__value: Self, info: SerializationInfo | None = None
) -> Any
Return the serialized instance of the type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__value
|
Self
|
Value to serialize. |
required |
info
|
SerializationInfo | None
|
Additional information to pass to the serializer.
Defaults to |
None
|
Returns:
Type | Description |
---|---|
Any
|
A serialized instance. |
Examples:
>>> class MyType(BaseType, int):
... @classmethod
... def serialize(cls, value: Self) -> str:
... return f"Serialized {self!r}"
Note
Override and add serialization logic here, if necessary. The
serialization to be invoked is set up in the schema. For more
complex logic, you may want to override the
__get_pydantic_core_schema__
and __get_pydantic_json_schema__
methods directly.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/types/base.py
EngineUrl
dataclass
EngineUrl(
conn: str,
/,
*,
scheme: None = None,
username: None = None,
password: None = None,
host: None = None,
port: None = None,
database: None = None,
)
EngineUrl(
conn: str | None = None,
/,
*,
scheme: str | None = None,
username: str | None = None,
password: str | None = None,
host: str | None = None,
port: int | None = None,
database: str | None = None,
)
A database engine URL type enforcing async driver selection.
Initialize a database engine URL.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/types/networks.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
username
class-attribute
instance-attribute
username: str | None = None
The username part of the URL, or omit for no username.
password
class-attribute
instance-attribute
password: str | None = None
The password part of the URL, or omit for no password.
port
class-attribute
instance-attribute
port: int | None = None
The port part of the URL, or omit for no port.
database
class-attribute
instance-attribute
database: str | None = None
The database part of the URL, or omit for no database path.
EngineMap
A database engine URL map type.
Initialize a database engine URL map.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/types/networks.py
IPvAddressFactory
Bases: BaseTypeFactory[IPvAddressFactoryAlias]
An IP address type factory.
It extends the built-in ipaddress.IPv4Address
, ipaddress.IPv6Address
,
and pydantic IPvAnyAddress
classes with additional validation and schema
methods.
IPvInterfaceFactory
Bases: BaseTypeFactory[IPvInterfaceFactoryAlias]
An IP interface type factory.
It extends the built-in ipaddress.IPv4Interface
,
ipaddress.IPv6Interface
, and pydantic IPvAnyInterface
classes with
additional validation and schema methods.
IPvNetworkFactory
Bases: BaseTypeFactory[IPvNetworkFactoryAlias]
An IP network type factory.
It extends the built-in ipaddress.IPv4Network
, ipaddress.IPv6Network
,
and pydantic IPvAnyNetwork
classes with additional validation and schema
methods.
UrlFactory
Bases: BaseTypeFactory[PydanticUrl]
A URL type factory.
It extends the pydantic Url
class with additional validation and schema
methods.
MultiHostUrlFactory
Bases: BaseTypeFactory[PydanticMultiHostUrl]
A multi host URL type factory.
It extends the pydantic MultiHostUrl
class with additional validation and
schema methods.
plateforme.core.types.numbers
This module provides utilities for managing number types within the Plateforme framework leveraging Pydantic schemas for validation and serialization, and compatibility with SQLAlchemy's data type system.
PositiveDecimal
module-attribute
A decimal that must be positive.
NegativeDecimal
module-attribute
A decimal that must be negative.
NonPositiveDecimal
module-attribute
A decimal that must be non-positive.
NonNegativeDecimal
module-attribute
A decimal that must be non-negative.
FiniteDecimal
module-attribute
A decimal that must be finite.
StrictDecimal
module-attribute
A decimal that must be strict.
NonPositiveFloat
module-attribute
A float that must be non-positive.
NonNegativeFloat
module-attribute
A float that must be non-negative.
PositiveInteger
module-attribute
An integer that must be positive.
NegativeInteger
module-attribute
An integer that must be negative.
NonPositiveInteger
module-attribute
An integer that must be non-positive.
NonNegativeInteger
module-attribute
An integer that must be non-negative.
AllowInfNan
dataclass
AllowInfNan(allow_inf_nan: bool = True)
Bases: PydanticMetadata
A field metadata class to indicate that a field should allow -inf
, inf
, and nan
.
BooleanFactory
Bases: BaseTypeFactory[bool]
A boolean type factory.
It extends the built-in bool
class with additional validation and schema
methods.
DecimalFactory
Bases: BaseTypeFactory[Decimal]
A decimal type factory.
It extends the built-in decimal.Decimal
class with additional validation
and schema methods.
FloatFactory
Bases: BaseTypeFactory[float]
A float type factory.
It extends the built-in float
class with additional validation and schema
methods.
IntegerFactory
Bases: BaseTypeFactory[int]
An integer type factory.
It extends the built-in int
class with additional validation and schema
methods.
plateforme.core.types.paths
This module provides utilities for managing path types within the Plateforme framework leveraging Pydantic schemas for validation and serialization, and compatibility with SQLAlchemy's data type system.
DirectoryPath
module-attribute
A path that must point to a directory.
NewPath
module-attribute
A path for a new file or directory that must not already exist.
PathFactory
Bases: BaseTypeFactory[Path]
A path type factory.
It extends the built-in pathlib.Path
class with additional validation and
schema methods.
plateforme.core.types.secrets
This module provides utilities for managing secret types within the Plateforme framework leveraging Pydantic schemas for validation and serialization, and compatibility with SQLAlchemy's data type system.
SecretType
Bases: BaseType
, Generic[_T]
A secret type for storing sensitive information.
Initialize the secret type with the given value.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/types/secrets.py
validate
classmethod
validate(
__value: Any, info: ValidationInfo | None = None
) -> Self
Validate value and return a new instance of the type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__value
|
Any
|
Value to validate. |
required |
info
|
ValidationInfo | None
|
Addition information to pass to the validator.
Defaults to |
None
|
Returns:
Type | Description |
---|---|
Self
|
A type initialized with validated |
Examples:
>>> class MyType(BaseType, int):
... @classmethod
... def validate(cls, value: Any) -> Self:
... if value < 0:
... raise ValueError('Value must be positive.')
... return cls(value)
>>> MyType(1)
1
>>> MyType(-1)
ValueError: Value must be positive.
Note
Override and add validation logic here, if necessary. The
validation is performed after the schema validation. For more
complex logic, you may want to override the
__get_pydantic_core_schema__
and __get_pydantic_json_schema__
methods directly.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/types/base.py
get_secret_value
serialize
classmethod
serialize(
value: Self, info: SerializationInfo | None = None
) -> Self | str
Serialize the secret value.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/types/secrets.py
SecretStr
Bases: SecretType[str]
A secret string type.
It is used for storing sensitive information that you do not want to be
visible in logging or tracebacks. When the secret value is nonempty, it is
displayed as '**********'
instead of the underlying value in calls to
repr()
and str()
. If the value is empty, it is displayed as ''
.
Examples:
>>> class User(BaseModel):
... username: str
... password: SecretStr
... user = User(username='johndoe', password='kLj4$2')
Initialize the secret type with the given value.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/types/secrets.py
validate
classmethod
validate(
__value: Any, info: ValidationInfo | None = None
) -> Self
Validate value and return a new instance of the type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__value
|
Any
|
Value to validate. |
required |
info
|
ValidationInfo | None
|
Addition information to pass to the validator.
Defaults to |
None
|
Returns:
Type | Description |
---|---|
Self
|
A type initialized with validated |
Examples:
>>> class MyType(BaseType, int):
... @classmethod
... def validate(cls, value: Any) -> Self:
... if value < 0:
... raise ValueError('Value must be positive.')
... return cls(value)
>>> MyType(1)
1
>>> MyType(-1)
ValueError: Value must be positive.
Note
Override and add validation logic here, if necessary. The
validation is performed after the schema validation. For more
complex logic, you may want to override the
__get_pydantic_core_schema__
and __get_pydantic_json_schema__
methods directly.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/types/base.py
serialize
classmethod
serialize(
value: Self, info: SerializationInfo | None = None
) -> Self | str
Serialize the secret value.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/types/secrets.py
SecretBytes
Bases: SecretType[bytes]
A secret bytes type.
It is used for storing sensitive information that you do not want to be
visible in logging or tracebacks. When the secret value is nonempty, it is
displayed as b'**********'
instead of the underlying value in calls to
repr()
and str()
. If the value is empty, it is displayed as b''
.
Examples:
>>> class User(BaseModel):
... username: str
... password: SecretBytes
... user = User(username='johndoe', password=b'kLj4$2')
>>> print((SecretBytes(b'password'), SecretBytes(b'')))
(SecretBytes(b'**********'), SecretBytes(b''))
Initialize the secret type with the given value.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/types/secrets.py
validate
classmethod
validate(
__value: Any, info: ValidationInfo | None = None
) -> Self
Validate value and return a new instance of the type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__value
|
Any
|
Value to validate. |
required |
info
|
ValidationInfo | None
|
Addition information to pass to the validator.
Defaults to |
None
|
Returns:
Type | Description |
---|---|
Self
|
A type initialized with validated |
Examples:
>>> class MyType(BaseType, int):
... @classmethod
... def validate(cls, value: Any) -> Self:
... if value < 0:
... raise ValueError('Value must be positive.')
... return cls(value)
>>> MyType(1)
1
>>> MyType(-1)
ValueError: Value must be positive.
Note
Override and add validation logic here, if necessary. The
validation is performed after the schema validation. For more
complex logic, you may want to override the
__get_pydantic_core_schema__
and __get_pydantic_json_schema__
methods directly.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/types/base.py
serialize
classmethod
serialize(
value: Self, info: SerializationInfo | None = None
) -> Self | str
Serialize the secret value.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/types/secrets.py
plateforme.core.types.strings
This module provides utilities for managing string types within the Plateforme framework leveraging Pydantic schemas for validation and serialization, and compatibility with SQLAlchemy's data type system.
StrictString
module-attribute
A string that must be validated strictly.
StringFactory
Bases: BaseTypeFactory[str]
A string type factory.
It extends the built-in str
class with additional validation and schema
methods.
plateforme.core.types.uuid
This module provides utilities for managing UUID types within the Plateforme framework leveraging Pydantic schemas for validation and serialization, and compatibility with SQLAlchemy's data type system.