Skip to content

Instantly share code, notes, and snippets.

@ianf-mongodb
ianf-mongodb / insert_encrypted_document.py
Created June 29, 2022 20:36
Python Driver Local KMS Tutorial
from pymongo import MongoClient
from pymongo.encryption_options import AutoEncryptionOpts
from pymongo.encryption import ClientEncryption
import base64
import os
from bson.codec_options import CodecOptions
from bson.binary import STANDARD, UUID
import pprint
# start-key-vault

These are the source files to build Python sample applications that use CSFLE with the following KMS providers:

  • AWS
  • GCP
  • Azure
  • Local KMS

To build Python applications, run the following command from the parent of this directory:

mlaunch --replicaset
mongosh --port 27017
cfg = rs.conf();
cfg.settings.getLastErrorDefaults = {w : 2, wtimeout: 0}
rs.reconfig(cfg)
#MongoServerError: Failed to reconfig: Replica set config contains customized getLastErrorDefaults, which has been deprecated and is now ignored. Use setDefaultRWConcern instead to set a cluster-wide default writeConcern.
print("Hello World!")