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

The maximum length of the url. Defaults to None.

Type: int | None

allowed_schemes

The allowed schemes. Defaults to None.

Type: list[str] | None

host_required

Whether the host is required. Defaults to None.

Type: bool | None

default_host

The default host. Defaults to None.

Type: str | None

default_port

The default port. Defaults to None.

Type: int | None

default_path

The default path. Defaults to None.

Type: str | None

EmailStr

Validate email addresses.

NameEmail

Bases: Representation

Validate a name and email address combination.

Attributes

name

The name.

email

The email address.

IPvAnyAddress

Validate an IPv4 or IPv6 address.

IPvAnyInterface

Validate an IPv4 or IPv6 interface.

IPvAnyNetwork

Validate an IPv4 or IPv6 network.

validate_email

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

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

Returns

tuple[str, str]

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)]