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

Supported Languages

Indexed via tree-sitter (adding a language = drop a YAML in languages/). All other extensions listed below are ingested as body-only File nodes.

Language Extensions Parser Notes
Python .py tree_sitter_python Full contextual resolution (imports, scopes, receiver types, self/super MRO)
JavaScript .js tree_sitter_javascript Functions, classes, calls, imports/exports, routes, HTTP calls
JavaScript (JSX) .jsx tree_sitter_javascript Same as JS + JSX components
TypeScript .ts tree_sitter_typescript Types, interfaces, generics, inheritance
TypeScript (TSX) .tsx tree_sitter_typescript Same as TS + JSX/TSX components

Body-only file nodes (no AST, searchable as files): .json, .md, .html, .css, .yml, .yaml, .toml, .txt, .sql. Excluded dirs are node_modules, venv, dist, migrations, .git etc. (configurable via CORDYCEPS_EXCLUDE).

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.4

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.4
File Size Uploaded Provenance Actions
engramedb-1.1.4.tar.gz 35.4 kB Without provenance Details for engramedb-1.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for engramedb 1.1.4
File Interpreter ABI Platform Actions
engramedb-1.1.4-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.4-cp310-cp310-manylinux_2_34_x86_64.whl

Total release size: 507.7 kB

Release files / engramedb-1.1.4.tar.gz

Download URL engramedb-1.1.4.tar.gz
Size 35.4 kB
Tags Source
SHA-256 checksum
How to use checksums
80c2b978ac50da079d6f68694eee42f1a1a5208f6000de22ff5175c699af4c2d
BLAKE2b-256 checksum
How to use checksums
d07367843f0272fcca3bf69580e51dabdc875e64e904286ef73a27bdd08cabb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.1

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

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

Security for engramedb 1.1.4

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