Metadata-Version: 2.4
Name: engramedb
Version: 1.1.1
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
License-File: LICENSE
Summary: Real-time Code-Native Graph Database Engine (Rust Core)
Author: Ghassen Saidi
License: MIT
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM

# engramedb

[![PyPI Version](https://img.shields.io/pypi/v/engramedb.svg)](https://pypi.org/project/engramedb/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

**EngramDB** is a high-performance, real-time, code-native graph database engine written in **Rust** with native **PyO3** Python bindings.

Designed for AI agentic tools, MCP servers, code search engines, and static analysis tools, EngramDB compiles AST nodes, function calls, class inheritance, and file dependencies into an in-memory Compressed Sparse Row (CSR) graph for microsecond-latency impact analysis and graph querying.

---

## Key Features

- ⚡ **Ultra-Fast CSR Graph Traversal**: Bidirectional dual CSR (execution vs full-dependency) for sub-millisecond `blast_radius` / `recursive_callees`.
- 🧵 **Thread-Safe Architecture**: `Arc<RwLock<InnerEngineState>>` with `read()`/`write()` and `snapshot_loaded` warm-start guard.
- 🔍 **Rich AST Metadata Indexing**: Functions/classes/files/folders/routes with signatures, decorators, `inherits`, `imports`, line ranges + `extra_json` (`python_import_bindings`, `python_receiver_types`, `python_shadowed_names` for Python contextual calls `v3`).
- 🛡️ **Blast Radius & Impact Analysis**: `get_callers`/`get_callees` = execution only; `get_dependencies`/`get_dependents` = full structural + execution.
- 💾 **Zero-Copy Persistence**: Binary snapshot `v3` (`EGRM` + typed `resolved_call_edges`/`execution_edges`/`generated_execution_edges`/`structural_edges`).
- 🐍 **Pre-compiled Python Wheels**: Linux/macOS/Windows, CPython 3.10–3.13.

---

## Installation

```bash
pip install engramedb
```

---

## Quick Start

```python
import engramdb

# 1. Initialize engine with workspace storage path
engine = engramdb.PyMetadataEngine("/path/to/workspace")

# 2. Index AST nodes (calls + extra metadata)
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")

# 3. Wire edges — execution vs structural are typed (v3 snapshot)
engine.add_edge("services.py:create_sale", "inventory.py:deduct_stock")  # 2 args: execution/call edge
engine.add_structural_edge("services.py:create_sale", "services.py")      # containment / import / ORM

# 4. Build CSR (dual graphs: execution + full dependencies)
engine.build()

# 5. Typed traversal
print(engine.get_callees("services.py:create_sale"))      # execution only
print(engine.get_dependencies("services.py:create_sale"))  # execution + structural
print(engine.blast_radius("inventory.py:deduct_stock", 3))
print(engine.search("create_sale"))
```

---

## License

Distributed under the [MIT License](LICENSE).

