Skip to main content
Info:

Python bindings for libmongocrypt. See GitHub for the latest source.

Author:

Shane Harvey

About

Python wrapper library for libmongocrypt that supports client side encryption in drivers. PyMongoCrypt uses cffi and cryptography.

PyMongoCrypt supports Python 3.8+ and PyPy3.9+.

Support / Feedback

For issues with, questions about, or feedback for PyMongoCrypt, please look into our support channels. Please do not email any of the PyMongoCrypt developers directly with issues or questions - you’re more likely to get an answer on the mongodb-user list on Google Groups.

Bugs / Feature Requests

Think you’ve found a bug? Want to see a new feature in PyMongoCrypt? Please open a case in our issue management tool, JIRA:

Bug reports in JIRA for all driver projects (i.e. PYTHON, CSHARP) and the Core Server (i.e. SERVER) project are public.

How To Ask For Help

Please include all of the following information when opening an issue:

  • Detailed steps to reproduce the problem, including full traceback, if possible.

  • The exact python version used, with patch level:

    $ python -c "import sys; print(sys.version)"
  • The exact version of PyMongoCrypt used:

    $ python -c "import pymongocrypt; print(pymongocrypt.__version__)"
  • The exact version of libbmongocrypt used by PyMongoCrypt:

    $ python -c "import pymongocrypt; print(pymongocrypt.libmongocrypt_version())"
  • The exact version of PyMongo used (if applicable), with patch level:

    $ python -c "import pymongo; print(pymongo.version); print(pymongo.has_c())"
  • The operating system and version (e.g. Windows 7, OSX 10.8, …)

  • Web framework or asynchronous network library used, if any, with version (e.g. Django 1.7, mod_wsgi 4.3.0, gevent 1.0.1, Tornado 4.0.2, …)

Security Vulnerabilities

If you’ve identified a security vulnerability in a driver or any other MongoDB project, please report it according to the instructions here.

Installation

PyMongoCrypt can be installed with pip:

$ python -m pip install pymongocrypt
$ python -c "import pymongocrypt; print(pymongocrypt.libmongocrypt_version())"
1.9.0

PyMongoCrypt ships wheels for macOS, Windows, and manylinux2010 that include an embedded libmongocrypt build.

Installing from wheels on Linux requires pip 19 or later because it adds support for manylinux2010 wheels. Older versions of pip will attempt installation using the pymongocrypt-X.Y.tar.gz source distribution which requires the extra step of downloading and installing libmongocrypt as described below. Users can upgrade to pip 19 by running:

$ python -m pip install --upgrade 'pip>=19'

Installing from source

Installing from source (or the pymongocrypt-X.Y.tar.gz source distribution, or pip < 19 on Linux) requires an extra step of installing libmongocrypt. First, install PyMongoCrypt from source:

$ git clone git@github.com:mongodb/libmongocrypt.git
$ python -m pip install ./libmongocrypt/bindings/python

Next, install libmongocrypt:

Installing libmongocrypt

libmongocrypt is continuously built and published on evergreen.

Follow the instructions here to install the correct libmongocrypt build for your operating system.

Alternatively, the latest tarballs containing libmongocrypt binaries are published here. Download and extract the correct libmongocrypt.tar.gz for your operating system and set PYMONGOCRYPT_LIB to the path to your operating system’s libmongocrypt.so file.

For example:: macOS:

$ # Set PYMONGOCRYPT_LIB for macOS:
$ export PYMONGOCRYPT_LIB=$(pwd)/libmongocrypt/lib/libmongocrypt.dylib
$ python -c "import pymongocrypt; print(pymongocrypt.libmongocrypt_version())"
1.18.0

Windows:

$ # Set PYMONGOCRYPT_LIB for Windows:
$ chmod +x $(pwd)/libmongocrypt-all/windows-test/bin/mongocrypt.dll
$ export PYMONGOCRYPT_LIB=$(pwd)/libmongocrypt/bin/mongocrypt.dll
$ python -c "import pymongocrypt; print(pymongocrypt.libmongocrypt_version())"
1.18.0

Linux: set the libmongocrypt build for your platform, for example for Ubuntu 22.04 x86_64:

$ # Set PYMONGOCRYPT_LIB for Ubuntu 22.04 x86_64:
$ export PYMONGOCRYPT_LIB=$(pwd)/libmongocrypt/lib64/libmongocrypt.so
$ python -c "import pymongocrypt; print(pymongocrypt.libmongocrypt_version())"
1.18.0
$ # Check that native crypto is enabled for better performance:
$ python -c 'from pymongocrypt.binding import lib;print(lib.mongocrypt_is_crypto_available())'
True

Note if your Linux platform is not available, the generic linux-x86_64-glibc_2_7-nocrypto build should still be compatible however the “nocrypto” build will result in lower performance for encryption and decryption:

$ # Set PYMONGOCRYPT_LIB for linux-x86_64-glibc_2_7-nocrypto:
$ export PYMONGOCRYPT_LIB=$(pwd)/libmongocrypt/lib64/libmongocrypt.so
$ python -c "import pymongocrypt; print(pymongocrypt.libmongocrypt_version())"
1.18.0
$ python -c 'from pymongocrypt.binding import lib;print(lib.mongocrypt_is_crypto_available())'
False

Dependencies

PyMongoCrypt supports Python 3.8+ and PyPy3.9+.

PyMongoCrypt requires cffi and cryptography.

If not installed using one of the official wheels, PyMongoCrypt also requires libmongocrypt to be installed on your system. If libmongocrypt is not installed you will see an error like this:

>>> import pymongocrypt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pymongocrypt/__init__.py", line 15, in <module>
    from pymongocrypt.binding import libmongocrypt_version, lib
  File "pymongocrypt/binding.py", line 803, in <module>
    lib = ffi.dlopen(os.environ.get('PYMONGOCRYPT_LIB', 'mongocrypt'))
  File "/.../lib/python3.8/site-packages/cffi/api.py", line 146, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "/.../lib/python3.8/site-packages/cffi/api.py", line 828, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File "/.../lib/python3.8/site-packages/cffi/api.py", line 823, in _load_backend_lib
    raise OSError(msg)
OSError: ctypes.util.find_library() did not manage to locate a library called 'mongocrypt'

Use the PYMONGOCRYPT_LIB environment variable to load a locally installed libmongocrypt build without relying on platform specific library path environment variables, like LD_LIBRARY_PATH. For example:

$ export PYMONGOCRYPT_LIB='/path/to/libmongocrypt.so'
$ python -c "import pymongocrypt; print(pymongocrypt.libmongocrypt_version())"
1.9.0

Testing

The easiest way to run the tests is to run python setup.py test in the root of the distribution.

Release files for pymongocrypt 1.19.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymongocrypt 1.19.0
File Size Uploaded
pymongocrypt-1.19.0.tar.gz 69.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pymongocrypt 1.19.0
File
pymongocrypt-1.19.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
pymongocrypt-1.19.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details
pymongocrypt-1.19.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64, Linux glibc 2.28+ ARM64 Details
pymongocrypt-1.19.0-py3-none-macosx_11_0_universal2.whl Python 3 none macOS 11.0+ universal2 (ARM64, x86-64) Details

Total release size:14.4 MB

Release files / pymongocrypt-1.19.0.tar.gz

Download URL pymongocrypt-1.19.0.tar.gz
Size 69.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9e1ce65161fb1166f73c4dc98e42047b5a2314eb14b7140aba06c82be1f9866d
BLAKE2b-256 checksum
How to use checksums
020185c5ec690e272d5a5bf82a0390f40e8bbdaf6c0d96d7132d711f6e9e2076
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.

Transparency log

Release files / pymongocrypt-1.19.0-py3-none-win_amd64.whl

Download URL pymongocrypt-1.19.0-py3-none-win_amd64.whl
Size 1.6 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
aa80c0cf3df2923a40c41b48d219212afbd18ee7e6e77e7b1bc5e8dd6065534e
BLAKE2b-256 checksum
How to use checksums
e8f109b0da5b02eab911aa87c477bc74e56bb7f662a97e23aa0c76cfd0744496
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.

Transparency log

Release files / pymongocrypt-1.19.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pymongocrypt-1.19.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 3.8 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
3c0c551a8dee4ce790a2b676e37ade34536b2942fd0c90c591732fffcccc40c1
BLAKE2b-256 checksum
How to use checksums
5481bedcac784e8dfa8f0fb1c8aca649a7d1e57ac45e6b01b5f239f53bae4364
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.

Transparency log

Release files / pymongocrypt-1.19.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl

Download URL pymongocrypt-1.19.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl
Size 4.1 MB
Tags Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
6caf4d61a55e59fceeb573d06b96ab181f71c2a4e8e7cfa7ba276c4f87b850fd
BLAKE2b-256 checksum
How to use checksums
baec04188792660bb68d7b6310de87e97072512c8ad5a41762d9aa0c49e85b9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.

Transparency log

Release files / pymongocrypt-1.19.0-py3-none-macosx_11_0_universal2.whl

Download URL pymongocrypt-1.19.0-py3-none-macosx_11_0_universal2.whl
Size 4.7 MB
Tags Python 3 macOS 11.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
7f831cb5e9c5bbe96199c748054aba3b9489c9bb2c5887a13c6922f1d2c64955
BLAKE2b-256 checksum
How to use checksums
4a5a5fe43fccdedb4cebaf8130e1152eca765460098f27fac11ebaa0fc71053f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.19.0 This release

5 release files

1.18.0

5 release files

1.17.0

5 release files

1.15.1

5 release files

1.14.0

5 release files

1.10.0

5 release files

1.9.2

6 release files

1.9.1

6 release files

1.8.0

6 release files

1.7.0

6 release files

1.6.1

6 release files

1.6.0

6 release files

1.5.2

6 release files

1.5.1

6 release files

1.5.0

6 release files

1.4.1

6 release files

1.4.0

6 release files

1.3.1

6 release files

1.3.0

7 release files

1.2.0

5 release files

1.1.2

5 release files

1.1.1

5 release files

1.1.0

4 release files

1.0.1

4 release files

1.0.0

4 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page