PyMongo 4.19 Released

We are pleased to announce the 4.18.0 release of PyMongo - MongoDB’s Python Driver.

Changes in 4.19.0

PyMongo 4.19 brings a number of changes including:

  • Added support for Python 3.15.

  • Dropped support for Python 3.9 and 3.10.

  • Removed support for PyPy.

  • Removed the deprecated Algorithm.RANGEPREVIEW and QueryType.RANGEPREVIEW members (PYTHON-6009).

  • Added support for running the synchronous and asynchronous clients in subinterpreters, including inside concurrent.futures.InterpreterPoolExecutor (Python 3.14+). Only in subinterpreters, which do not allow daemon threads, the synchronous client’s monitor threads now start as non-daemon threads and are stopped and joined when the interpreter is torn down. Monitor threads in the main interpreter remain daemon threads and shutdown behavior is unchanged. Note that because these threads are non-daemon, a subinterpreter may block on teardown until any in-flight monitor work completes.

  • Added support for routing Key Management Service (KMS) requests for Client-Side Field Level Encryption and Queryable Encryption through an HTTP proxy, using the new kms_connect_callback option on :class:`~pymongo.encryption_options.AutoEncryptionOpts`, :class:`~pymongo.encryption.ClientEncryption`, and :class:`~pymongo.asynchronous.encryption.AsyncClientEncryption`. The callback opens the connection and the driver performs the KMS TLS handshake over it, so verification still targets the KMS host rather than the proxy. For an ordinary HTTP proxy, pass :class:`~pymongo.encryption_options.HTTPProxyKMSConnect` or :class:`~pymongo.encryption_options.AsyncHTTPProxyKMSConnect` instead of writing a callback. Both helpers accept custom CONNECT headers, e.g. Proxy-Authorization for proxies that require authentication.

  • Added the srv_host_validator keyword argument to :class:`~pymongo.synchronous.mongo_client.MongoClient` and :class:`~pymongo.asynchronous.mongo_client.AsyncMongoClient`, an alternative to srvAllowedHostsSuffix for deployments whose acceptable SRV hosts cannot be expressed as a single suffix. The callback is invoked once per SRV-returned host and must return a boolean: True to accept the host and False to reject it. During initial DNS discovery a non-boolean return raises an error; during SRV polling it is treated as a rejection. It is mutually exclusive with srvAllowedHostsSuffix and, because it takes a callable, cannot be set in a connection string. See the :class:`~pymongo.synchronous.mongo_client.MongoClient` and :class:`~pymongo.asynchronous.mongo_client.AsyncMongoClient` documentation for security considerations.

  • srvAllowedHostsSuffix may now be set to a single label reserved for private or special use, such as localhost, test, or internal.

Bug fixes

  • Fixed a bug where the synchronous client could permanently deadlock under gevent when a greenlet was killed while checking a connection back into the pool (PYTHON-6074).

  • MongoClient.append_metadata() and AsyncMongoClient.append_metadata() now detect duplicates by comparing the whole :class:`~pymongo.driver_info.DriverInfo` instead of only its name. The comparison is exact, so drivers that differ in name case or platform are no longer treated as duplicates (PYTHON-6040).

  • driver.name and driver.version in the handshake metadata are now |-delimited lists with 1:1 index correspondence, including empty version entries for the built-in |c and |async name segments (PYTHON-6040).

  • Fixed a bug where truncating the handshake metadata to 512 bytes could leave driver.name and driver.version with different numbers of | delimiters (PYTHON-6040).

  • :class:`~pymongo.driver_info.DriverInfo` now raises :class:`ValueError` when any field contains the reserved | delimiter (PYTHON-6040).

  • Fixed a bug in SRV polling where invalid hosts where topology would not be updated if one returned host was invalid.

  • Fixed a bug where the C extension’s BSON decoder accepted documents whose element data overlaps the document terminator instead of raising InvalidBSON (PYTHON-6111).

  • Fixed a bug where the pure-Python decode_all() accepted buffers ending in a partial document instead of raising InvalidBSON, now matching the C extension (PYTHON-6163).

Issues Resolved

See the PyMongo 4.19.0 release notes in JIRA for the list of resolved issues in this release.