This library builds a graph (entities and relations) incrementally, and stores them in append-only logs. Now supports optional community tagging.
Table of Contents
Architecture
The library follows a modular architecture with the following components:
Core Components
-
GraphBuilder
- Main class for building and managing the graph.
- Supports incremental entity and relation updates.
- Maintains append-only logs for all changes.
- Integrates with configurable indexers for efficient lookups.
-
GraphCompactor
- Processes the append-only logs to create compacted representations.
- Merges entity updates based on timestamps.
- Builds adjacency lists for efficient graph traversal.
- Supports sharding for large datasets.
-
Indexers
- Abstract interface for entity indexing
- Implementations:
SQLiteIndexer: Persistent storage using SQLiteMemoryIndexer: In-memory storage with JSON serialization
Architecture Diagram
graph TD
subgraph "Graph Builder"
GB[GraphBuilder] --> |add_entity| EL[Entity Log]
GB --> |add_relation| RL[Relation Log]
GB --> |index| IDX[Indexer]
end
subgraph "Graph Compactor"
GC[GraphCompactor] --> |read| EL
GC --> |read| RL
GC --> |write| ES[Entity Shards]
GC --> |write| AL[Adjacency Lists]
end
subgraph "Storage"
EL --> |append-only| LOGS[Logs]
RL --> |append-only| LOGS
IDX --> |persist| DB[(SQLite DB)]
ES --> |sharded| STORAGE[Storage]
AL --> |compacted| STORAGE
end
classDef primary fill:#E6D5AC,stroke:#D4B483,stroke-width:2px,color:#000
classDef secondary fill:#D4E6AC,stroke:#B4D483,stroke-width:2px,color:#000
classDef storage fill:#ACD4E6,stroke:#83B4D4,stroke-width:2px,color:#000
class GB,GC primary
class EL,RL,ES,AL secondary
class LOGS,DB,STORAGE storage
Storage Structure
output_dir/
├── entities/ # Compacted entity shards
├── relations/ # Relation data
├── logs/ # Append-only update logs
│ ├── entity_updates.jsonl
│ └── relation_updates.jsonl
├── adjacency/ # Compacted adjacency lists
└── index.db # SQLite index (if using SQLiteIndexer)
Data Model
- Entities: Nodes in the graph with properties
- Relations: Directed edges between entities with properties
- Updates: Timestamped changes to entities and relations
- Shards: Partitioned storage for efficient processing
Usage
Basic Usage
from graph_builder.storage_manager import GraphBuilder
from graph_builder.config import GraphBuilderConfig
config = GraphBuilderConfig(output_dir="graph_output")
graph = GraphBuilder(config)
# Ingest entities with optional community
graph.add_entity(1, {"name": "Alice", "type": "Person", "community_id": "team_alpha"})
graph.add_entity(2, {"name": "Bob", "type": "Person", "community_id": "team_alpha"})
# Create a relation
graph.add_relation(100, 1, 2, {"type": "FRIENDS_WITH"})
graph.finalize()
Compaction
from graph_builder import GraphCompactor
# Compact the graph data
compactor = GraphCompactor(base_dir="graph_output")
compactor.compact_entities() # Merge entity updates
compactor.build_adjacency() # Build adjacency lists
Features
- Incremental Updates: Support for timestamped updates to entities and relations
- Efficient Storage: Append-only logs with periodic compaction
- Flexible Indexing: Choose between SQLite or in-memory indexing
- Sharding: Support for large datasets through sharding
- Timestamp Tracking: All changes are tracked with UTC timestamps
Installation
pip install graph-builder
Requirements
- Python 3.12+
- SQLite3 (for SQLiteIndexer)
License
MIT License
Metadata
Release files for graph-builder 0.2.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 | |
|---|---|---|---|---|
| graph_builder-0.2.0.tar.gz | 12.8 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| graph_builder-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.4 kB
Release files / graph_builder-0.2.0.tar.gz
| Download URL | graph_builder-0.2.0.tar.gz |
|---|---|
| Size | 12.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d22b80a64666a532fe7604a9d9145fb82f3a1871cd55259378bcfc166d90019e
|
|
BLAKE2b-256 checksum How to use checksums |
6d2a3cbd3db94a0aecd13eeae9ce6db5f7f2c0d54a3cab359f2974fa86b5ffbb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 23, 2025.
Transparency logRelease files / graph_builder-0.2.0-py3-none-any.whl
| Download URL | graph_builder-0.2.0-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a1082b77224abc60baaaed4bdded089af7a6c09622933023d7b856c83546a139
|
|
BLAKE2b-256 checksum How to use checksums |
c0853581bd06e92c3b6c79ec799f2c07e4b7fb580c7e05f1e69d4be7b0ceb43b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 23, 2025.
Transparency logSecurity for graph-builder 0.2.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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for graph_builder-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 23, 2025.
Transparency logA 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.