> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mutagent.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK Quickstart

> Create your first prompt and list results with the MutagenT Python SDK

# Python SDK Quickstart

Get up and running with the MutagenT Python SDK in minutes.

## Prerequisites

* Python 3.10+
* `pip install mutagent-sdk`
* A MutagenT API key — set as `MUTAGENT_API_KEY` in your environment

## Create a Prompt

```python theme={null}
from mutagent import Mutagent
from mutagent.models import NameDescriptionVersion

client = Mutagent()

# Create a new prompt
prompt = client.prompt.create_prompt(NameDescriptionVersion(
    name="Support Assistant",
    raw_prompt="You are a helpful assistant for {company}. Answer questions about {topic}.",
    input_schema={"type": "object", "properties": {"company": {"type": "string"}, "topic": {"type": "string"}}},
))

print(f"Created: {prompt.id}")
print(f"Name: {prompt.name}")
```

## List Prompts

```python theme={null}
from mutagent import Mutagent

client = Mutagent()

result = client.prompt.list_prompts()
for p in result.get("data", []):
    print(f"  {p['id']}: {p['name']}")
```

## Get a Specific Prompt

```python theme={null}
# id_ is a numeric prompt ID (integer)
prompt = client.prompt.get_prompt(id_=123)
print(prompt["name"], prompt.get("raw_prompt") or prompt.get("human_prompt"))
```

## Async Version

The same operations work with `AsyncMutagent` in async contexts:

```python theme={null}
import asyncio
from mutagent import AsyncMutagent

async def main():
    async with AsyncMutagent() as client:
        # Create a prompt
        from mutagent.models import NameDescriptionVersion
        prompt = await client.prompt.create_prompt(NameDescriptionVersion(
            name="Support Assistant",
            raw_prompt="You are a helpful assistant for {company}.",
            input_schema={"type": "object", "properties": {"company": {"type": "string"}}},
        ))
        print(f"Created: {prompt['id']}")

        # List all prompts
        result = await client.prompt.list_prompts()
        print(f"Total prompts: {len(result.get('data', []))}")

asyncio.run(main())
```

## Error Handling

All API errors raise `MutagentError` with the HTTP status code, response body, and headers:

```python theme={null}
from mutagent import Mutagent
from mutagent.errors import SDKError

client = Mutagent()

try:
    prompt = client.prompt.get_prompt(id_=999999)  # nonexistent ID
except SDKError as e:
    print(f"Status: {e.status_code}")
    print(f"Body: {e.body}")
```

## Retries

The SDK automatically retries transient failures (429, 5xx) with exponential backoff (250ms → 500ms → 1s → 2s → 4s, 3 retries by default). The retry logic is built in and requires no configuration.

Configure the timeout at construction time:

```python theme={null}
client = Mutagent(
    api_key="mt_xxxxxxxxxxxx",
    timeout=30.0,   # seconds (default: 60)
)
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Tracing" icon="radar" href="/sdk/python/tracing">
    Add observability to your Python LLM calls
  </Card>

  <Card title="Python Integrations" icon="python" href="/integrations/python/overview">
    Auto-trace frameworks: Anthropic, OpenAI, LangChain, LangGraph
  </Card>

  <Card title="TypeScript Quickstart" icon="js" href="/sdk/typescript/installation">
    TypeScript SDK for comparison
  </Card>

  <Card title="API Reference" icon="book" href="/api-reference/overview">
    Full REST API documentation
  </Card>
</CardGroup>
