PoofDB
PoofDB is a lightweight, file-based, encrypted NoSQL database for Python, built with Pydantic for data validation and Fernet for encryption. It supports asynchronous operations, allowing you to store and manage structured data in a simple JSON-like format with strong encryption.
Features
- Encrypted Storage: All data is encrypted using Fernet (symmetric encryption) with a user-provided or auto-generated key.
- Pydantic Integration: Validates data using Pydantic models for type safety and structure.
- Asynchronous API: Built for async applications using Python's
asyncio. - Simple Structure: Organizes data into databases (max 10), collections (max 50 per database), and documents with unique IDs (12–26 characters).
- File-Based: Stores data in a single encrypted file (e.g.,
cluster.poof).
Quick Start
Create a simple script to use PoofDB. Below is an example (simple_db.py) that inserts and reads a document using a custom Pydantic model.
import asyncio
from pydantic import BaseModel
from poof import PoofCluster
class User(BaseModel):
name: str
age: int
async def main():
# Use an existing key or generate a new one (see "Generating a New Key")
key = "your key"
# Create cluster
cluster = await PoofCluster.create("cluster.poof", key=key)
# Get database and collection
db = await cluster.get_database("my_db")
coll = await db.get_collection("my_collection")
# Insert document
user = User(name="Alice", age=25)
doc = await coll.insert(user)
print(f"Inserted: objId={doc.objId}, Name={user.name}, Age={user.age}")
# Read document
found_doc = await coll.find_by_id(doc.objId)
if found_doc:
user_data = User(**found_doc.data)
print(f"Found: objId={found_doc.objId}, Name={user_data.name}, Age={user_data.name}")
# Save cluster
await cluster.save()
if __name__ == "__main__":
asyncio.run(main())
Run the script:
python simple_db.py
Output:
Inserted: objId=XyZ123AbCdEfGhIjKlMnOp, Name=Alice, Age=25
Found: objId=XyZ123AbCdEfGhIjKlMnOp, Name=Alice, Age=25
Generating a New Key
To create a new cluster with a new encryption key, use the following script (new_cluster_key.py):
import asyncio
from poof import PoofCluster
async def main():
cluster = await PoofCluster.create("new_cluster.poof")
key = cluster.get_encryption_key()
print(f"New encryption key: {key}")
await cluster.save()
print(f"New cluster created at: new_cluster.poof")
if __name__ == "__main__":
asyncio.run(main())
Run it:
python new_cluster_key.py
Output:
New encryption key: a1B2c3D4e5F6g7H8i9J0kL1mN2oP3qR4sT5uV6wX7yZ8=
New cluster created at: new_cluster.poof
Important: Save the key securely, as it’s required to access the cluster file. Lost keys cannot be recovered.
API Overview
- PoofCluster: Manages the database file and encryption.
create(file_path, key=None): Creates or loads a cluster.get_encryption_key(): Returns the base64-encoded key.get_database(name): Retrieves or creates a database.save(): Saves the cluster to the file.
- PoofDatabase: Manages collections (max 50).
get_collection(name): Retrieves or creates a collection.
- PoofCollection: Manages documents.
insert(data): Inserts a document with a random ID (12–26 chars).find_by_id(obj_id): Finds a document by ID.find_all(): Returns all documents.update(obj_id, data): Updates a document.delete(obj_id): Deletes a document.
- PoofDocument: Represents a document with an
objIdanddata(dictionary).
Custom Models
Define your own Pydantic model to validate data. For example:
class MyModel(BaseModel):
field1: str
field2: int
Use it in place of User in the example above.
Limitations
- Maximum 10 databases per cluster.
- Maximum 50 collections per database.
- Document IDs are 12–26 characters, randomly generated.
- Data is stored in a single file, which may not scale for very large datasets.
- Encryption key must be managed manually.
Error Handling
- Invalid Key: Raises
ValueError: Decryption failedif the key is incorrect. - Validation Errors: Pydantic raises
ValidationErrorif data doesn’t match the model. - Limits Exceeded: Raises
ValueErrorif database or collection limits are reached.
Metadata
Release files for poofdb 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| poofdb-0.0.1.tar.gz | 4.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| poofdb-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.4 kB
Release files / poofdb-0.0.1.tar.gz
| Download URL | poofdb-0.0.1.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27e9e3350098e03e5915523cbfdf9ffe9887b00ecf46cfcfb57354ab2b6e586e
|
|
BLAKE2b-256 checksum How to use checksums |
c44afe057186be5d7e70070128d62b4d063953d4069c8adbc60fd499eb64b554
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.0
|
Release files / poofdb-0.0.1-py3-none-any.whl
| Download URL | poofdb-0.0.1-py3-none-any.whl |
|---|---|
| Size | 2.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9bfe4b01e41b47f99d0ab22184c382c76a3c568c9a5a3573f52869caece9d28d
|
|
BLAKE2b-256 checksum How to use checksums |
be13a5e48d0627e603970d480ea0a8a370d76e35020261573ec07385795f08d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.0
|
Security for poofdb 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.