Engram Python SDK
Neural memory format for AI systems — hierarchical, temporal, multi-modal.
Installation
pip install engram
With LangChain support:
pip install engram[langchain]
Quick Start
from engram import MemoryTree
# Create a new memory tree
tree = MemoryTree()
# Add memories
tree.add("The capital of France is Paris.", tags=["geography", "facts"])
tree.add("Python was created by Guido van Rossum.", tags=["programming", "facts"])
# Save to file
tree.save("knowledge.engram")
# Load from file
tree = MemoryTree.from_file("knowledge.engram")
print(f"Loaded {tree.size()} memories")
# Search
results = tree.find_by_tag("facts")
results = tree.search_text("Python")
Core Concepts
Memory Nodes
Each memory is a MemoryNode with:
- Content — Text, image, audio, or code
- Hierarchy — Parent/child relationships
- Temporal — Created, modified, accessed timestamps
- Quality — Score, confidence, verification status
- Embedding — Optional vector for semantic search
- Metadata — Tags and custom properties
MemoryTree
The MemoryTree class manages a collection of nodes:
from engram import MemoryTree, ContentType
tree = MemoryTree()
# Add with options
node = tree.add(
"Important information",
content_type=ContentType.TEXT,
tags=["important"],
custom={"source": "manual"},
)
# Hierarchy
parent = tree.add("Parent topic")
child = tree.add("Child detail", parent_id=parent.id)
# Access
tree.get(node.id) # Get by ID
tree.get_all() # All nodes
tree.get_roots() # Root nodes only
tree.get_children(parent.id) # Children of a node
# Search
tree.find_by_tag("important")
tree.find_by_depth(1)
tree.search_text("information")
# With embeddings
import numpy as np
embedding = np.random.rand(384).astype(np.float32)
tree.add("Embedded memory", embedding=embedding)
tree.search_similar(query_embedding, top_k=10)
File I/O
from engram import read_engram, write_engram
# Low-level access
engram_file = read_engram("data.engram")
print(engram_file.header.metadata.source)
print(f"{len(engram_file.nodes)} nodes")
# Modify and save
engram_file.header.metadata.description = "Updated"
write_engram(engram_file, "data.engram")
LangChain Integration
Use Engram as a persistent memory backend for LangChain:
from engram.langchain import EngramMemory
from langchain.chains import ConversationChain
from langchain_openai import ChatOpenAI
# Create persistent memory
memory = EngramMemory(brain_path="chat.engram")
# Use with LangChain
chain = ConversationChain(
llm=ChatOpenAI(),
memory=memory,
)
# Conversations persist across sessions
response = chain.predict(input="Hello!")
# Search conversation history
results = memory.search("Hello")
# Add knowledge for RAG
memory.add_knowledge(
"Engram is a neural memory format.",
tags=["product", "definition"]
)
# Access underlying tree
memory.tree.find_by_tag("conversation")
EngramMemory Options
EngramMemory(
brain_path="chat.engram", # Path to .engram file
memory_key="history", # Key for memory in chain
input_key="input", # Key for human input
output_key="output", # Key for AI output
return_messages=False, # Return Message objects vs string
max_history=10, # Max messages to return
)
Binary Format
The .engram format is a binary file with:
- Magic bytes:
ENGRAM(6 bytes) - Version: Major.Minor (2 bytes)
- Header length: uint32 LE (4 bytes)
- Header: MessagePack-encoded metadata
- Payload: MessagePack-encoded nodes, entities, links
Integrity is verified via SHA-256 hash stored in the header.
Compatibility
The Python SDK is fully compatible with:
@terronex/engram— TypeScript/JavaScript SDKengram-rs— Rust SDK (coming soon)engram-go— Go SDK (coming soon)
All SDKs read and write the same binary format (Engram v1.0).
API Reference
Types
| Type | Description |
|---|---|
MemoryNode |
A single memory with content, hierarchy, and metadata |
Entity |
Named entity extracted from memories |
MemoryLink |
Relationship between nodes |
EngramFile |
Complete file structure |
EngramHeader |
File metadata and configuration |
Enums
| Enum | Values |
|---|---|
ContentType |
text, image, audio, code, summary |
DecayTier |
hot, warm, cold, archive |
EntityType |
person, place, organization, concept, event, document |
LinkType |
related, references, contradicts, supersedes, elaborates, summarizes, causes, follows |
Functions
| Function | Description |
|---|---|
read_engram(path) |
Read an engram file |
write_engram(engram, path) |
Write an engram file |
load(path) |
Shorthand for read_engram |
save(engram, path) |
Shorthand for write_engram |
License
MIT — See LICENSE for details.
Links
Metadata
Release files for terronex-engram 1.0.0
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 | |
|---|---|---|---|---|
| terronex_engram-1.0.0.tar.gz | 20.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| terronex_engram-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.6 kB
Release files / terronex_engram-1.0.0.tar.gz
| Download URL | terronex_engram-1.0.0.tar.gz |
|---|---|
| Size | 20.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
22b4d140dfbeeaec6f0572a53eb5b916743539c78fda77c30c8328e7246e68ee
|
|
BLAKE2b-256 checksum How to use checksums |
f32751c4de8a2e63006f3fedf7d6754fdcf56c9a3b17814b5ca2b3610b7506fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / terronex_engram-1.0.0-py3-none-any.whl
| Download URL | terronex_engram-1.0.0-py3-none-any.whl |
|---|---|
| Size | 17.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f46a70d0657253ffb8e1b04486e0e34181a70ae89cdc5fc14036990663e1344e
|
|
BLAKE2b-256 checksum How to use checksums |
1bed1c3e1af5b79a36089ad53678a69de3bb92457d064529b8b203ad91b95dd5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for terronex-engram 1.0.0
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.