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.1.tar.gz (28.2 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.1-py3-none-any.whl (31.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: roamresearch_client_py-0.3.1.tar.gz
  • Upload date:
  • Size: 28.2 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.1.tar.gz
Algorithm Hash digest
SHA256 aba094000cae0acfb50af8ea6d9d5a1bb7d48c258b81a0375ed7418ddf82ec49
MD5 7bd399970542fd548e193f78b7edc971
BLAKE2b-256 4edf4780ade822b73b1900d2cf6ec1f110f68da259c9fdeddf6deb6e17f07083

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for roamresearch_client_py-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cc402fa3cfc4df505f4211794ca847d9673fd7e3d69660fbe00a9bab4861ffc4
MD5 b68924b985fd791d873476fd35e583fc
BLAKE2b-256 aa80264fcbd153cedef04d7d63af49cd37eee621cdd12b35a313a21fdd57181e

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