Skip to main content

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

Project description

roamresearch-client-py

This is another Roam Research Python Client with opinionated design.

Highlight:

  • Built-in CLI & MCP supports which should be LLM & Agent friendly.
  • Pythonic coding API for building templates.

Installation

# Install from PyPI
pip install roamresearch-client-py

# Or with uv as a CLI tool
uv tool install roamresearch-client-py

Configuration

Environment Variables

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

Configuration File

Run rr init to create a config file at ~/.config/roamresearch-client-py/config.toml:

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

[logging]
level = "WARNING"        # DEBUG, INFO, WARNING, ERROR, CRITICAL
httpx_level = "WARNING"  # Control httpx library logging

CLI Usage

# Initialize config file
rr init

# Get a page by title
rr get "Page Title"

# Get a block by uid
rr get "((block-uid))"

# Search blocks
rr search "keyword"
rr search "term1" "term2" --ignore-case --limit 50

# Save markdown to Roam as a new page
rr save --title "New Page" --file content.md
echo "# Hello" | rr save --title "New Page"

# Update existing page or block (smart diff, preserves UIDs)
rr update "Page Title" --file updated.md
rr update "Page Title" --file updated.md --dry-run  # Preview changes
rr update "((block-uid))" --file content.md
echo "new content" | rr update "Page Title" --force

# Execute raw datalog query
rr q '[:find ?title :where [?e :node/title ?title]]'

# Start MCP server
rr mcp
rr mcp --port 9100

Python API

Create Blocks

from roamresearch_client_py import RoamClient

async with RoamClient() as client:
    async with client.create_block("This is title") as blk:
        blk.write("Line 1")
        blk.write("Line 2")
        with blk:
            blk.write("Indented Line 3")
        blk.write("Back to normal")
# Everything saves in batch when exiting

Query and Search

async with RoamClient() as client:
    # Get page by title
    page = await client.get_page_by_title("My Page")

    # Get block by uid
    block = await client.get_block_by_uid("block-uid")

    # Search blocks
    results = await client.search_blocks(["keyword"], limit=20)

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

Update Existing Content

async with RoamClient() as client:
    # Update a single block's text
    result = await client.update_block_text(
        uid="block-uid",
        text="Updated content",
        dry_run=False  # Set True to preview without executing
    )

    # Update entire page with smart diff (preserves block UIDs)
    result = await client.update_page_markdown(
        title="Page Title",
        markdown="## New content\n- Item 1\n- Item 2",
        dry_run=False
    )

    # Result contains stats and preserved UIDs
    print(result['stats'])  # {'creates': 0, 'updates': 2, 'moves': 0, 'deletes': 0}
    print(result['preserved_uids'])  # List of reused block UIDs

MCP Server

The built-in MCP server exposes Roam Research tools for AI assistants.

# Start SSE MCP server (default port 9000)
rr mcp

# With custom settings
rr mcp --port 9100 --token <TOKEN> --graph <GRAPH>

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.0.tar.gz (27.4 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.0-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: roamresearch_client_py-0.3.0.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.26.2 CPython/3.12.1 Darwin/25.0.0

File hashes

Hashes for roamresearch_client_py-0.3.0.tar.gz
Algorithm Hash digest
SHA256 24f96e8041b676b541f6575c19a8d94554d517a3022f3ea109496e2385b30462
MD5 5e5c35a395d153a722d74008bf024452
BLAKE2b-256 3b5c10055a29bd0fc16a5518dd7172e5def01306e93f5579810cb8b1b5982793

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for roamresearch_client_py-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f44bf987959322c34f5a341c89265dda09088c0c12cd6c2ddd972b978501456
MD5 6d08c1dc8c0ba726ce8e299dab90c75e
BLAKE2b-256 bdba1ab697170962ca50ceb7e24d59287401f4c8a6ad22ccd302d7d262246f36

See more details on using hashes here.

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