UrlConstraints
This class defines validation and formatting constraints for URL types, such as maximum length, allowed schemes, and host requirements. It provides a mechanism to apply these constraints to Pydantic core schemas, ensuring that URL instances adhere to specific structural and security rules. The class also supports default values for hosts, ports, and paths while managing how empty paths are preserved.
Attributes
| Attribute | Type | Description |
|---|---|---|
| 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 |
| preserve_empty_path | `bool | None` = None |
Constructor
Signature
def 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,
preserve_empty_path: bool | None = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| 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 |
| preserve_empty_path | `bool | None` = None |
Methods
defined_constraints()
@classmethod
def defined_constraints() - > dict[str, Any]
Fetch a key / value mapping of constraints to values that are not None. Used for core schema updates.
Returns
| Type | Description |
|---|---|
dict[str, Any] | A dictionary containing only the active URL constraints and their configured values |