Skip to main content

Roam Research Python client with built-in CLI and MCP server support.

Project description

roamresearch-client-py

Roam Research client. Programmable. CLI. SDK. MCP.

For developers who automate. For LLMs that need graph access. Smart diff keeps UIDs intact. References survive. Minimal API calls.

Install

pip install roamresearch-client-py

# standalone
uv tool install roamresearch-client-py

Setup

export ROAM_API_TOKEN="your-token"
export ROAM_API_GRAPH="your-graph"

Or rr init creates ~/.config/roamresearch-client-py/config.toml:

[roam]
api_token = "your-token"
api_graph = "your-graph"

[mcp]
host = "127.0.0.1"
port = 9000
topic_node = ""

[batch]
size = 100
max_retries = 3

[logging]
level = "WARNING"
httpx_level = "WARNING"

Env vars take precedence.

CLI

Get

rr get "Page Title"
rr get "((block-uid))"
rr get "Page Title" --debug

Search

rr search "keyword"
rr search "term1" "term2"
rr search "term" --tag "#TODO"
rr search --tag "[[Project]]"
rr search "term" --page "Page" -i -n 50

Save

Create or update. Preserves UIDs.

rr save -t "Page" -f content.md
echo "# Hello" | rr save -t "Page"

Refs

rr refs "Page Title"
rr refs "block-uid"

Todos

rr todos
rr todos --done
rr todos --page "Work" -n 100

Query

rr q '[:find ?title :where [?e :node/title ?title]]'
rr q '[:find ?t :in $ ?p :where ...]' --args "Page"

MCP

rr mcp
rr mcp --port 9100
rr mcp --token <T> --graph <G>

SDK

Connect

from roamresearch_client_py import RoamClient

async with RoamClient() as client:
    pass

async with RoamClient(api_token="...", graph="...") as client:
    pass

Write

async with client.create_block("Root") as blk:
    blk.write("Child 1")
    blk.write("Child 2")
    with blk:
        blk.write("Grandchild")
    blk.write("Child 3")

Read

page = await client.get_page_by_title("Page")
block = await client.get_block_by_uid("uid")
daily = await client.get_daily_page()

Search

results = await client.search_blocks(["python", "async"], limit=50)
todos = await client.search_by_tag("#TODO", limit=50)
refs = await client.find_references("block-uid")
refs = await client.find_page_references("Page Title")
todos = await client.search_todos(status="TODO", page_title="Work")

Update

await client.update_block_text("uid", "New text")

result = await client.update_page_markdown("Page", "## New\n- Item", dry_run=False)
# result['stats'] = {'creates': 0, 'updates': 2, 'moves': 0, 'deletes': 0}
# result['preserved_uids'] = ['uid1', 'uid2']

Query

result = await client.q('[:find ?title :where [?e :node/title ?title]]')

Batch

Atomic operations.

from roamresearch_client_py.client import (
    create_page, create_block, update_block, remove_block, move_block
)

actions = [
    create_page("New Page"),
    create_block("Text", parent_uid="page-uid"),
    update_block("uid", "Updated"),
    move_block("uid", parent_uid="new-parent", order=0),
    remove_block("old-uid"),
]
await client.batch_actions(actions)

MCP Tools

Tool Description
save_markdown Create/update page
get Fetch as markdown
search Text + tag search
query Raw Datalog
find_references Block/page refs
search_todos TODO/DONE items
update_markdown Smart diff update
{"title": "Notes", "markdown": "## Topic\n- Point"}
{"terms": ["python"], "tag": "TODO", "limit": 20}
{"identifier": "Page", "markdown": "## New", "dry_run": true}

Internals

Smart Diff — Match by content. Preserve UIDs. Detect moves. Minimize calls.

Markdown ↔ Roam — Bidirectional. Headings, lists, tables, code, inline.

Task Queue — SQLite. Background. Retry. JSONL logs.

Requirements

  • Python 3.10+
  • Roam API token

License

MIT

Project details


Download files

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

Source Distribution

roamresearch_client_py-0.3.4.tar.gz (34.1 kB view details)

Uploaded Source

Built Distribution

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

roamresearch_client_py-0.3.4-py3-none-any.whl (37.7 kB view details)

Uploaded Python 3

File details

Details for the file roamresearch_client_py-0.3.4.tar.gz.

File metadata

  • Download URL: roamresearch_client_py-0.3.4.tar.gz
  • Upload date:
  • Size: 34.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for roamresearch_client_py-0.3.4.tar.gz
Algorithm Hash digest
SHA256 9480fd856461a8bc9887ea97a5280db77c024104a3a15783902e08ee4ecc9e0d
MD5 331eb0726ff3c6be48458e8178091fa9
BLAKE2b-256 925d7c4d28186a452d4fc2628b1e55c232bcbf016a3de163f4339e440ce5bca8

See more details on using hashes here.

Provenance

The following attestation bundles were made for roamresearch_client_py-0.3.4.tar.gz:

Publisher: release-from-pr-comment.yml on Leechael/roamresearch-client-py

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

File details

Details for the file roamresearch_client_py-0.3.4-py3-none-any.whl.

File metadata

File hashes

Hashes for roamresearch_client_py-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8e1637cf9fb9b6d4289c9aac52ab4c2aba40ecb04cd765c36ce3ddd1b81185fe
MD5 1b662a47324b244fa290f6b54fb95b0e
BLAKE2b-256 1c598c9bafe8f7f7cdc9d5bf661fbc0accc46f58cffd6eec59de4f2216055a08

See more details on using hashes here.

Provenance

The following attestation bundles were made for roamresearch_client_py-0.3.4-py3-none-any.whl:

Publisher: release-from-pr-comment.yml on Leechael/roamresearch-client-py

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page