Skip to content
You're viewing docs for v1.10. See the latest version →

Install

Installation is as simple as:

Terminal
pip install 'pydantic<2'

pydantic has no required dependencies except Python 3.7, 3.8, 3.9, 3.10 or 3.11 and typing-extensions. If you’ve got Python 3.7+ and pip installed, you’re good to go.

Pydantic is also available on conda under the conda-forge channel:

Terminal
conda install 'pydantic<2' -c conda-forge

Compiled with Cython

pydantic can optionally be compiled with cython which should give a 30-50% performance improvement.

By default pip install provides optimized binaries via PyPI for Linux, MacOS and 64bit Windows.

If you’re installing manually, install cython<3 (Pydantic 1.x is incompatible with Cython v3 and above) before installing pydantic and compilation should happen automatically.

To test if pydantic is compiled run:

import pydantic
print('compiled:', pydantic.compiled)

Performance vs package size trade-off

Compiled binaries can increase the size of your Python environment. If for some reason you want to reduce the size of your pydantic installation you can avoid installing any binaries using the pip --no-binary option. Make sure Cython is not in your environment, or that you have the SKIP_CYTHON environment variable set to avoid re-compiling pydantic libraries:

Terminal
SKIP_CYTHON=1 pip install --no-binary pydantic pydantic<2

Alternatively, you can re-compile pydantic with custom build options, this would require having the Cython package installed before re-compiling pydantic with:

Terminal
CFLAGS="-Os -g0 -s" pip install \
  --no-binary pydantic \
  --global-option=build_ext \
  pydantic<2

Optional dependencies

pydantic has two optional dependencies:

To install these along with pydantic:

Terminal
pip install 'pydantic[email]<2'
# or
pip install 'pydantic[dotenv]<2'
# or just
pip install 'pydantic[email,dotenv]<2'

Of course, you can also install these requirements manually with pip install email-validator and/or pip install python-dotenv.

Install from repository

And if you prefer to install pydantic directly from the repository:

Terminal
pip install git+https://github.com/pydantic/[email protected]#egg=pydantic
# or with extras
pip install git+https://github.com/pydantic/[email protected]#egg=pydantic[email,dotenv]