Installation is as simple as:
pip install pydantic
pydantic has no required dependencies except Python 3.7, 3.8, 3.9, 3.10 or 3.11 and
If you've got Python 3.7+ and
pip installed, you're good to go.
conda install pydantic -c conda-forge
Compiled with Cython¶
pydantic can optionally be compiled with cython which should give a 30-50% performance improvement.
pip install provides optimized binaries via PyPI for Linux, MacOS and 64bit Windows.
If you're installing manually, install
cython 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:
SKIP_CYTHON=1 pip install --no-binary pydantic pydantic
pydantic is repeated here intentionally,
--no-binary pydantic tells
pip you want no binaries for pydantic,
pip which package to install.
CFLAGS="-Os -g0 -s" pip install \ --no-binary pydantic \ --global-option=build_ext \ pydantic
pydantic has two optional dependencies:
- If you require email validation you can add email-validator
- dotenv file support with
To install these along with pydantic:
pip install pydantic[email] # or pip install pydantic[dotenv] # or just pip install pydantic[email,dotenv]
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: