Rust-powered embedded database for Python: encryption, GraphRAG, MemPalace AI memory, and an agent-friendly CLI
Project description
RSN DB
A Rust-powered embedded database for Python — fast, secure, and optionally opinionated.
Installation · Quick start · Documentation · Security · Changelog
RSN DB is a single-file embedded database with a native Rust engine and a Python API. Use it like a lightweight local datastore, a graph-aware knowledge store (GraphRAG), or an agent-friendly shell with optional MemPalace AI memory integration.
Highlights
- Performance — Rust core, zstd compression, optimized indexes
- Security — AES-256-GCM encryption at rest, SHA-256 integrity checks, path guards, DoS limits
- Persistence — Explicit
save()/load()/snapshot()with JSON engine snapshots - GraphRAG — Ingest text and query relationships without an external LLM
- Personality modes — Professional, Friendly, or Snarky CLI feedback (130+ snark lines, mood/vitals in Snarky mode)
- AI memory — Session memory sidecar plus optional official MemPalace bridge
- Agent-friendly CLI — Non-interactive
-c,--json,--no-promptfor automation
Installation
pip install rsn_db
Optional extras
# Official MemPalace integration (local-first AI memory)
pip install 'rsn_db[mempalace]'
# Development / tests
pip install 'rsn_db[dev]'
Requires Python 3.9+. Prebuilt wheels are published for common Linux targets; other platforms build from source via maturin (Rust toolchain required).
Quick start
Beginners (recommended)
from rsn_db.beginners import quick_start, insert_many, records_to_dicts
from rsn_db import Query
db = quick_start("my_app.rsndb", mode="friendly")
db.create_table("tasks", {"title": {"type": "string", "required": True}})
insert_many(db, "tasks", [{"title": "Learn RSN DB"}, {"title": "Ship the release"}])
print(records_to_dicts(db.query(Query("tasks"))))
db.save()
Context manager (auto-save on exit)
from rsn_db import open_db
with open_db("shop.rsndb") as db:
db.create_table("products", {"name": {"type": "string", "required": True}})
db.insert("products", {"name": "Widget", "price": 9.99})
Core API (full control)
from rsn_db import Database, Query
db = Database(
storage_path="data.rsndb",
encryption_key="change-me-in-production",
compression="zstd",
mode="professional",
)
db.create_table("users", {"name": {"type": "string", "required": True}})
db.insert("users", {"name": "Alice", "age": 30})
rows = db.query(Query("users").where_eq("name", "Alice"))
db.save()
db.snapshot("backup.rsndb")
See documentation/BEGINNERS.md for a guided walkthrough.
CLI
Interactive shell:
rsn
Automation / agents
rsn --no-prompt -c "SHOW TABLES"
rsn --mode snarky -c "PULSE"
rsn --storage ./app.rsndb --json -c "COUNT users"
rsn --help
REPL commands (non-exhaustive)
| Category | Examples |
|---|---|
| Tables | SHOW TABLES, DESCRIBE users, COUNT users |
| GraphRAG | INGEST …, GRAPH_QUERY … |
| Alive (Snarky) | PULSE, MOOD, VITALS, ACHIEVEMENT |
| MemPalace | MEMPALACE HELP, MEMPALACE SEARCH …, MEMPALACE REMEMBER … |
| Transactions | BATCH, COMMIT, ROLLBACK |
MemPalace integration
RSN DB wraps the official MemPalace/mempalace package (wings → rooms → drawers, ChromaDB, local-first). Install the extra, then:
from rsn_db import open_db
with open_db("app.rsndb", mempalace=True) as db:
db.remember("User prefers Tuesday deploys")
print(db.palace_search("deploy schedule"))
db.sync_to_mempalace()
Use only official sources: GitHub, PyPI, mempalaceofficial.com.
Details: documentation/mempalace.md
Session memory
Lightweight JSON sidecar for conversation turns — no extra install:
from rsn_db import SessionMemory
mem = SessionMemory.for_database("app.rsndb")
mem.add("user", "Remember: staging uses port 8081")
mem.add("assistant", "Noted.")
mem.save()
With MemPalace enabled, RsnDatabase.sync_to_mempalace() pushes turns into your palace.
GraphRAG
Ingest unstructured text and query it locally:
db.ingest("RSN DB was built with Rust and exposed to Python via PyO3.", source="docs")
print(db.graph_query("What is RSN DB built with?"))
Personality modes
| Mode | Behavior |
|---|---|
| Professional | Minimal, neutral output |
| Friendly | Helpful tone with light personality |
| Snarky | Full commentary, 130+ remark pool, mood tracking, ambient PULSE / VITALS |
Set via Python (mode="snarky"), CLI (--mode snarky), or saved preference on first run.
Security
RSN DB is designed with a security-first posture:
| Control | Description |
|---|---|
| Encryption at rest | AES-256-GCM (optional encryption_key) |
| Integrity | SHA-256 checksums on persisted blocks |
| Path guard | Blocks absolute paths and directory traversal |
| DoS limits | Caps on batch size, recursion depth, command length |
| Safe imports | SQLite/JSON import respects declared schema types |
Full write-up: documentation/security.md · documentation/threat_model.md
Documentation
| Document | Description |
|---|---|
| BEGINNERS.md | First-time user guide |
| mempalace.md | Official MemPalace bridge |
| security.md | Security features and guidance |
| threat_model.md | STRIDE threat model |
| patchnotes.md | Version history |
| examples/ | Usage examples |
Development
git clone https://github.com/Enderchefcoder/RSN_DB.git
cd RSN_DB
pip install maturin pytest pytest-cov 'mempalace>=3.3.5,<4'
maturin develop --release
pytest tests/ --cov=rsn_db --cov-config=pyproject.toml
cargo clippy -- -W clippy::pedantic
License
MIT — see LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rsn_db-0.4.3.tar.gz.
File metadata
- Download URL: rsn_db-0.4.3.tar.gz
- Upload date:
- Size: 1.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d2f1d71f9bf88b421e8c3791502bfeb64d9858b1089e272a7e25309cd1419c9
|
|
| MD5 |
a515201da2b36c8a21ef6e20911598fc
|
|
| BLAKE2b-256 |
37952fec7759d709b7646ac1093a9c67b684b633e934e91eb1708aa4cf6ee020
|
File details
Details for the file rsn_db-0.4.3-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: rsn_db-0.4.3-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
518cca59de524505919def5544ce24b35b504274d17a7096553aca55ba1af5f4
|
|
| MD5 |
08b4ca68a69eda2ffc66284ff0ec298a
|
|
| BLAKE2b-256 |
6e0f881f2f5558590870084d21bd47be913b340c8a15bf10ea8ec41f99c18bda
|