Python Client Library

This reference covers all objects and functions exposed by the Railengine client library to ingest content, organize datasets, and run retrieval queries.

For a more detailed documentation, please visit the PyPI Package for Ingestion here → and Retrieval here →

Installation

				
					pip install rail-engine-ingest
# or
uv pip install rail-engine-ingest
				
			

Authentication

The ingestion SDK uses the  ENGINE_TOKEN  environment variable for authentication. Copy the value below and add it to your .env file:

.env Example

Your .env file should look like this:
				
					ENGINE_TOKEN="[Your ENGINE_TOKEN Here]"
				
			

Code Example

Here’s a simple example of how to ingest documents using the Python SDK:

				
					import os
from railtown.engine.ingest import RailengineIngest

# ENGINE_TOKEN is automatically read from environment variable
# Make sure ENGINE_TOKEN is set: export ENGINE_TOKEN="your-token-here"
client = RailEngineIngest()

# Ingest a blog post
blog_post = {
    "title": "Getting Started with Railengine",
    "body": "Railengine is a powerful storage engine that makes it easy to build AI applications...",
    "author": "Jane Doe",
    "published_date": "2024-01-15",
    "tags": ["python", "ai", "tutorial"],
    "category": "Technology"
}

response = client.ingest(blog_post)
print(f"Ingested blog post: {response}")
				
			

Retrieval

Installation

				
					pip install rail-engine
# or
uv pip install rail-engine
				
			

Authentication

You need to generate an ENGINE_PAT in the Security Tokens tab

.env Example

Your .env file should look like this:
				
					ENGINE_PAT="your-pat-token-here"
ENGINE_ID="19275045-4fe0-4c13-a802-1563bfc1b96c"
				
			

Code Example

Here’s a simple example of how to ingest documents using the Python SDK:

				
					import asyncio
from railtown.engine import Railengine

async def main():
    # Initialize client (reads from ENGINE_PAT env var)
    async with RailEngine() as client:
        blog_posts = client.list_storage_documents()
        async for item in blog_posts:
            print(item)

asyncio.run(main())