Pydantic Extra Types
raw JSON → 2.11.1 verified Tue May 12 auth: no python install: verified quickstart: stale
Pydantic Extra Types extends Pydantic with specialized data types for various common use cases, such as `Color`, `PhoneNumber`, `Country`, `ULID`, and `SemanticVersion`. It is currently at version 2.11.1 and receives frequent updates, often with monthly or bi-monthly patch and minor releases, adding new types and features.
pip install pydantic-extra-types Common errors
error ModuleNotFoundError: No module named 'pydantic_extra_types' ↓
cause The `pydantic-extra-types` library has not been installed in your Python environment.
fix
pip install pydantic-extra-types
error ImportError: cannot import name 'Color' from 'pydantic.color' ↓
cause In Pydantic V2, types like `Color` and `PaymentCardNumber` were moved from the main `pydantic` package to `pydantic-extra-types`.
fix
Update your import statement from
from pydantic import Color to from pydantic_extra_types.color import Color (or similar for other moved types). error PydanticCustomError: 'color_error', 'value is not a valid color: value must be a tuple, list or string' ↓
cause The input value provided for a `pydantic-extra-types` field, such as `Color`, does not conform to its expected format or validation rules.
fix
Ensure the input value matches the required format for the specific extra type (e.g., a valid color string like '#FFF' or 'red', or an RGB/RGBA tuple).
error ModuleNotFoundError: No module named 'phonenumbers' ↓
cause Specific types within `pydantic-extra-types`, such as `PhoneNumber` and `ULID`, have additional external dependencies (`phonenumbers` and `python-ulid` respectively) that must be installed separately.
fix
Install the missing optional dependency for the specific extra type you are using. For
PhoneNumber, run pip install phonenumbers. For ULID, run pip install python-ulid. Warnings
breaking When migrating from Pydantic V1 to V2, types like `Color` and `PaymentCardNumber` were moved out of the main `pydantic` library into `pydantic-extra-types`. Direct imports from `pydantic.color` or `pydantic.payment` will no longer work. ↓
fix Update your imports from `from pydantic import Color` to `from pydantic_extra_types.color import Color`, and ensure `pydantic-extra-types` is installed.
deprecated The previous `semver` module, which relied on the external `python-semver` package, has been deprecated in `v2.10.0`. It was replaced by an internal `SemanticVersion` type. ↓
fix Migrate imports from `from pydantic_extra_types.semver import SemVer` (or similar) to `from pydantic_extra_types.semantic_version import SemanticVersion`.
gotcha Many specialized types within `pydantic-extra-types` require additional optional dependencies to be installed. For example, `PhoneNumber` requires `phonenumbers`, `Country` types require `pycountry`, and `PendulumDuration` requires `pendulum`. Simply installing `pydantic-extra-types` without specifying extras will lead to `ModuleNotFoundError` when these types are used. ↓
fix Install `pydantic-extra-types` with the necessary extras, e.g., `pip install "pydantic-extra-types[phonenumbers,pycountry]"` or `pip install "pydantic-extra-types[all]"`.
gotcha Most types are not directly available from the top-level `pydantic_extra_types` package but are nested within submodules. For instance, `Color` is in `pydantic_extra_types.color`, and `PhoneNumber` is in `pydantic_extra_types.phone_numbers`. Attempting `from pydantic_extra_types import Color` will result in an `ImportError`. ↓
fix Always import types from their specific submodules, e.g., `from pydantic_extra_types.color import Color`.
Install
pip install "pydantic-extra-types[all]" pip install "pydantic-extra-types[phonenumbers,pendulum,pycountry]" Install compatibility verified last tested: 2026-05-12
python os / libc variant status wheel install import disk
3.10 alpine (musl) all sdist - 0.21s 153.2M
3.10 alpine (musl) all - - 0.23s 155.7M
3.10 alpine (musl) phonenumbers,pendulum,pycountry wheel - 0.23s 140.5M
3.10 alpine (musl) phonenumbers,pendulum,pycountry - - 0.23s 139.6M
3.10 alpine (musl) pydantic-extra-types wheel - 0.22s 28.5M
3.10 alpine (musl) pydantic-extra-types - - 0.23s 28.5M
3.10 slim (glibc) all wheel 9.5s 0.15s 153M
3.10 slim (glibc) all - - 0.15s 155M
3.10 slim (glibc) phonenumbers,pendulum,pycountry wheel 7.6s 0.17s 140M
3.10 slim (glibc) phonenumbers,pendulum,pycountry - - 0.15s 139M
3.10 slim (glibc) pydantic-extra-types wheel 3.7s 0.15s 28M
3.10 slim (glibc) pydantic-extra-types - - 0.18s 28M
3.11 alpine (musl) all sdist - 0.36s 122.5M
3.11 alpine (musl) all - - 0.39s 125.8M
3.11 alpine (musl) phonenumbers,pendulum,pycountry wheel - 0.36s 108.3M
3.11 alpine (musl) phonenumbers,pendulum,pycountry - - 0.42s 107.9M
3.11 alpine (musl) pydantic-extra-types wheel - 0.37s 31.2M
3.11 alpine (musl) pydantic-extra-types - - 0.39s 31.1M
3.11 slim (glibc) all wheel 8.2s 0.31s 123M
3.11 slim (glibc) all - - 0.30s 126M
3.11 slim (glibc) phonenumbers,pendulum,pycountry wheel 6.7s 0.31s 107M
3.11 slim (glibc) phonenumbers,pendulum,pycountry - - 0.29s 107M
3.11 slim (glibc) pydantic-extra-types wheel 2.9s 0.32s 31M
3.11 slim (glibc) pydantic-extra-types - - 0.32s 31M
3.12 alpine (musl) all sdist - 0.58s 111.4M
3.12 alpine (musl) all - - 0.62s 114.6M
3.12 alpine (musl) phonenumbers,pendulum,pycountry wheel - 0.58s 97.4M
3.12 alpine (musl) phonenumbers,pendulum,pycountry - - 0.61s 97.0M
3.12 alpine (musl) pydantic-extra-types wheel - 0.57s 22.9M
3.12 alpine (musl) pydantic-extra-types - - 0.61s 22.8M
3.12 slim (glibc) all wheel 8.0s 0.60s 113M
3.12 slim (glibc) all - - 0.57s 116M
3.12 slim (glibc) phonenumbers,pendulum,pycountry wheel 6.7s 0.56s 97M
3.12 slim (glibc) phonenumbers,pendulum,pycountry - - 0.57s 96M
3.12 slim (glibc) pydantic-extra-types wheel 2.5s 0.60s 23M
3.12 slim (glibc) pydantic-extra-types - - 0.73s 22M
3.13 alpine (musl) all sdist - 0.18s 111.1M
3.13 alpine (musl) all - - 0.20s 114.2M
3.13 alpine (musl) phonenumbers,pendulum,pycountry wheel - 0.19s 97.2M
3.13 alpine (musl) phonenumbers,pendulum,pycountry - - 0.20s 96.6M
3.13 alpine (musl) pydantic-extra-types wheel - 0.19s 22.6M
3.13 alpine (musl) pydantic-extra-types - - 0.20s 22.4M
3.13 slim (glibc) all wheel 8.0s 0.19s 114M
3.13 slim (glibc) all - - 0.20s 116M
3.13 slim (glibc) phonenumbers,pendulum,pycountry wheel 6.8s 0.18s 96M
3.13 slim (glibc) phonenumbers,pendulum,pycountry - - 0.21s 96M
3.13 slim (glibc) pydantic-extra-types wheel 2.7s 0.20s 22M
3.13 slim (glibc) pydantic-extra-types - - 0.23s 22M
3.9 alpine (musl) all sdist - 0.21s 98.6M
3.9 alpine (musl) all - - 0.22s 101.7M
3.9 alpine (musl) phonenumbers,pendulum,pycountry wheel - 0.21s 86.1M
3.9 alpine (musl) phonenumbers,pendulum,pycountry - - 0.22s 85.8M
3.9 alpine (musl) pydantic-extra-types wheel - 0.22s 28.0M
3.9 alpine (musl) pydantic-extra-types - - 0.22s 28.0M
3.9 slim (glibc) all wheel 10.7s 0.20s 98M
3.9 slim (glibc) all - - 0.19s 101M
3.9 slim (glibc) phonenumbers,pendulum,pycountry wheel 9.0s 0.20s 85M
3.9 slim (glibc) phonenumbers,pendulum,pycountry - - 0.19s 85M
3.9 slim (glibc) pydantic-extra-types wheel 4.3s 0.23s 28M
3.9 slim (glibc) pydantic-extra-types - - 0.19s 28M
Imports
- Color wrong
from pydantic import Colorcorrectfrom pydantic_extra_types.color import Color - PhoneNumber
from pydantic_extra_types.phone_numbers import PhoneNumber - CountryAlpha2
from pydantic_extra_types.country import CountryAlpha2 - SemanticVersion wrong
from pydantic_extra_types.semver import SemanticVersioncorrectfrom pydantic_extra_types.semantic_version import SemanticVersion
Quickstart stale last tested: 2026-04-24
from pydantic import BaseModel, ValidationError
from pydantic_extra_types.phone_numbers import PhoneNumber
class Contact(BaseModel):
name: str
phone: PhoneNumber
try:
# Valid phone number
c = Contact(name='Alice', phone='+1 650-253-0000')
print(c.phone.e164) # Outputs: +16502530000 (formatted by default as RFC3966 or E164, depending on version/config)
# Invalid phone number
Contact(name='Bob', phone='not-a-phone-number')
except ValidationError as e:
print(f"Validation error: {e}")