Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dist-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

- uses: actions/setup-python@v6
with:
python-version: "3.9"
python-version: "3.11"
cache: 'pip'
cache-dependency-path: 'bindings/python/pyproject.toml'
allow-prereleases: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.9", "3.13", "3.14"]
python-version: ["3.11", "3.13", "3.14"]

steps:
- uses: actions/checkout@v5
Expand Down
6 changes: 3 additions & 3 deletions bindings/python/.evergreen/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ createvirtualenv () {

# Prints each usable interpreter from the space-separated candidate list,
# one per line, ascending by version. An interpreter is usable if it is
# version 3.9 or later, a final release, and not free-threaded.
# version 3.11 or later, a final release, and not free-threaded.
_probe_pythons() {
for bin in $1; do
[ -x "$bin" ] || continue
"$bin" -c 'import sys
ok = sys.version_info >= (3, 9) and sys.version_info.releaselevel == "final" and "free-threading" not in sys.version
ok = sys.version_info >= (3, 11) and sys.version_info.releaselevel == "final" and "free-threading" not in sys.version
exit(0 if ok else 1)' 2>/dev/null || continue
printf '%s\t%s\n' "$("$bin" -c 'import sys; print("%04d" % (sys.version_info[0] * 1000 + sys.version_info[1]))')" "$bin"
done | sort | cut -f2-
}

# Prints the Python interpreters in the standard numbered toolchain locations,
# one per line, ascending by version, Python 3.9+ only. Only plain version
# one per line, ascending by version, Python 3.11+ only. Only plain version
# directories are matched (e.g. 3.14, not 3.14-asan-ubsan, 3.14t, or on
# Windows Python314t/Python314-arm64). On Linux, falls back to the latest
# MongoDB toolchain interpreter when the Python toolchain is absent, then to
Expand Down
2 changes: 2 additions & 0 deletions bindings/python/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
Changes in Version 1.21.0
-------------------------

- Drop support for Python 3.9 and 3.10, and for PyPy. Python >=3.11 is now
required.
- Bundle libmongocrypt 1.21.0 in release wheels.
- Removed the deprecated "prefixPreview", "suffixPreview", and
"substringPreview" query types. Use "prefix", "suffix", and "substring"
Expand Down
10 changes: 5 additions & 5 deletions bindings/python/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Python wrapper library for libmongocrypt that supports client side encryption
in drivers. PyMongoCrypt uses `cffi <https://pypi.org/project/cffi/>`_ and
`cryptography <https://pypi.org/project/cryptography/>`_.

PyMongoCrypt supports Python 3.8+ and PyPy3.9+.
PyMongoCrypt supports Python 3.11+.

Support / Feedback
==================
Expand Down Expand Up @@ -157,7 +157,7 @@ for encryption and decryption::
Dependencies
============

PyMongoCrypt supports Python 3.8+ and PyPy3.9+.
PyMongoCrypt supports Python 3.11+.

PyMongoCrypt requires `cffi <https://pypi.org/project/cffi/>`_ and
`cryptography <https://pypi.org/project/cryptography/>`_.
Expand All @@ -175,11 +175,11 @@ installed you will see an error like this:
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
File "/.../lib/python3.11/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
File "/.../lib/python3.11/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
File "/.../lib/python3.11/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'

Expand Down
6 changes: 3 additions & 3 deletions bindings/python/RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ Manually Creating Wheels
$ git clone [email protected]:mongodb/libmongocrypt.git
$ cd libmongocrypt/bindings/python
$ git checkout "pymongocrypt <release version number>"
$ MACOS_TARGET=macos_x86_64 PYTHON=<python38> ./release.sh
$ PYTHON=<python310> ./release.sh
$ MACOS_TARGET=macos_x86_64 PYTHON=<python311> ./release.sh
$ PYTHON=<python311> ./release.sh

Make sure to run using the official binaries for Python 3.8 and 3.10. You
Make sure to run using the official binaries for Python 3.11. You
should end up with the same files created by Evergreen (except for the Windows wheel).

#. To build the release package for Windows, launch a windows-64-vsMulti-small
Expand Down
6 changes: 3 additions & 3 deletions bindings/python/pymongocrypt/asynchronous/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
import os
from collections import namedtuple
from datetime import datetime, timedelta, timezone
from datetime import UTC, datetime, timedelta

try:
from pymongo_auth_aws.auth import aws_temp_credentials
Expand Down Expand Up @@ -74,7 +74,7 @@ async def _get_azure_credentials():
# Credentials are considered expired when: Expiration - now < 1 mins.
creds = _azure_creds_cache
if creds:
if creds.expires_utc - datetime.now(tz=timezone.utc) < timedelta(seconds=60):
if creds.expires_utc - datetime.now(tz=UTC) < timedelta(seconds=60):
_azure_creds_cache = None
else:
return {"accessToken": creds.access_token}
Expand Down Expand Up @@ -114,7 +114,7 @@ async def _get_azure_credentials():
% response.content
) from e

expires_utc = datetime.now(tz=timezone.utc) + timedelta(seconds=expires_in)
expires_utc = datetime.now(tz=UTC) + timedelta(seconds=expires_in)
_azure_creds_cache = _azure_creds(data["access_token"], expires_utc)
return {"accessToken": data["access_token"]}

Expand Down
14 changes: 2 additions & 12 deletions bindings/python/pymongocrypt/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,9 @@

"""Utility functions and definitions for Python compatibility."""

import sys
from abc import ABC # noqa: F401 # re-exported for pymongocrypt.*.state_machine

PY3 = sys.version_info[0] >= 3

if PY3:
from abc import ABC

unicode_type = str
else:
from abc import ABCMeta as _ABCMeta

ABC = _ABCMeta("ABC", (object,), {})
unicode_type = "unicode"
unicode_type = str


def str_to_bytes(string):
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/pymongocrypt/mongocrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, options, callback):
if not isinstance(options, MongoCryptOptions):
raise TypeError("options must be a MongoCryptOptions")

if not isinstance(callback, (AsyncMongoCryptCallback, MongoCryptCallback)):
if not isinstance(callback, AsyncMongoCryptCallback | MongoCryptCallback):
raise TypeError(
"callback must be a MongoCryptCallback or AsyncMongoCryptCallback"
)
Expand Down
9 changes: 3 additions & 6 deletions bindings/python/pymongocrypt/options.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from pymongocrypt.compat import unicode_type


class MongoCryptOptions:
def __init__(
self,
Expand Down Expand Up @@ -114,23 +111,23 @@ def __init__(
f"kms_providers[{name!r}] must contain "
"'email' and 'privateKey'"
)
if not isinstance(provider["privateKey"], (bytes, unicode_type)):
if not isinstance(provider["privateKey"], bytes | str):
raise TypeError(
f"kms_providers[{name!r}]['privateKey'] must "
"be an instance of bytes or str"
)
elif provider_type == "kmip":
if "endpoint" not in provider:
raise ValueError(f"kms_providers[{name!r}] must contain 'endpoint'")
if not isinstance(provider["endpoint"], (str, unicode_type)):
if not isinstance(provider["endpoint"], str):
raise TypeError(
f"kms_providers[{name!r}]['endpoint'] must "
"be an instance of str"
)
elif provider_type == "local":
if "key" not in provider:
raise ValueError(f"kms_providers[{name!r}] must contain 'key'")
if not isinstance(provider["key"], (bytes, unicode_type)):
if not isinstance(provider["key"], bytes | str):
raise TypeError(
f"kms_providers[{name!r}]['key'] must be an "
"instance of bytes or str"
Expand Down
6 changes: 3 additions & 3 deletions bindings/python/pymongocrypt/synchronous/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
import os
from collections import namedtuple
from datetime import datetime, timedelta, timezone
from datetime import UTC, datetime, timedelta

try:
from pymongo_auth_aws.auth import aws_temp_credentials
Expand Down Expand Up @@ -74,7 +74,7 @@ def _get_azure_credentials():
# Credentials are considered expired when: Expiration - now < 1 mins.
creds = _azure_creds_cache
if creds:
if creds.expires_utc - datetime.now(tz=timezone.utc) < timedelta(seconds=60):
if creds.expires_utc - datetime.now(tz=UTC) < timedelta(seconds=60):
_azure_creds_cache = None
else:
return {"accessToken": creds.access_token}
Expand Down Expand Up @@ -114,7 +114,7 @@ def _get_azure_credentials():
% response.content
) from e

expires_utc = datetime.now(tz=timezone.utc) + timedelta(seconds=expires_in)
expires_utc = datetime.now(tz=UTC) + timedelta(seconds=expires_in)
_azure_creds_cache = _azure_creds(data["access_token"], expires_utc)
return {"accessToken": data["access_token"]}

Expand Down
5 changes: 1 addition & 4 deletions bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dynamic = ["version", "dependencies", "optional-dependencies"]
description = "Python bindings for libmongocrypt"
readme = "README.rst"
license = {file="LICENSE"}
requires-python = ">=3.9"
requires-python = ">=3.11"
authors = [
{ name = "Shane Harvey", email = "[email protected]" },
]
Expand All @@ -30,9 +30,6 @@ classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
Expand Down
13 changes: 1 addition & 12 deletions bindings/python/scripts/update_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,13 @@
"""

import re
from itertools import pairwise
from pathlib import Path

DROP_RE = re.compile(r"^\s*(#|MONGOCRYPT_EXPORT)")
HERE = Path(__file__).absolute().parent


# itertools.pairwise backport for Python 3.9 support.
def pairwise(iterable):
# pairwise('ABCDEFG') → AB BC CD DE EF FG

iterator = iter(iterable)
a = next(iterator, None)

for b in iterator:
yield a, b
a = b


def strip_file(content):
fold = content.replace("\\\n", " ")
all_lines = [*fold.split("\n"), ""]
Expand Down
Loading
Loading