Skip to main content

Python bindings for libmongocrypt

Project description

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.7+ and PyPy3.7+.

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, JAVA) 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.2.1

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.

libmongocrypt is continuously built and published on evergreen. The latest tarball containing libmongocrypt built on all supported variants is published here. Download and extract libmongocrypt-all.tar.gz and set PYMONGOCRYPT_LIB to 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             rhel-62-64-bit      rhel72-zseries-test ubuntu1604-arm64
debian10            rhel-67-s390x       suse12-64           ubuntu1804-64
debian92            rhel-70-64-bit      suse12-s390x        ubuntu1804-arm64
linux-64-amazon-ami rhel-71-ppc64el     suse15-64           windows-test
macos               rhel-80-64-bit      ubuntu1604

macOS:

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

Windows:

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

Linux:

$ # 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.2.1

Dependencies

PyMongoCrypt supports Python 3.7+ and PyPy3.7+.

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.7/site-packages/cffi/api.py", line 146, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "/.../lib/python3.7/site-packages/cffi/api.py", line 828, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File "/.../lib/python3.7/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.2.1

Testing

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymongocrypt-1.7.0.tar.gz (44.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pymongocrypt-1.7.0-py3-none-win_amd64.whl (2.7 MB view details)

Uploaded Python 3Windows x86-64

pymongocrypt-1.7.0-py3-none-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (5.0 MB view details)

Uploaded Python 3manylinux: glibc 2.12+ x86-64

pymongocrypt-1.7.0-py3-none-manylinux2010_x86_64.whl (5.0 MB view details)

Uploaded Python 3manylinux: glibc 2.12+ x86-64

pymongocrypt-1.7.0-py3-none-macosx_11_0_universal2.whl (6.9 MB view details)

Uploaded Python 3macOS 11.0+ universal2 (ARM64, x86-64)

pymongocrypt-1.7.0-py3-none-macosx_10_14_intel.whl (3.5 MB view details)

Uploaded Python 3macOS 10.14+ Intel (x86-64, i386)

File details

Details for the file pymongocrypt-1.7.0.tar.gz.

File metadata

  • Download URL: pymongocrypt-1.7.0.tar.gz
  • Upload date:
  • Size: 44.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for pymongocrypt-1.7.0.tar.gz
Algorithm Hash digest
SHA256 ac1e31d5a10ba6af13942aaaf28276840a2d1235f5bcec812efe753415c63d3e
MD5 b9cb89ad745188c4ff4a38dd8883af95
BLAKE2b-256 f190be1714c1eaf9f299923857dc1c14c05526cc713205b99ec2ee3c3fb4b148

See more details on using hashes here.

File details

Details for the file pymongocrypt-1.7.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: pymongocrypt-1.7.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for pymongocrypt-1.7.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 7af4f79c13c8670a462fe94fb194b87d31360b34d12ef5f321be9eff2568c5ae
MD5 bd0416fabec4b57507e2e2db9c317306
BLAKE2b-256 59689dbf227aed02c1871c89fd51f6bf9913ab837b1a5e9154c972c4841ac2d0

See more details on using hashes here.

File details

Details for the file pymongocrypt-1.7.0-py3-none-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for pymongocrypt-1.7.0-py3-none-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 9ef63775768bdc049228e03c10f489a2645690cb65fdf1a78ddbf84f3fbfd8f2
MD5 a8de2cd31354b04f86d4a7bc207a910e
BLAKE2b-256 671caeca7f2a28536d811cc28e014de540bfb2d000f06544e4b924e22132033e

See more details on using hashes here.

File details

Details for the file pymongocrypt-1.7.0-py3-none-manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for pymongocrypt-1.7.0-py3-none-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 13e1b15708730a93d2992d3351977c4f5dbcb015aec3056602ed14e83db975b5
MD5 18ecaee774281e6b742611a55f834aa1
BLAKE2b-256 ce1809e420cf4559d0a2ce9c6fd87d90f13fe2f5033dfc64f5e9470e28d3b286

See more details on using hashes here.

File details

Details for the file pymongocrypt-1.7.0-py3-none-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for pymongocrypt-1.7.0-py3-none-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 4e891770b9a60abddded783dfe703b65314fecf10cab8a824f7f1ab31cfbec2a
MD5 ffa7b4df3257d903ef7f5187ffc673f6
BLAKE2b-256 7f94bf061840a2deffd085b2236a29f4f3fa0af40c58b2cd45b26b668dd96ba5

See more details on using hashes here.

File details

Details for the file pymongocrypt-1.7.0-py3-none-macosx_10_14_intel.whl.

File metadata

File hashes

Hashes for pymongocrypt-1.7.0-py3-none-macosx_10_14_intel.whl
Algorithm Hash digest
SHA256 a6817ad6526699c6e2876a555e057d4b487e3b5598b352557450043b7c837cea
MD5 1f8a8e26e75489d3e40539aabf3af6ee
BLAKE2b-256 4d75160e29a6d38c09ab655fd9a2d2af1d1258dc5640e0b9a3c5cb518b33ef17

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page