Network Types
The networks module contains types for common network-related fields.
AnyHttpUrl
module-attribute
¶
AnyHttpUrl = Annotated[
Url, UrlConstraints(allowed_schemes=["http", "https"])
]
A type that will accept any http or https URL.
HttpUrl
module-attribute
¶
HttpUrl = Annotated[
Url,
UrlConstraints(
max_length=2083, allowed_schemes=["http", "https"]
),
]
A type that will accept any http or https URL with a max length of 2083 characters.
FileUrl
module-attribute
¶
FileUrl = Annotated[
Url, UrlConstraints(allowed_schemes=["file"])
]
A type that will accept any file URL.
PostgresDsn
module-attribute
¶
PostgresDsn = 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",
],
),
]
A type that will accept any Postgres DSN.
CockroachDsn
module-attribute
¶
CockroachDsn = Annotated[
Url,
UrlConstraints(
host_required=True,
allowed_schemes=[
"cockroachdb",
"cockroachdb+psycopg2",
"cockroachdb+asyncpg",
],
),
]
A type that will accept any Cockroach DSN.
AmqpDsn
module-attribute
¶
AmqpDsn = Annotated[
Url, UrlConstraints(allowed_schemes=["amqp", "amqps"])
]
A type that will accept any AMQP DSN.
RedisDsn
module-attribute
¶
RedisDsn = Annotated[
Url,
UrlConstraints(
allowed_schemes=["redis", "rediss"],
default_host="localhost",
default_port=6379,
default_path="/0",
),
]
A type that will accept any Redis DSN.
MongoDsn
module-attribute
¶
MongoDsn = Annotated[
MultiHostUrl,
UrlConstraints(
allowed_schemes=["mongodb", "mongodb+srv"],
default_port=27017,
),
]
A type that will accept any MongoDB DSN.
KafkaDsn
module-attribute
¶
KafkaDsn = Annotated[
Url,
UrlConstraints(
allowed_schemes=["kafka"],
default_host="localhost",
default_port=9092,
),
]
A type that will accept any Kafka DSN.
MySQLDsn
module-attribute
¶
MySQLDsn = Annotated[
Url,
UrlConstraints(
allowed_schemes=[
"mysql",
"mysql+mysqlconnector",
"mysql+aiomysql",
"mysql+asyncmy",
"mysql+mysqldb",
"mysql+pymysql",
"mysql+cymysql",
"mysql+pyodbc",
],
default_port=3306,
),
]
A type that will accept any MySQL DSN.
MariaDBDsn
module-attribute
¶
MariaDBDsn = Annotated[
Url,
UrlConstraints(
allowed_schemes=[
"mariadb",
"mariadb+mariadbconnector",
"mariadb+pymysql",
],
default_port=3306,
),
]
A type that will accept any MariaDB DSN.
UrlConstraints
dataclass
¶
Bases: _fields.PydanticMetadata
Url constraints.
Attributes:
Name | Type | Description |
---|---|---|
max_length |
int | None
|
The maximum length of the url. Defaults to |
allowed_schemes |
list[str] | None
|
The allowed schemes. Defaults to |
host_required |
bool | None
|
Whether the host is required. Defaults to |
default_host |
str | None
|
The default host. Defaults to |
default_port |
int | None
|
The default port. Defaults to |
default_path |
str | None
|
The default path. Defaults to |
EmailStr ¶
Validate email addresses.
Example
from pydantic import BaseModel, EmailStr
class Model(BaseModel):
email: EmailStr
print(Model(email='[email protected]'))
#> email='[email protected]'
NameEmail ¶
NameEmail(name, email)
Bases: _repr.Representation
Validate a name and email address combination.
Example
from pydantic import BaseModel, NameEmail
class User(BaseModel):
email: NameEmail
print(User(email='John Doe <[email protected]>'))
#> email=NameEmail(name='John Doe', email='[email protected]')
Attributes:
Name | Type | Description |
---|---|---|
name |
The name. |
|
email |
The email address. |
Source code in pydantic/networks.py
227 228 229 |
|
IPvAnyAddress ¶
Validate an IPv4 or IPv6 address.
IPvAnyInterface ¶
Validate an IPv4 or IPv6 interface.
IPvAnyNetwork ¶
Validate an IPv4 or IPv6 network.
validate_email ¶
validate_email(value)
Email address validation using https://pypi.org/project/email-validator/.
Note
Note that:
- Raw IP address (literal) domain parts are not allowed.
- "John Doe local_part@domain.com" style "pretty" email addresses are processed.
- Spaces are striped from the beginning and end of addresses, but no error is raised.
Source code in pydantic/networks.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
|