Skip to content
You're viewing docs for v2.2. See the latest version →

Network Types

The networks module contains types for common network-related fields.

UrlConstraints

Bases: PydanticMetadata

Url constraints.

Attributes

max_length

Type: int | None Default: None

allowed_schemes

Type: list[str] | None Default: None

host_required

Type: bool | None Default: None

default_host

Type: str | None Default: None

default_port

Type: int | None Default: None

default_path

Type: str | None Default: None


EmailStr

Validate email addresses.


NameEmail

Bases: Representation

Validate a name and email address combination.

Attributes

name

Default: name

email

Default: email


IPvAnyAddress

Validate an IPv4 or IPv6 address.

Methods

new

def __new__(cls, value: Any) -> IPv4Address | IPv6Address

Validate an IPv4 or IPv6 address.

Returns

IPv4Address | IPv6Address


IPvAnyInterface

Validate an IPv4 or IPv6 interface.

Methods

new

def __new__(cls, value: NetworkType) -> IPv4Interface | IPv6Interface

Validate an IPv4 or IPv6 interface.

Returns

IPv4Interface | IPv6Interface


IPvAnyNetwork

Validate an IPv4 or IPv6 network.

Methods

new

def __new__(cls, value: NetworkType) -> IPv4Network | IPv6Network

Validate an IPv4 or IPv6 network.

Returns

IPv4Network | IPv6Network


getattr_migration

def getattr_migration(module: str) -> Callable[[str], Any]

Implement PEP 562 for objects that were either moved or removed on the migration to V2.

Returns

Callable[[str], Any] — A callable that will raise an error if the object is not found.

Parameters

module : str

The module name.


import_email_validator

def import_email_validator() -> None

Returns

None


validate_email

def validate_email(value: str) -> tuple[str, str]

Email address validation using https://pypi.org/project/email-validator/.

Returns

tuple[str, str]


JsonSchemaValue

A type alias for a JSON schema value. This is a dictionary of string keys to arbitrary values.

Default: Dict[str, Any]

NetworkType

Type: TypeAlias Default: 'str | bytes | int | tuple[str | bytes | int, str | int]'

AnyUrl

Base type for all URLs.

Default: Url

AnyHttpUrl

A type that will accept any http or https URL.

Default: Annotated[Url, UrlConstraints(allowed_schemes=['http', 'https'])]

HttpUrl

A type that will accept any http or https URL with a max length of 2083 characters.

Default: Annotated[Url, UrlConstraints(max_length=2083, allowed_schemes=['http', 'https'])]

FileUrl

A type that will accept any file URL.

Default: Annotated[Url, UrlConstraints(allowed_schemes=['file'])]

PostgresDsn

A type that will accept any Postgres DSN.

Default: Annotated[MultiHostUrl, UrlConstraints(host_required=True, allowed_schemes=['postgres', 'postgresql', 'postgresql+asyncpg', 'postgresql+pg8000', 'postgresql+psycopg', 'postgresql+psycopg2', 'postgresql+psycopg2cffi', 'postgresql+py-postgresql', 'postgresql+pygresql'])]

CockroachDsn

A type that will accept any Cockroach DSN.

Default: Annotated[Url, UrlConstraints(host_required=True, allowed_schemes=['cockroachdb', 'cockroachdb+psycopg2', 'cockroachdb+asyncpg'])]

AmqpDsn

A type that will accept any AMQP DSN.

Default: Annotated[Url, UrlConstraints(allowed_schemes=['amqp', 'amqps'])]

RedisDsn

A type that will accept any Redis DSN.

Default: Annotated[Url, UrlConstraints(allowed_schemes=['redis', 'rediss'], default_host='localhost', default_port=6379, default_path='/0')]

MongoDsn

A type that will accept any MongoDB DSN.

Default: Annotated[MultiHostUrl, UrlConstraints(allowed_schemes=['mongodb', 'mongodb+srv'], default_port=27017)]

KafkaDsn

A type that will accept any Kafka DSN.

Default: Annotated[Url, UrlConstraints(allowed_schemes=['kafka'], default_host='localhost', default_port=9092)]

MySQLDsn

A type that will accept any MySQL DSN.

Default: Annotated[Url, UrlConstraints(allowed_schemes=['mysql', 'mysql+mysqlconnector', 'mysql+aiomysql', 'mysql+asyncmy', 'mysql+mysqldb', 'mysql+pymysql', 'mysql+cymysql', 'mysql+pyodbc'], default_port=3306)]

MariaDBDsn

A type that will accept any MariaDB DSN.

Default: Annotated[Url, UrlConstraints(allowed_schemes=['mariadb', 'mariadb+mariadbconnector', 'mariadb+pymysql'], default_port=3306)]

pretty_email_regex

Default: _build_pretty_email_regex()