Skip to main content

Official Python SDK for the PromptRails API

Project description

PromptRails Python SDK

PyPI version Python versions License: MIT

Official Python SDK for PromptRails — the AI agent orchestration platform.

Installation

pip install promptrails

Quick Start

Synchronous

from promptrails import PromptRails

client = PromptRails(api_key="pr_key_...")

# Execute an agent
result = client.agents.execute("agent-id", input={"query": "Summarise this week's sales"})
print(result.output)

client.close()

Async

import asyncio
from promptrails import AsyncPromptRails

async def main():
    async with AsyncPromptRails(api_key="pr_key_...") as client:
        result = await client.agents.execute("agent-id", input={"query": "hello"})
        print(result.output)

asyncio.run(main())

Context Manager

with PromptRails(api_key="pr_key_...") as client:
    agents = client.agents.list()
    for agent in agents.data:
        print(agent.name)

Error Handling

from promptrails import NotFoundError, ValidationError, RateLimitError, QuotaExceededError

try:
    result = client.agents.execute("agent-id", input={})
except QuotaExceededError:
    print("Execution limit reached — upgrade your plan")
except RateLimitError:
    print("Too many requests, back off and retry")
except NotFoundError as e:
    print(f"Agent not found: {e.message}")

Available Resources

Resource Methods
client.agents list, get, create, update, delete, execute, list_versions, create_version, list_guardrails, create_guardrail, list_memories, create_memory, search_memories, delete_all_memories
client.prompts list, get, create, update, delete, list_versions, create_version
client.executions list, get
client.credentials list, get, create, update, delete, set_default, check_connection
client.data_sources list, get, create, update, delete, list_versions, create_version, test_connection, query
client.chat list_sessions, get_session, create_session, delete_session, list_messages, send_message
client.traces list, get_by_trace_id
client.costs get_summary, get_agent_summary
client.scores list, get, create, update, delete, list_configs, get_config, create_config, update_config, delete_config, aggregates
client.mcp_tools list, get, create, update, delete
client.approvals list, get, decide
client.agent_triggers list, get, create (with source + source_config), update, delete
client.agent_vfs list, read, write, stat, mkdir, move, copy, delete, grep, glob, usage
client.a2a get_agent_card, send_message, get_task, list_tasks, cancel_task
client.media_models list
client.media generate
client.assets list, get, delete, get_signed_url

Media Studio

Generate images, speech, and video using various providers:

# List available media models
models = client.media_models.list(media_type="image")
for model in models:
    print(f"{model.provider}/{model.model_id}: {model.display_name}")

# Generate an image
result = client.media.generate(
    provider="fal",
    media_type="image",
    model="fal-ai/flux/schnell",
    prompt="A futuristic cityscape at sunset",
    config={"width": 1024, "height": 768},
)
print(result.url)

# List assets
assets = client.assets.list(type="image")
for asset in assets.data:
    print(f"{asset.file_name} ({asset.mime_type})")

# Get a signed download URL
signed = client.assets.get_signed_url(asset_id="asset-id")
print(signed.url)

# Delete an asset
client.assets.delete(asset_id="asset-id")

Configuration

Option Default Description
api_key required API key
base_url https://api.promptrails.ai API base URL
timeout 30.0 Request timeout (seconds)
max_retries 3 Max retries on network/5xx errors

Contributing

# Install development dependencies
pip install -e ".[dev]"

# Run linter
ruff check .

# Run formatter
ruff format .

# Run tests
pytest tests/ -v

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

promptrails-0.4.0.tar.gz (30.0 kB view details)

Uploaded Source

Built Distribution

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

promptrails-0.4.0-py3-none-any.whl (40.3 kB view details)

Uploaded Python 3

File details

Details for the file promptrails-0.4.0.tar.gz.

File metadata

  • Download URL: promptrails-0.4.0.tar.gz
  • Upload date:
  • Size: 30.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for promptrails-0.4.0.tar.gz
Algorithm Hash digest
SHA256 d8f53f4e5d085fe83b43a4d4d1131c072a318d68a7efe64efe17bafecca32a2f
MD5 7d858f2b141af2d44679a67e4ef04657
BLAKE2b-256 8fb40e47ca1c8b8d1d39e4c412b9fdbd6136d666b2d62f7ce226784f0ea6c070

See more details on using hashes here.

File details

Details for the file promptrails-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: promptrails-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 40.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for promptrails-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a9c9175c59526d6bb4441dcbef1d8214a8c5f7ec4d1d7f51a042be509f999788
MD5 1392a773cfa347317358766e6c06a6c7
BLAKE2b-256 bff4eea7442c82d3f3a1d3d90f7fc2cc9c9256f3c2b701c0db49054ef2c27e97

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