Metadata-Version: 2.4
Name: forktex-data
Version: 0.1.0
Summary: Typed records held as an immutable graph of owned nodes and typed edges, loaded from a directory of JSON, searched by retrieval pipelines, carried in bundles and served over MCP.
License-Expression: AGPL-3.0-or-later OR LicenseRef-ForkTex-Commercial
License-File: LICENSE
License-File: NOTICE
Keywords: data,records,graph,retrieval,bm25,mcp,pydantic
Author: FORKTEX
Author-email: info@forktex.com
Requires-Python: >=3.14,<4.0
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: Indexing
Classifier: Typing :: Typed
Provides-Extra: mcp
Requires-Dist: forktex (>=1.3,<2)
Requires-Dist: mcp (>=2.3,<3) ; extra == "mcp"
Requires-Dist: pydantic (>=2.14,<3)
Project-URL: Bug Tracker, https://github.com/forktex/forktex-data/issues
Project-URL: Changelog, https://github.com/forktex/forktex-data/blob/master/CHANGELOG.md
Project-URL: Documentation, https://github.com/forktex/forktex-data/tree/master/docs
Project-URL: Homepage, https://forktex.com
Project-URL: Repository, https://github.com/forktex/forktex-data
Description-Content-Type: text/markdown

<p align="center">
  <img src="https://raw.githubusercontent.com/forktex/forktex-data/master/docs/assets/data-banner.png" alt="forktex-data" height="120">
</p>

<p align="center">
  <a href="https://pypi.org/project/forktex-data/"><img src="https://img.shields.io/pypi/v/forktex-data.svg" alt="PyPI"></a>
  <a href="https://pypi.org/project/forktex-data/"><img src="https://img.shields.io/pypi/pyversions/forktex-data.svg" alt="Python"></a>
  <a href="https://github.com/forktex/forktex-data/blob/master/LICENSE"><img src="https://img.shields.io/pypi/l/forktex-data.svg" alt="License"></a>
</p>

<p align="center"><em>Working memory for scripts and agents: typed records as one graph, in memory.</em></p>

Your records, typed by JSON declarations, load from a directory or a bundle
into an immutable graph held in your process. Search, walk and pack it into a
token budget with retrieval pipelines that say why each item is there; publish
a knowledge base as one versioned file; and serve it to an agent over MCP.

```bash
pip install forktex-data            # the library
pip install "forktex-data[mcp]"     # and forktex-data-mcp, the bundle server
```

```python
import asyncio

from forktex_data import (
    ConstrainedWalk, Graph, LexicalSeeds, Moves, Pack, Pipeline, RecordCodec, TextIndex, TypeCatalog,
)

types = TypeCatalog()
types.declare_all(
    [
        {
            "$type": "TypeDeclaration",
            "name": "Note",
            "role": "Node",
            "fields": {"title": {"type": "string"}, "body": {"type": ["string", "null"]}},
            "required": ["title"],
            "spec": {"levels": {"brief": ["title"], "full": ["title", "body"]}},
        },
        {"$type": "TypeDeclaration", "name": "cites", "role": "Edge"},
    ]
)

ASK = Pipeline(
    steps=(
        TextIndex(fields={"title": 3, "body": 1}),
        LexicalSeeds(limit=2),
        ConstrainedWalk(moves=Moves(follow={"cites": 1.0}), hops=2),
        Pack(budget_tokens=200, levels=("brief", "full")),
    )
)


async def main() -> None:
    codec = RecordCodec(types)
    graph = Graph(
        types,
        [
            codec.decode({"$type": "Note", "$id": "tides", "title": "Tides", "body": "The sea rises with the moon."}),
            codec.decode({"$type": "Note", "$id": "moon", "title": "The moon", "body": "It keeps its distance."}),
            codec.decode({"$type": "cites", "$id": "c1", "source": "tides", "target": "moon"}),
        ],
    )
    result = await ASK.run(graph, "why does the sea rise")
    for item in result.packed.items:
        print(item.id, item.level, [hop.to for hop in item.path])  # tides full []  /  moon full ['moon']


asyncio.run(main())
```

## Requirements

| | |
|---|---|
| **Python** | 3.14, with or without the GIL |
| **Event loop** | asyncio |
| **Dependencies** | `forktex` and `pydantic`; the `mcp` extra adds the `mcp` SDK. No service of any kind |
| **Data** | JSON records of types you declare, each naming its `$type` and `$id`. Everything is held in memory |

## What you can build

| You want to | Read |
|---|---|
| Declare record types as JSON documents — formats, patterns, inheritance, graph rules | [Declare your types](https://github.com/forktex/forktex-data/blob/master/docs/guide.md#declare-your-types) |
| Load a directory of records as one graph, strictly or leniently | [Load a directory](https://github.com/forktex/forktex-data/blob/master/docs/guide.md#load-a-directory) |
| Search, walk and pack a graph into a token budget, with provenance | [Run a pipeline](https://github.com/forktex/forktex-data/blob/master/docs/guide.md#run-a-pipeline) |
| Scope a walk by type, depth, place and fields, as data | [Admit nodes with a graph filter](https://github.com/forktex/forktex-data/blob/master/docs/guide.md#admit-nodes-with-a-graph-filter) |
| Store a pipeline as JSON and run it again identically | [Store and send a pipeline](https://github.com/forktex/forktex-data/blob/master/docs/guide.md#store-and-send-a-pipeline) |
| Publish a knowledge base as one pinned file a reader opens without your code | [Publish a bundle](https://github.com/forktex/forktex-data/blob/master/docs/guide.md#publish-a-knowledge-base-as-a-bundle) |
| Let Claude, or any MCP client, query a bundle offline | [Serve a bundle over MCP](https://github.com/forktex/forktex-data/blob/master/docs/guide.md#serve-a-bundle-over-mcp) |

## How it works

| Concept | What it is |
|---|---|
| **Record** | A frozen pydantic value with `$type`, `$id` and optionally `$v`: a `Node`, which may be owned by another node, or an `Edge` between two nodes |
| **Type catalogue** | The types you own, each declared at runtime by a `TypeDeclaration` document: its fields, text levels, sibling order and graph rules |
| **Graph** | Every record, built once and never changed: nodes by `$id`, who owns whom, and which edges join what |
| **Pipeline** | A closed list of steps, checked against the graph, then run: choose a text index, seed by BM25, walk weighted moves, pack into a budget. A typed JSON document |
| **Graph filter** | Which nodes a walk may enter — by type, depth, place and fields — as data |
| **Bundle** | A knowledge base as one JSON Lines file: declarations, records, text index, named pipelines, a content hash |
| **Bundle server** | `forktex-data-mcp --bundle PATH`: six read-only MCP tools over stdio, plus your own |

The ideas in ten minutes: [concepts](https://github.com/forktex/forktex-data/blob/master/docs/concepts.md).

## Things to know

| | |
|---|---|
| **It is working memory, not storage** | A graph lives in one process, and nothing is written back. Tables and durable, shared storage are [forktex-grid](https://github.com/forktex/forktex-grid)'s; workflows are forktex-flow's. Persist what you need as record JSON or a bundle |
| **A graph is built once** | There are no updates: build a new graph from the records you want. Any number of tasks may read and run over one at once without a lock |
| **The API is async where it is data-sized** | `load`, `Pipeline.run`, `write_bundle` and `open_bundle` compute on a worker thread, so the event loop is never blocked; lookups are plain calls |
| **Every refusal names every problem** | One `DataError` with `details["problems"]`; a node that is not there raises its subclass `DataNotFoundError` |
| **Documents run no code** | Pipelines, filters, templates and declarations are data; a pipeline names only the four shipped steps |
| **Results are deterministic** | The same records and query give the same bytes, whatever the file order |

## Documentation

| Page | For |
|---|---|
| [Concepts](https://github.com/forktex/forktex-data/blob/master/docs/concepts.md) | How it thinks, in ten minutes |
| [Guide](https://github.com/forktex/forktex-data/blob/master/docs/guide.md) | Runnable files for each way to use it |
| [Reference](https://github.com/forktex/forktex-data/blob/master/docs/reference.md) | Every public name, document and refusal |
| [Operating](https://github.com/forktex/forktex-data/blob/master/docs/operating.md) | Sizes, threads, memory, determinism, serving |

## Stability

Pre-1.0. Semantic versioning covers every name in `forktex_data.__all__` and
`forktex_data.server.__all__`, the JSON documents the library reads and
writes, the bundle format and the bundle server's tools; until 1.0 a minor
version may change them, and the CHANGELOG says how. Changes are listed in the
[CHANGELOG](https://github.com/forktex/forktex-data/blob/master/CHANGELOG.md).

## Contributing

Working on `forktex-data` itself? Start with
[`docs/development.md`](https://github.com/forktex/forktex-data/blob/master/docs/development.md).
Security issues go to the address in
[SECURITY.md](https://github.com/forktex/forktex-data/blob/master/SECURITY.md).

## Licence

AGPL-3.0-or-later, or a commercial licence from FORKTEX S.R.L.
(info@forktex.com). See [LICENSE](https://github.com/forktex/forktex-data/blob/master/LICENSE) and
[NOTICE](https://github.com/forktex/forktex-data/blob/master/NOTICE).

