Skip to main content

Macrame

CI Python crates.io docs.rs PyPI Python versions MSRV License

A bitemporal graph ledger for knowledge management — embedded, single-file, no server.

Macrame stores concepts linked by typed, weighted relationships — where both concepts and relationships change over time, and the history of those changes is itself a first-class asset. Everything lives in one .db file on disk. No database server, no network protocol, no external service.


Why Macrame

Strength What it means
Bitemporal by design Two independent clocks per row — valid time (when a fact held in the world) and transaction time (when the database learned it). as_of(ts) answers "what did the world look like?" and reconstruct(ts) answers "what did we believe?" — both correct, both different.
Single file, embedded The entire database is one file on the local filesystem. Link it directly into your application. Run on Windows desktop, Linux, or macOS — the Rust suite runs on all three in CI.
Graph + vectors + search Recursive CTE traversal, native DiskANN vector search, FTS5 keyword search, and hybrid RRF fusion — all in one crate, no external graph library.
Five in-memory analytics Dijkstra, A*, SCC, k-core, and Louvain — operating on a typed Subgraph with zero external dependencies.
Rebuildable materialization links_current is a cache of current belief, always rebuildable from the append-only transaction_log. Drift is detectable by audit, recoverable by atomic or chunked rebuild.
Archival path Closed intervals move to a cold database inside atomic sessions. Point-in-time reconstruction composes from snapshots plus anchored folds — fast because it doesn't fold from genesis.
Runtime safety One Write Actor serialises all writes; read connections carry PRAGMA query_only = ON enforced at the engine level. No raw SQL escapes the guard.

Quick Start

Rust

[dependencies]
macrame-db = "0.8"
use macrame::prelude::*;

async fn main() {
    let db = Database::open("knowledge.db").await?;

    db.upsert_concept(ConceptUpsert::new("quantum", "Quantum Computing")
        .valid_from("2026-01-01T00:00:00.000000Z"))
        .await?;

    db.upsert_concept(ConceptUpsert::new("entanglement", "Quantum Entanglement")
        .valid_from("2026-01-01T00:00:00.000000Z"))
        .await?;

    db.assert_edge(EdgeAssertion::new("quantum", "entanglement", "ENTAILS")
        .valid_from("2026-01-01T00:00:00.000000Z")
        .weight(1.0))
        .await?;

    let subgraph = db.traverse()
        .start_node("quantum")
        .max_depth(3)
        .execute(db.read_conn(), None)
        .await?;
}

Python

pip install macrame-db
import macrame

T0 = "2026-01-01T00:00:00.000000Z"

with macrame.Database.open("knowledge.db") as db:
    db.write_concepts([
        macrame.ConceptUpsert("quantum", "Quantum Computing", valid_from=T0),
        macrame.ConceptUpsert("entanglement", "Quantum Entanglement", valid_from=T0),
    ])
    db.assert_edge(
        macrame.EdgeAssertion("quantum", "entanglement", "ENTAILS", valid_from=T0)
    )
    graph = db.load_subgraph("quantum", 3, 1 << 20)
    print(graph.dijkstra("quantum"))

Architecture Highlights

Eight Doctrine Invariants

Every design decision derives from these invariants:

  1. The boundary is sacred — Everything above libSQL is ours; everything below it is upstream. Never patch the engine.
  2. Two clocks, never mixed — Valid time and transaction time are independent axes. No code path derives one from the other.
  3. Assertions are immutable — Rows in links are never updated in place. The past is never rewritten; it is only ever superseded.
  4. The ledger is a table, not the log — Transaction-time reconstruction reads transaction_log, not WAL or CDC frames.
  5. No physical deletion in hot tables — Rows leave through the archive path only. Ad-hoc DELETE aborts at the trigger layer.
  6. Derivative state is disposablelinks_current is a rebuildable materialization. Drift is detectable, recoverable by rebuild.
  7. Embeddings are immutable per version, excluded from the ledger — Vectors live in per-model tables; they never appear in transaction_log payloads.
  8. Fidelity is a parameter, never a silent defaultas_of(ts) and reconstruct(ts) say what they mean in their signatures.

Concurrency Model

  • One writer — a dedicated Tokio task holds the sole write-capable connection
  • Many readers — WAL journaling; readers never block on writer
  • Two-tier priority channels — high-priority (user-driven) preempts low-priority (background)
  • Cooperative chunking — bounded to ~3 ms per chunk, four paths with different row counts (90 edges, 70 concepts, 600 annotations, 30 embeddings)

Schema Versioning

Version Feature
v2 Legacy-free baseline
v3 analytics_annotations table
v4 FTS5 external-content index
v5 Overlap guard index
v6 Overlapping closed intervals refused in actor
v7 CHECK (weight >= 0.0) on links.weight
v8 concepts.rowid_pk, the third FTS trigger, and the two unread indices dropped — current

v8 is the last rung before the 1.0 freeze that could take it: rowid_pk INTEGER PRIMARY KEY costs id the primary key, and D-036 forbids a primary-key change after 1.0 (D-119). It also drops idx_annotations_label and idx_lc_tgt_active, which shipped in the v7 baseline with no query that seeks on them — measured at −7.9% off assert_edge (D-089, D-118).


Rust Implementation

Detail Value
Edition Rust 2021
MSRV 1.88 (verified, not declared)
Runtime tokio async, single process
Engine libSQL 0.9.30 (MIT, unmodified)
Schema version 8
Test suite 296 Rust · 305 with metrics · 316 with property-tests · 344 Python — all green (measured 2026-08-02)
Dependencies tokio, serde, bincode, zstd, thiserror, tracing, ulid

Module Map

Module Responsibility
schema DDL, triggers, migrations
graph CTE compilation, subgraph loading, vector filters
temporal as_of(), reconstruct(), snapshots, archive
vector Model registration, embedding upsert, DiskANN search, hybrid RRF
integrity Audit, atomic rebuild, chunked shadow-swap rebuild
connection Database handle, Write Actor, priority channels
error DbError enum, error classification

Python Bindings (v0.8.0)

Detail Value
Engine pyo3 0.29 + maturin
Surface Synchronous (Write Actor serialises all writes)
GIL Released via Python::detach around Runtime::block_on
Distribution macrame-db on PyPI, import macrame
Wheels abi3-py310 — one per platform (Linux x86_64/aarch64, macOS universal2, Windows x86_64)
Python CPython 3.10+
Type stubs Ship with wheel, py.typed set, mypy --strict in CI

Key design decisions

  • Synchronous surface — The Write Actor serialises every write through one channel, so exposing await advertises concurrency the architecture does not grant.
  • Opaque Subgraph — A #[pyclass] with forwarded accessors; .to_dict() for callers who want the copy. It paid for itself in 0.8.0: the crate re-represented EdgeRef and no binding signature moved, because there is no converted copy whose layout had to follow (D-101, D-123).
  • Open intervals cross as None — Not a sentinel datetime, because datetime.max cannot survive .astimezone() east of UTC.
  • Absent content crosses as Noneload_subgraph does not fetch document text unless asked (content=True). "" cannot mark not loaded, because it is a valid value of the type (D-116, D-123).
  • Every error is typed — 35 exception classes under MacrameError, with six intermediate groups for catching sets: IntegrityError, ValidationError, VectorError, TemporalError, WriterError, BudgetError.
  • metrics shipped on — The wheel ships with the metrics feature enabled because feature flags do not survive into binary artifacts.

Performance (measured, not gated)

Re-measured at 0.8.0, because B2 changed how a Subgraph is represented, B3 changed what a load carries, and B4 dropped an index — three reasons a table of 0.7.0 numbers would have been describing a different crate.

Operation Budget 0.7.0 0.8.0
Single assertion ≤ 5 ms 258 µs, and still O(out-degree), not O(1) (D-059)
Chunk commit (edges, 90 rows) ≤ 3 ms 2.39 ms 2.40 ms
Three-hop traversal ≤ 10 ms 2.1 ms 1.66 ms
Vector top-10 ≤ 20 ms 294 µs 246 µs
Hybrid top-10 ≤ 50 ms 2.0 ms 1.77 ms
Full fold (reconstruct) ≤ 100 ms 21 ms 16.9 ms
Composition (snapshot + delta) ≤ 100 ms 3.4 ms 2.18 ms

Two controls, or the read-path numbers would mean nothing. A uniform improvement across unrelated paths is what a faster machine looks like, so: the fixed control/select_1 row reads 1.51–1.62 µs against the 1.589–1.639 µs D-090 recorded, and the chunk-commit path — which 0.8.0 did not touch — is 2.39 → 2.40 ms. The machine has not moved and an untouched path has not moved, so the 12–36% on the read paths is the code.

The single-assertion row is a fixture measurement and the caveat is the load-bearing part: it is under budget on this fixture and remains linear in out-degree, so a high-degree hub still exceeds it. Dropping idx_lc_tgt_active bought −7.9% on that path (D-118); it did not change the complexity.

All budgets measured on named reference hardware, and deliberately not CI gates (D-055) — an absolute ≤ 5 ms on a shared runner is an assertion about whichever machine picked up the job. Regression detection uses criterion baselines, machine against itself. See §9 of the architecture docs for full table.


Known Risks

Risk Mitigation
R15: Concurrent open → access violation (libSQL 0.9.30) One open per database; R15 reproduces transparently through Python
Property test binaries fault mid-suite property-tests feature gate; serialised runs; CI classifies each run rather than counting failures, and retries only a crash
Covering index wins over selective EXPLAIN QUERY PLAN assertions on every index-sensitive query
Snapshot chain divergence verify_snapshot_chain() reports but does not repair (snapshots are disposable)

Minimum Supported Rust Version

1.88, verified rather than declared — cargo +1.88.0 check --all-features --all-targets passes and 1.85 does not. The constraint comes from libsql-ffi's build dependency chain (bindgen → which → home), not from this crate's own code (which needs only 1.73).


Documentation


Naming

Distribution macrame-db, import macrame — on both crates.io and PyPI. The Rust side has no caveat: a crate's [lib] name is namespaced per build graph, so macrame-db providing macrame collides with nothing. site-packages is flat.

The PyPI package macrame is an unrelated, effectively abandoned build tool (0.0.1, 2021). If it installs a top-level macrame/, then installing both leaves two distributions contending for one directory — pip warns on file conflicts, so this is a known and non-silent risk. Importing as macrame_db is the fallback if it ever matters.


License

See LICENSE for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

macrame_db-0.8.0.tar.gz (939.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

macrame_db-0.8.0-cp310-abi3-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.10+Windows x86-64

macrame_db-0.8.0-cp310-abi3-manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

macrame_db-0.8.0-cp310-abi3-manylinux_2_28_aarch64.whl (4.8 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

macrame_db-0.8.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.0 MB view details)

Uploaded CPython 3.10+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file macrame_db-0.8.0.tar.gz.

File metadata

  • Download URL: macrame_db-0.8.0.tar.gz
  • Upload date:
  • Size: 939.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for macrame_db-0.8.0.tar.gz
Algorithm Hash digest
SHA256 0588f35422c8ceeecad1190e23dfbc0443eedea4b16faf7dd6f833eb6892f455
MD5 8ea7957985951d5343f497b698eacf5a
BLAKE2b-256 2b9d369e8679bc8d16f15bba315910c681f56b77326e2a69a7da3968cd3e50cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for macrame_db-0.8.0.tar.gz:

Publisher: wheels.yml on opticsWolf/Macrame

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file macrame_db-0.8.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: macrame_db-0.8.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for macrame_db-0.8.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c32d3629f0ccc663faf6cad6792d5783715976141e97cd7ea510d3c98e29b676
MD5 97d003009f11a706c07945fc147c3772
BLAKE2b-256 f36ba403ee157e3034d32b3e45a1cb39dea101a852288af5185b6019737fc8f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for macrame_db-0.8.0-cp310-abi3-win_amd64.whl:

Publisher: wheels.yml on opticsWolf/Macrame

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file macrame_db-0.8.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for macrame_db-0.8.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 82396eea4ba72784a0474f26ea926caa36a63c30f1fdaa1a5f7935f0c95d55eb
MD5 c473524650803b5ab2f04d812504bf97
BLAKE2b-256 ef66bfe8c4ffb6d32a30dc29cfe0c281579e06ae7ddd8f3b8abf71c9756a3ccb

See more details on using hashes here.

Provenance

The following attestation bundles were made for macrame_db-0.8.0-cp310-abi3-manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on opticsWolf/Macrame

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file macrame_db-0.8.0-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for macrame_db-0.8.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7e79b3d244e5fc55123d34b2be75673c944e3940648ecf686b85eefe862210e0
MD5 d7806ef867bc383381fbec16d6a9e6d2
BLAKE2b-256 3179ec458f7163bad7c78abdcf5e55998bb84d54db225c24205e60599b938017

See more details on using hashes here.

Provenance

The following attestation bundles were made for macrame_db-0.8.0-cp310-abi3-manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on opticsWolf/Macrame

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file macrame_db-0.8.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for macrame_db-0.8.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 9c8607dd1841c3a2f322ee06007aa83bf4a1a3830b56d9aa3c22b231f2b46f70
MD5 1242db071b420280c19f989f1eaabdf7
BLAKE2b-256 ee13ec2a701e4425f009e915297e91b5bacb83f1b8c7e6c35f60b7f30a74428d

See more details on using hashes here.

Provenance

The following attestation bundles were made for macrame_db-0.8.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: wheels.yml on opticsWolf/Macrame

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.17.0

5 files

0.16.0

5 files

0.15.0

5 files

0.14.0

5 files

0.13.0

5 files

0.12.0

5 files

0.11.0

5 files

0.10.0

5 files

0.9.0

5 files

This release

0.8.0 This release

5 files

0.7.0

5 files

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