---
title: "Python SDK"
description: "The Python wrapper is async-first, easy to drop into services and notebooks, and maps cleanly onto the runtime event stream."
sidebar:
  label: "Python"
seo:
  title: "Python SDK | Autohand Code Agent SDK"
  description: "Python guide for the Autohand Code Agent SDK with async streaming, typed event parsing, permission handling, and runtime configuration."
---

## Install

```bash title="uv"
uv add autohand-sdk
```

```bash title="pip"
pip install autohand-sdk
```

## Stream a prompt [#streaming]

`AutohandSDK` works best inside an async context manager so startup and teardown stay tidy.

```python
import asyncio
from autohand_sdk import AutohandSDK

async def main():
    async with AutohandSDK(cwd='.', model='fantail2') as sdk:
        async for event in sdk.stream_prompt('Explain what src/index.ts is responsible for.'):
            if event['type'] == 'message_update':
                print(event.get('delta', ''), end='')
            elif event['type'] == 'tool_start':
                print('\nRunning', event.get('tool_name') or event.get('toolName'))

asyncio.run(main())
```

## Respond to permission requests [#permissions]

```python
async with AutohandSDK(cwd='.', permission_mode='interactive') as sdk:
    async for event in sdk.stream_prompt('Run the test suite and summarize failures.'):
        if event['type'] == 'permission_request':
            await sdk.respond_to_permission(
                event['request_id'],
                decision='allow',
                allowed=event.get('tool') != 'run_command',
            )
            continue

        if event['type'] == 'message_update':
            print(event.get('delta', ''), end='')
```

## Parse typed events [#typed-events]

Raw events are dictionaries, but you can upgrade known ones into typed models when you want stricter handling.

```python
from autohand_sdk import parse_sdk_event

async with AutohandSDK(cwd='.') as sdk:
    async for raw_event in sdk.stream_prompt('Hello'):
        event = parse_sdk_event(raw_event)
        if not isinstance(event, dict) and event.type == 'message_update':
            print(event.delta or '', end='')
```

## Activate skills [#skills]

The Python wrapper can point at installed skills or local `SKILL.md` files.

```python
sdk = AutohandSDK(
    cwd='.',
    skill_refs=[
        'typescript',
        './skills/my-custom/SKILL.md',
        {'name': 'api', 'path': '/absolute/path/to/SKILL.md'},
    ],
    copy_skill_files=False,
)
```

## Configuration notes [#config]

- `startup_check=True` is useful when you want fast feedback if the CLI process does not come up cleanly.
- Known camelCase fields are mirrored with snake\_case aliases on incoming event dictionaries.
- Provider configuration still lives in the CLI config file for the CLI-backed Python SDK.

## Next steps

- Open [Handle approvals and user input](/agent-sdk/io/approvals) for the full review loop.
- Open [Python API](/agent-sdk/python-api) for reference details.
