No description
- Python 100%
| mongocrypt | ||
| .gitattributes | ||
| .gitignore | ||
| example.py | ||
| INSTALL.md | ||
| LICENSE | ||
| MANIFEST.in | ||
| pyproject.toml | ||
| README.md | ||
MongoCrypt
A Python package for MongoDB with automatic encryption using Motor. All data stored in MongoDB is automatically encrypted using a secret key.
Features
- 🔒 Automatic encryption/decryption of all data
- ⚡ Async/await support with Motor
- 🛠️ Basic CRUD operations
- 🔑 Secret-based encryption using Fernet (symmetric encryption)
Installation
From Git Repository
Install directly from a git repository:
pip install git+https://github.com/yourusername/MongoCrypt.git
Or install from a specific branch/tag:
pip install git+https://github.com/yourusername/MongoCrypt.git@main
pip install git+https://github.com/yourusername/MongoCrypt.git@v0.1.0
Local Development Installation
For local development:
git clone https://github.com/yourusername/MongoCrypt.git
cd MongoCrypt
pip install -e .
Or with development dependencies:
pip install -e ".[dev]"
Usage
import asyncio
from mongocrypt import MongoCryptClient
async def main():
# Initialize client with MongoDB URI and encryption secret
client = MongoCryptClient(
uri="mongodb://localhost:27017",
secret="your-secret-key-here" # Keep this secure!
)
# Connect to database
await client.connect()
# Get a collection
collection = client.get_collection("mydb", "mycollection")
# Insert encrypted document
result = await collection.insert_one({"name": "John", "age": 30})
print(f"Inserted document with ID: {result.inserted_id}")
# Find encrypted document (automatically decrypted)
document = await collection.find_one({"_id": result.inserted_id})
print(f"Found document: {document}")
# Update encrypted document
await collection.update_one(
{"_id": result.inserted_id},
{"$set": {"age": 31}}
)
# Delete document
await collection.delete_one({"_id": result.inserted_id})
# Close connection
await client.close()
if __name__ == "__main__":
asyncio.run(main())
Security Notes
- Never commit your secret key to version control
- Use environment variables or secure secret management for production
- The secret key must be the same for encryption and decryption
- If you lose the secret key, encrypted data cannot be recovered
License
MIT