Skip to main content

engramedb

PyPI Version License: MIT Python

EngramDB is a high-performance, code-native graph database engine implemented in Rust with PyO3 Python bindings. It is designed for AI agents, MCP servers, code search and static analysis tooling. EngramDB compiles functions, classes, files and their relationships into an in-memory Compressed Sparse Row (CSR) graph for low-latency call-graph queries and impact analysis.

Overview

Cordyceps and similar systems require fast, language-aware dependency analysis without invoking a full compiler. EngramDB provides:

  • Deterministic node identity (file_path:qualified_name) with content hashing (Blake3)
  • Dual CSR graphs: execution graph (call edges) and full dependency graph (execution + structural)
  • Snapshot persistence with versioned binary format for fast cold-start and warm-start

Package name on PyPI is engramedb. Import name is engramdb:

pip install engramedb
import engramdb

Features

  • CSR Graph Traversal — Bidirectional CSR with blast_radius (callers) and recursive_callees (callees), configurable depth, microsecond latency on 50k nodes
  • Thread Safety — Arc<RwLock<InnerEngineState>> with concurrent read() and exclusive write(); snapshot_loaded guard for warm-start correctness
  • Rich Metadata Index — Nodes for Function, Class, File, Folder, Route, Middleware, Declaration with signatures, docstrings, decorators, inheritance (base_classes/inherits), line ranges, and extra_json payloads
  • Typed Edges — Separation of resolved_call_edges (Python contextual resolution), execution_edges / generated_execution_edges (routes, middleware, HTTP), and structural_edges (containment, imports, Django ORM). get_callers/get_callees traverse execution only; get_dependencies/get_dependents traverse the full graph
  • Python Contextual Resolution (v3) — Lexically scoped, import-aware and receiver-typed resolution using python_import_bindings, python_receiver_types, python_shadowed_names; handles aliases, dotted imports, self/cls/super() MRO, shadowed locals, and union annotations
  • Persistence — Binary snapshot v3 (EGRM magic + version byte) persisting both metadata and typed edge sets; automatic invalidation on stale indexes
  • Pre-built Wheels — Linux, macOS and Windows for CPython 3.10–3.13

Installation

pip install engramedb

Requires Python 3.10 or newer.

Quick Start

import engramdb
import json

# 1. Initialize — workspace path is the snapshot root
engine = engramdb.PyMetadataEngine("/path/to/workspace")

# 2. Index nodes (extra metadata accepted as dict via _extra or JSON via extra_json)
engine.add_node(
    "services.py:create_sale",
    "Function",
    "create_sale",
    "services.py",
    _extra={
        "signature": "def create_sale(user, item_id):",
        "docstring": "Creates a new sales transaction.",
        "decorators": ["transaction.atomic"],
        "lines_start": 10,
        "lines_end": 25,
    }
)
engine.add_node("inventory.py:deduct_stock", "Function", "deduct_stock", "inventory.py")
engine.add_node("services.py", "File", "services.py", "services.py")

# 3. Wire edges — two args only
engine.add_edge("services.py:create_sale", "inventory.py:deduct_stock")          # execution / call edge
engine.add_structural_edge("services.py:create_sale", "services.py")            # containment edge
# generated edges (routes, middleware) use add_generated_edge and are replaced on re-resolve

# 4. Build CSR graphs
engine.build()

# 5. Query — typed traversal
print(engine.get_callees("services.py:create_sale"))       # execution callees only
print(engine.get_dependencies("services.py:create_sale"))  # execution + structural
print(engine.get_callers("inventory.py:deduct_stock"))
print(engine.blast_radius("inventory.py:deduct_stock", 3)) # transitive callers
print(engine.get_recursive_callees("services.py:create_sale", 2))

# 6. Search and metadata
print(engine.search("create_sale"))
print(engine.get_node_meta("services.py:create_sale"))
print(engine.get_all_metadata())

Alternative extra_json form for raw bindings:

engine.add_node(
    "services.py:create_sale", "Function", "create_sale", "services.py",
    extra_json=json.dumps({"signature": "def create_sale(...):"})
)

API Reference

Method Description
PyMetadataEngine(path) Create or restore engine for workspace path. Restores v3 snapshot if present and compatible
add_node(node_id, node_type, name, file_path, ..., extra_json=None, _extra=None) Upsert node. node_id format file:qualified_name, files use file_path as id. _extra accepts dict, extra_json accepts JSON string
add_edge(from_id, to_id) Add execution edge (call / explicit dependency)
add_structural_edge(from_id, to_id) Add structural edge (file contains, import, class contains)
add_generated_edge(from_id, to_id) Add generated execution edge (route, middleware, frontend HTTP)
clear_generated_edges() Clear generated execution edges before re-resolution
get_callees(node_id) / get_callers(node_id) Direct execution neighbors (deduplicated, order-preserving)
get_dependencies(node_id) / get_dependents(node_id) Direct neighbors on the full graph (execution + structural + generated)
blast_radius(node_id, depth) Transitive callers (BFS on execution graph)
get_recursive_callees(node_id, depth) Transitive callees (BFS on execution graph)
search(keyword) Keyword search over name, file_path, signature
get_node_meta(node_id) / get_all_metadata() Metadata lookup
contains(node_id) / snapshot_loaded() Existence and warm-start status
invalidate_file(file_path) / repopulate_edges() Incremental invalidation and call re-resolution
build() / rebuild() / save() / close() CSR compilation and snapshot persistence

Persistence and Versioning

Snapshots are stored as .engram_snapshot.bin in the workspace root. Format version is 3 (EGRM + 0x03). Changing the extraction schema (parser python-contextual-calls-v3) or edge typing bumps the version and forces a full rescan when an older snapshot is encountered. snapshot_loaded() returns False for missing or incompatible snapshots.

Thread Safety

All mutations acquire the Rust write() lock; reads use read(). No py.allow_threads() is used — graph operations are sub-millisecond, avoiding GIL/mutex interaction.

License

Distributed under the MIT License.

Metadata

Release files for engramedb 1.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for engramedb 1.1.3
File Size Uploaded Provenance Actions
engramedb-1.1.3.tar.gz 34.5 kB Without provenance Details for engramedb-1.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for engramedb 1.1.3
File Interpreter ABI Platform Actions
engramedb-1.1.3-cp310-cp310-manylinux_2_34_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.34+ x86-64 Details for engramedb-1.1.3-cp310-cp310-manylinux_2_34_x86_64.whl

Total release size: 507.2 kB

Release files / engramedb-1.1.3.tar.gz

Download URL engramedb-1.1.3.tar.gz
Size 34.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c17d038f235b31b90b32028e0e44451220f18a473a5830188f6e242bb886f9e0
BLAKE2b-256 checksum
How to use checksums
158680e5874b60866edc895bb4c1dfb159e601a4f9e4897741864e2d4c07f0f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.1

Release files / engramedb-1.1.3-cp310-cp310-manylinux_2_34_x86_64.whl

Download URL engramedb-1.1.3-cp310-cp310-manylinux_2_34_x86_64.whl
Size 472.7 kB
Tags CPython 3.10 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
468f2f4c987509f2906b79b2eabfe58883e0ca41724e425f778693ef19709c8f
BLAKE2b-256 checksum
How to use checksums
2c529727fe08604e3fa4d652a233c47ca044dd4fea3aaa2a3366e9d5268138bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.1

Security for engramedb 1.1.3

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page