> ## Documentation Index
> Fetch the complete documentation index at: https://docs.magpiedb.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Magpie is a trace store for AI agents, used as a library (crate `magpiedb`, npm `magpiedb`, PyPI `magpiedb`) or as `magpie-server`, which takes OpenTelemetry (OTLP over HTTP on 127.0.0.1:4318 and gRPC on 127.0.0.1:4317 by default).
> Use only the commands, flags, routes and JSON shapes that these pages show. Do not guess a flag or a query field: if a page does not show it, say that the docs do not show it.
> Install the library with `cargo add magpiedb`, `npm install magpiedb` or `pip install magpiedb`. Get the server from the GitHub Releases download or the Docker image `ghcr.io/intojhanurag/magpie-server`, as the quick start shows.
> Only one process may write to a store folder at a time. For many apps, send traces to one `magpie-server`.
> `magpie-server doctor` checks a running server. An AI agent can query the traces over MCP at `/mcp` on the HTTP port (page guides/mcp).

# Use Magpie as a library

> Install magpiedb for Node.js, Python or Rust, open a store in your app, set its options, and close it.

```sh Node.js theme={null}
npm install magpiedb
```

```sh Python theme={null}
pip install magpiedb
```

```sh Rust theme={null}
cargo add magpiedb
```

`magpiedb` runs inside your app, like SQLite: there is no server. A store is one folder. Node.js, Python and Rust call the same engine and take the same JSON shapes as the [server query API](https://docs.magpiedb.com/queries/overview.md). The import name is `magpiedb` in every language (the name `magpie` is taken on PyPI by another project).

| | Node.js | Python | Rust |
| - | - | - | - |
| Prebuilt binary | macOS arm64 and x64; Linux x64 and arm64 with glibc 2.17 or newer | macOS arm64 and x64; Linux x64 and arm64 (manylinux) | Cargo compiles the crate |
| Other systems | Windows and Linux with musl (Alpine): build from source | pip builds the source package, which needs Rust (stable) | |
| Runtime | Node 18 or newer | CPython 3.9 or newer (one abi3 wheel); no wheel for the free-threaded build | Rust (stable) |

> [accordion] Build from source
>
> `REPO` is the folder of a clone of [the repo](https://github.com/intojhanurag/magpie). You need Rust (stable); for Node.js also Node 24, for Python also [`uv`](https://docs.astral.sh/uv/).
>
> ```sh Node.js theme={null}
> (cd "$REPO/bindings/node" && npm ci && npm run build)
> npm install "$REPO/bindings/node"       # in the folder of your app
> ```
>
> ```sh Python theme={null}
> cd "$REPO/bindings/python"
> uv venv --clear .venv && uv pip install --python .venv/bin/python "maturin>=1.9.4,<2"
> .venv/bin/maturin develop --release --uv   # builds the module and installs it into .venv
> # run your app with "$REPO/bindings/python/.venv/bin/python"
> ```
>
> ```sh Rust theme={null}
> cargo add magpiedb --path "$REPO/crates/core"
> ```
>
> The first build compiles the engine (some minutes). Tests and wheels: [Node.js](https://docs.magpiedb.com/libraries/node.md#build-and-test), [Python](https://docs.magpiedb.com/libraries/python.md#build-and-test).

## Open a store

```js Node.js theme={null}
import { Store } from 'magpiedb'

const store = await Store.open('./traces')
// write and query
await store.close()
```

```python Python theme={null}
from magpiedb import Store

with Store.open("./traces") as store:  # the with block calls close()
    ...  # write and query
```

```rust Rust theme={null}
use magpiedb::{Options, Store};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let store = Store::open("traces", Options::default())?;
    // write and query
    store.close()?;
    Ok(())
}
```

`Store.open` opens the store in the folder, or makes a new one. `close` commits what is left, waits for merges and frees the folder for another writer. In Node.js and Python, a call after `close` fails; in Rust, `close` takes the store. The examples on the next pages use an open `store`.

## Only one process writes

> [!WARNING]
>
> One process at a time may write to a store folder: a second writer is refused. Other processes can open the folder read-only. For many apps, send traces to one [`magpie-server`](https://docs.magpiedb.com/library-or-server).

```js Node.js theme={null}
const reader = await Store.open('./traces', { readOnly: true })
await reader.refresh() // see the newest commit now
```

```python Python theme={null}
reader = Store.open("./traces", read_only=True)
reader.refresh()  # see the newest commit now
```

```rust Rust theme={null}
let reader = Store::open("traces", Options { read_only: true, ..Default::default() })?;
reader.refresh()?; // see the newest commit now
```

A read-only store also picks up new commits on its own, within about 0.5 s.

## Set options

```js Node.js theme={null}
const store = await Store.open('./traces', { durability: 'os', commitInterval: 1000, retentionMs: 30 * 86400000 })
```

```python Python theme={null}
store = Store.open("./traces", durability="os", commit_interval=1000, retention_ms=30 * 86_400_000)
```

```rust Rust theme={null}
use std::time::Duration;
use magpiedb::Durability;

let store = Store::open("traces", Options {
    durability: Durability::Os,
    commit_interval: Some(Duration::from_millis(1000)),
    retention: Some(Duration::from_secs(30 * 86_400)),
    ..Default::default()
})?;
```

Node.js takes an options object, Python takes keyword arguments, Rust takes the fields of `Options`. Times are milliseconds in Node.js and Python, and a `Duration` in Rust.

| Node.js | Python and Rust | Default | What it does |
| - | - | - | - |
| `durability` | `durability` | `'disk'` | What a write that returned survives: `'none'` (no write log), `'os'` (a crash of the process), `'disk'` (a crash of the machine). See [durability](https://docs.magpiedb.com/operations/durability-upgrades.md). |
| `commitInterval` | `commit_interval` | 500 ms | Time from the first uncommitted write to an automatic commit. `null` or `None`: no timer. |
| `readOnly` | `read_only` | `false` | Open without a writer. Many read-only processes can open one store. |
| `retentionMs` | `retention_ms` (Rust: `retention`) | not set: keep all | Keep spans this long. See [retention](https://docs.magpiedb.com/libraries/delete-maintenance.md#drop-old-spans). |
| `prices` | `prices` | not set | A price table: see [cost](https://docs.magpiedb.com/libraries/write-spans.md#compute-cost-from-a-price-table). |
| `mask` | `mask` | not set | A mask policy: see [masking](https://docs.magpiedb.com/libraries/write-spans.md#mask-private-data). |
| `compression` | `compression` | `{ zstd: 9 }` | `'lz4'` or `{ zstd: level }`, level 1 to 22. For the files this writer writes; old files stay readable. |
| `docstoreBlockBytes` | `docstore_block_bytes` | 1048576 | Stored spans are compressed in blocks of about this size. A bigger block makes the store smaller; a read of one span decompresses its whole block. |
| `pieces` | `pieces` | `false` | Keep a repeated piece (about 1 KB) of a long text once, when an earlier span of the same trace and hour has it. A store opens with either value. |
| `maxQueuedBytes` | `max_queued_bytes` | 256 MiB | `write` waits when this many bytes are accepted but not yet indexed. |
| `writerHeapBytes` | `writer_heap_bytes` | 256 MiB | Memory the writer may use before it flushes a segment. |
| `indexingThreads` | `indexing_threads` | 1 | Threads that build the index. |
| `clusterByTrace` | `cluster_by_trace` | `false` | Keep every segment sorted by trace. Chosen when the store is made. |
| `finalSegmentBytes` | `final_segment_bytes` | 1 GiB | A segment with more span text than this is not merged again. |
| `traceCacheSpans` | `trace_cache_spans` | 500000 | Spans of recent traces that the writer remembers. |
| not available | Rust only: `min_free_bytes` | 5% of the volume, at least 16 MiB, at most 1 GiB | The free space that writes keep on the volume. `Some(0)`: no reserve. See [errors](https://docs.magpiedb.com/libraries/errors.md). |

In Rust, `durability` is `Durability::None`, `Os` or `Disk`, and `compression` is `Compression::Lz4` or `Compression::Zstd(level)`.

## How calls run

| | Node.js | Python | Rust |
| - | - | - | - |
| A call | Returns a Promise. The work runs on a worker thread, not on the JavaScript thread. | Blocks until the engine is done. It releases the GIL: other threads run, and calls from many threads run at the same time. | A method that returns a `Result`. |
| With async code | `await` each call | No asyncio API: use `await asyncio.to_thread(store.search, query)` | |
| Names | camelCase: `findTraces`, `traceId` | snake\_case methods, camelCase keys: `find_traces`, `"traceId"` | snake\_case: `find_traces`, `trace_id` |
| JSON values | `true`, `null` | `True`, `None` | typed structs, `Option` |
| Types | `index.d.ts` | `magpiedb/__init__.pyi` | `cargo doc -p magpiedb --open` |

## What each language has

The task pages show every call in all three languages. These parts are not the same:

| Feature | Node.js | Python | Rust |
| - | - | - | - |
| Close with a block | no | `with Store.open(...)` | no |
| Integers above 2^53 | an error | exact | exact |
| `health()`: can the store take writes | no | no | yes |
| `refused_writes()`: writes refused for lack of disk space | no | no | yes |
| `segments()`: the segments, their sizes and time ranges | no | no | yes |
| `on_commit(f)`: a hook for each commit (an uploader) | no | no | yes |
| `open_on(spans, traces)`: open read-only on two folders, for a store on S3 | no | no | yes |
| Option `min_free_bytes` | no (the default) | no (the default) | yes |

Method lists: [Node.js](https://docs.magpiedb.com/libraries/node.md), [Python](https://docs.magpiedb.com/libraries/python.md), [Rust](https://docs.magpiedb.com/libraries/rust.md).

> [card] [Write spans](https://docs.magpiedb.com/libraries/write-spans.md)
>
> Write, replace and commit spans.

> [card] [Query from your app](https://docs.magpiedb.com/libraries/query.md)
>
> Search text, find traces, add up tokens and cost.

> [card] [Errors and input rules](https://docs.magpiedb.com/libraries/errors.md)
>
> What each language raises, and why.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.