Skip to main content

TitanRAG Python SDK & CLI

Official Python client library and developer CLI for the TitanRAG Enterprise Platform.

PyPI Python 3.12+ License: BSL-1.1


Installation

pip install titanrag

Or with uv:

uv add titanrag

Python SDK Usage

TitanRAG provides both async (AsyncTitanClient / TitanRAGClient) and synchronous (TitanClient) clients with built-in retries, jitter, and automatic token management.

import asyncio
from titanrag import AsyncTitanClient, TitanRAGError


async def main():
    async with AsyncTitanClient(
        base_url="http://localhost:8000/api/v1",
        api_key="your_api_key",
    ) as client:
        # Check system readiness
        health = await client.get_health_ready()
        print("TitanRAG Ready:", health)

        # Ask a question across a workspace
        response = await client.ask(
            workspace_id="your-workspace-id",
            question="What is our disaster recovery RTO objective?",
        )
        print("Answer:", response.answer)
        for citation in response.citations:
            print(f"- [{citation.source}] (relevance: {citation.score:.2f})")


if __name__ == "__main__":
    asyncio.run(main())

2. Streaming Responses (Real-time SSE)

Stream answer tokens, citations, and status events in real time:

import asyncio
from titanrag import AsyncTitanClient


async def main():
    async with AsyncTitanClient(base_url="http://localhost:8000/api/v1", api_key="your_api_key") as client:
        async for event in client.chat_stream(
            workspace_id="your-workspace-id",
            prompt="Summarize the Q3 cloud infrastructure budget.",
        ):
            if event.event_type == "token":
                print(event.data.get("token", ""), end="", flush=True)
            elif event.event_type == "citation":
                print(f"\n[Citation: {event.data.get('document_title')}]")
            elif event.event_type == "done":
                print("\nStream completed.")


if __name__ == "__main__":
    asyncio.run(main())

3. Synchronous Client

For CLI tools, scripts, or legacy sync environments:

from titanrag import TitanClient

with TitanClient(base_url="http://localhost:8000/api/v1", api_key="your_api_key") as client:
    response = client.ask(
        workspace_id="your-workspace-id",
        question="What are the key security policies for vendor API access?",
    )
    print(response.answer)

4. Document Ingestion

Upload documents for asynchronous ingestion, chunking, and embedding:

import asyncio
from titanrag import AsyncTitanClient


async def main():
    async with AsyncTitanClient(base_url="http://localhost:8000/api/v1", api_key="your_api_key") as client:
        result = await client.upload_file(
            workspace_id="your-workspace-id",
            file_path="contracts/master_services_agreement.pdf",
        )
        print(f"Document uploaded: {result.document_id}, status: {result.status}")


if __name__ == "__main__":
    asyncio.run(main())

Developer CLI (titan)

The package includes the titan CLI for terminal productivity, CI/CD pipelines, and script automation.

# Verify installation
titan version

# Authenticate against your TitanRAG cluster
titan login --url http://localhost:8000/api/v1 --key your_api_key

# Check current active profile
titan whoami

# Query with terminal markdown streaming
titan query "Explain the multi-tenant isolation model" --workspace my-workspace

# Pipe prompts via stdin
cat query.txt | titan query --workspace my-workspace

# Interactive REPL chat session
titan repl --workspace my-workspace

# Upload documents
titan upload path/to/report.pdf --workspace my-workspace

Error Handling

TitanRAG provides structured exceptions corresponding to HTTP response codes:

from titanrag import (
    AuthenticationError,
    NotFoundError,
    RateLimitError,
    ServerError,
    TitanRAGError,
)

try:
    response = client.ask(workspace_id="ws-123", question="Hello")
except AuthenticationError:
    print("Invalid or expired API key.")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds.")
except NotFoundError:
    print("Workspace or document not found.")
except TitanRAGError as e:
    print(f"TitanRAG Error [{e.status_code}]: {e.message}")

License

TitanRAG is licensed under the Business Source License 1.1 (BSL-1.1).

Metadata

Release files for titanrag 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for titanrag 0.1.1
File Size Uploaded
titanrag-0.1.1.tar.gz 22.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for titanrag 0.1.1
File Interpreter ABI Platform
titanrag-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 51.3 kB

Release files / titanrag-0.1.1.tar.gz

Download URL titanrag-0.1.1.tar.gz
Size 22.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7e293b1c97831c8d2caa54596568cf2012305b98ecc5e0876fef5d7af3d4ec9b
BLAKE2b-256 checksum
How to use checksums
7fb27a4ab72d72b63b7750cac9256ba2675f346e1428bc6d735b0b1d1af3be2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / titanrag-0.1.1-py3-none-any.whl

Download URL titanrag-0.1.1-py3-none-any.whl
Size 29.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e1dc714881e69de79b44ba9ac0b00b7c75435f465c04fe890219044a891f0b3f
BLAKE2b-256 checksum
How to use checksums
566190ab4bae1f85e15dfe7531722b79f386a15166c85f05f08f640cd0597c75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page