Package: pymongocrypt
Info:Python bindings for libmongocrypt. SeeGitHubfor the latest source.Author:Shane HarveyAboutPython wrapper library for libmongocrypt that supports client side encryption
in drivers. PyMongoCrypt usescffiandcryptography.PyMongoCrypt supports Python 3.7+ and PyPy3.7+.Support / FeedbackFor issues with, questions about, or feedback for PyMongoCrypt, please look into
oursupport channels. Please
do not email any of the PyMongoCrypt developers directly with issues or
questions - you’re more likely to get an answer on themongodb-userlist on Google Groups.Bugs / Feature RequestsThink you’ve found a bug? Want to see a new feature in PyMongoCrypt?
Please open a case in our issue management tool, JIRA:Create an account and login.Navigate tothe PYTHON project.ClickCreate Issue- Please provide as much information as possible about the issue type and how to reproduce it.Bug reports in JIRA for all driver projects (i.e. PYTHON, CSHARP, JAVA) and the
Core Server (i.e. SERVER) project arepublic.How To Ask For HelpPlease 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 VulnerabilitiesIf you’ve identified a security vulnerability in a driver or any other
MongoDB project, please report it according to theinstructions here.InstallationPyMongoCrypt can be installed withpip:$ python -m pip install pymongocrypt
$ python -c "import pymongocrypt; print(pymongocrypt.libmongocrypt_version())"
1.9.0PyMongoCrypt 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 addssupport 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 sourceInstalling 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/pythonNext, install libmongocrypt:Installing libmongocryptlibmongocrypt is continuously built and published on evergreen.
The latest tarball containing libmongocrypt built on all supported variants ispublished here.
Download and extractlibmongocrypt-all.tar.gzand setPYMONGOCRYPT_LIBto the path to your operating system’s libmongocrypt.so file.
For example:$ curl -O https://s3.amazonaws.com/mciuploads/libmongocrypt/all/master/latest/libmongocrypt-all.tar.gz
$ mkdir libmongocrypt-all && tar xzf libmongocrypt-all.tar.gz -C libmongocrypt-all
$ ls libmongocrypt-all
amazon2             debian92            rhel-80-64-bit      rhel72-zseries-test ubuntu1804-arm64
amazon2-arm64       linux-64-amazon-ami rhel-81-ppc64el     suse12-64           ubuntu2004-64
amazon2023          macos               rhel-82-arm64       suse15-64           ubuntu2004-arm64
amazon2023-arm64    rhel-62-64-bit      rhel-83-zseries     ubuntu1604          ubuntu2204-64
debian10            rhel-70-64-bit      rhel-91-64-bit      ubuntu1604-arm64    ubuntu2204-arm64
debian11            rhel-71-ppc64el     rhel-91-arm64       ubuntu1804-64       windows-testmacOS:$ # Set PYMONGOCRYPT_LIB for macOS:
$ export PYMONGOCRYPT_LIB=$(pwd)/libmongocrypt-all/macos/lib/libmongocrypt.dylib
$ python -c "import pymongocrypt; print(pymongocrypt.libmongocrypt_version())"
1.9.0Windows:$ # Set PYMONGOCRYPT_LIB for Windows:
$ chmod +x $(pwd)/libmongocrypt-all/windows-test/bin/mongocrypt.dll
$ export PYMONGOCRYPT_LIB=$(pwd)/libmongocrypt-all/windows-test/bin/mongocrypt.dll
$ python -c "import pymongocrypt; print(pymongocrypt.libmongocrypt_version())"
1.9.0Linux: 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-all/ubuntu2204-64/lib/libmongocrypt.so
$ python -c "import pymongocrypt; print(pymongocrypt.libmongocrypt_version())"
1.9.0
$ # Check that native crypto is enabled for better performance:
$ python -c 'from pymongocrypt.binding import lib;print(lib.mongocrypt_is_crypto_available())'
TrueNote if your Linux platform is not available, the generic RHEL 6.2 x86_64 “nocrypto” build
should still be compatible however the “nocrypto” build will result in lower performance
for encryption and decryption:$ # Set PYMONGOCRYPT_LIB for RHEL 6.2 x86_64:
$ export PYMONGOCRYPT_LIB=$(pwd)/libmongocrypt-all/rhel-62-64-bit/nocrypto/lib64/libmongocrypt.so
$ python -c "import pymongocrypt; print(pymongocrypt.libmongocrypt_version())"
1.9.0
$ python -c 'from pymongocrypt.binding import lib;print(lib.mongocrypt_is_crypto_available())'
FalseOther methods of installation (brew, rpm, yum, apt-get, deb, etc…) are documented here:https://www.mongodb.com/docs/manual/core/csfle/reference/libmongocrypt/#linux-installationDependenciesPyMongoCrypt supports Python 3.7+ and PyPy3.7+.PyMongoCrypt requirescffiandcryptography.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:>>>importpymongocryptTraceback(mostrecentcalllast):File"<stdin>",line1,in<module>File"pymongocrypt/__init__.py",line15,in<module>frompymongocrypt.bindingimportlibmongocrypt_version,libFile"pymongocrypt/binding.py",line803,in<module>lib=ffi.dlopen(os.environ.get('PYMONGOCRYPT_LIB','mongocrypt'))File"/.../lib/python3.7/site-packages/cffi/api.py",line146,indlopenlib,function_cache=_make_ffi_library(self,name,flags)File"/.../lib/python3.7/site-packages/cffi/api.py",line828,in_make_ffi_librarybackendlib=_load_backend_lib(backend,libname,flags)File"/.../lib/python3.7/site-packages/cffi/api.py",line823,in_load_backend_libraiseOSError(msg)OSError:ctypes.util.find_library()didnotmanagetolocatealibrarycalled'mongocrypt'Use thePYMONGOCRYPT_LIBenvironment variable to load a locally installed
libmongocrypt build without relying on platform specific library path environment
variables, likeLD_LIBRARY_PATH. For example:$ export PYMONGOCRYPT_LIB='/path/to/libmongocrypt.so'
$ python -c "import pymongocrypt; print(pymongocrypt.libmongocrypt_version())"
1.9.0TestingThe easiest way to run the tests is to runpython setup.py testin
the root of the distribution.