url_schema
Returns a schema that matches a URL value, e.g.:
from pydantic_core import SchemaValidator, core_schema
schema = core_schema.url_schema()
v = SchemaValidator(schema)
print(v.validate_python('https://example.com'))
# > https://example.com/
def url_schema(
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,
strict: bool | None = None,
ref: str | None = None,
metadata: dict[str, Any] | None = None,
serialization: SerSchema | None = None
) - > UrlSchema
Returns a schema that matches a URL value.
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 |
| strict | `bool | None` = None |
| ref | `str | None` = None |
| metadata | `dict[str, Any] | None` = None |
| serialization | `SerSchema | None` = None |
Returns
| Type | Description |
|---|---|
UrlSchema | A dictionary-based schema configuration used by pydantic-core to validate and parse URL strings. |