> ## Documentation Index
> Fetch the complete documentation index at: https://60db.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK

> Complete guide to the 60db Python SDK

## Installation

```bash theme={null}
pip install 60db
```

## Initialization

```python theme={null}
from sixtydb import SixtyDBClient

# Simple initialization
client = SixtyDBClient('your-api-key')

# With custom configuration

### Get all voices
voices = await client.getVoices();

### Get all lanuages
lanuages = await client.getLanguages();

### audio is an ArrayBuffer containing the audio data
```

## Text-to-Speech

### Basic TTS

```python theme={null}
audio = client.text_to_speech(
    text='Hello, world!',
    voice_id='default-voice',
    enhance=True,
    speed=1.0,
    language='en-us'
)

# Save to file
with open('output.mp3', 'wb') as f:
    f.write(audio)
```

## Speech-to-Text

### Transcribe Audio

```python theme={null}
with open('audio.mp3', 'rb') as audio_file:
    result = client.speech_to_text(audio_file, language='en')
    print(result['text'])
```

### Get Supported Languages

```python theme={null}
languages = client.get_languages()
for lang in languages:
    print(f"{lang['name']} ({lang['code']})")
```

## Voice Management

### List All Voices

```python theme={null}
voices = client.get_voices()
for voice in voices:
    print(f"{voice['name']} ({voice['id']})")
```

### Get Specific Voice

```python theme={null}
voice = client.get_voice('voice-id')
print(voice)
```

### Create Custom Voice

```python theme={null}
files = [
    open('sample1.mp3', 'rb'),
    open('sample2.mp3', 'rb'),
    open('sample3.mp3', 'rb')
]

new_voice = client.create_voice(
    name='My Custom Voice',
    files=files,
    description='A custom voice for my brand'
)

print(f"Created voice: {new_voice['id']}")

# Close files
for f in files:
    f.close()
```

### Update Voice

```python theme={null}
client.update_voice(
    voice_id='voice-id',
    name='Updated Voice Name',
    description='Updated description'
)
```

### Delete Voice

```python theme={null}
client.delete_voice('voice-id')
```

## Authentication

### Sign Up

```python theme={null}
user = client.sign_up(
    email='user@example.com',
    password='secure-password',
    name='John Doe'
)
```

### Sign In

```python theme={null}
session = client.sign_in(
    email='user@example.com',
    password='secure-password'
)

print(f"Token: {session['token']}")
```

### Get Profile

```python theme={null}
profile = client.get_profile()
print(profile)
```

### Update Profile

```python theme={null}
client.update_profile(
    name='Jane Doe',
    company='Acme Inc'
)
```

## Workspace Management

### List Workspaces

```python theme={null}
workspaces = client.get_workspaces()
```

### Create Workspace

```python theme={null}
workspace = client.create_workspace(
    name='My Workspace',
    description='Team workspace'
)
```

## Billing

### Get Available Plans

```python theme={null}
plans = client.get_plans()
for plan in plans:
    print(f"{plan['name']}: ${plan['price']}/month")
```

### Get Current Plan

```python theme={null}
current_plan = client.get_current_plan()
print(f"Current plan: {current_plan['name']}")
```

### Subscribe to Plan

```python theme={null}
client.subscribe('plan-id')
```

## Analytics

### Get Usage Statistics

```python theme={null}
usage = client.get_usage()
print(f"Characters used: {usage['characters']}")
print(f"API calls: {usage['api_calls']}")
```

## API Key Management

### List API Keys

```python theme={null}
api_keys = client.get_api_keys()
```

### Create API Key

```python theme={null}
new_key = client.create_api_key('Production Key')
print(f"New API key: {new_key['key']}")
```

### Delete API Key

```python theme={null}
client.delete_api_key('key-id')
```

## Webhooks

### List Webhooks

```python theme={null}
webhooks = client.get_webhooks()
```

### Create Webhook

```python theme={null}
webhook = client.create_webhook(
    url='https://example.com/webhook',
    events=['tts.completed', 'stt.completed']
)
```

### Delete Webhook

```python theme={null}
client.delete_webhook('webhook-id')
```

## Error Handling

```python theme={null}
from requests.exceptions import HTTPError

try:
    audio = client.text_to_speech(
        text='Hello, world!',
        voice_id='invalid-voice'
    )
except HTTPError as e:
    print(f"HTTP Error: {e.response.status_code}")
    print(f"Message: {e.response.json()['message']}")
except Exception as e:
    print(f"Error: {str(e)}")
```

## Type Hints

The SDK includes type hints for better IDE support:

```python theme={null}
from sixtydb import SixtyDBClient
from typing import Dict, List, Any

client: SixtyDBClient = SixtyDBClient('your-api-key')
voices: List[Dict[str, Any]] = client.get_voices()
```

## Async Support

For async applications, you can use the SDK with asyncio:

```python theme={null}
import asyncio
from sixtydb import SixtyDBClient

async def main():
    client = SixtyDBClient('your-api-key')

    # Run in executor for async compatibility
    loop = asyncio.get_event_loop()
    audio = await loop.run_in_executor(
        None,
        client.text_to_speech,
        'Hello, world!',
        'default-voice'
    )

    with open('output.mp3', 'wb') as f:
        f.write(audio)

asyncio.run(main())
```
