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

pydantic.networks

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

EmailStr

Validate email addresses.

IPvAnyAddress

Validate an IPv4 or IPv6 address.

IPvAnyInterface

Validate an IPv4 or IPv6 interface.

IPvAnyNetwork

Validate an IPv4 or IPv6 network.

NameEmail

Bases: Representation

Validate a name and email address combination.

Attributes

name

The name.

email

The email address.

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

validate_email

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

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

Returns

tuple[str, str]

AmqpDsn

A type that will accept any AMQP DSN.

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

AnyHttpUrl

A type that will accept any http or https URL.

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

AnyUrl

Base type for all URLs.

Default: Url

CockroachDsn

A type that will accept any Cockroach DSN.

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

FileUrl

A type that will accept any file URL.

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

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

KafkaDsn

A type that will accept any Kafka DSN.

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

MariaDBDsn

A type that will accept any MariaDB DSN.

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

MongoDsn

A type that will accept any MongoDB DSN.

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

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

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

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