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

# Python SDK usage

> Use the sync Telnyx client or the AsyncTelnyx client with httpx or aiohttp.

## Usage

The full API of this library can be found in [api.md](https://github.com/team-telnyx/telnyx-python/tree/master/api.md).

```python theme={null}
import os
from telnyx import Telnyx

client = Telnyx(
    api_key=os.environ.get("TELNYX_API_KEY"),  # This is the default and can be omitted
)

response = client.calls.dial(
    connection_id="conn12345",
    from_="+15557654321",
    to="+15551234567",
    webhook_url="https://your-webhook.url/events",
)
print(response.data)
```

While you can provide an `api_key` keyword argument,
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
to add `TELNYX_API_KEY="My API Key"` to your `.env` file
so that your API Key is not stored in source control.

## Async usage

Simply import `AsyncTelnyx` instead of `Telnyx` and use `await` with each API call:

```python theme={null}
import os
import asyncio
from telnyx import AsyncTelnyx

client = AsyncTelnyx(
    api_key=os.environ.get("TELNYX_API_KEY"),  # This is the default and can be omitted
)


async def main() -> None:
    response = await client.calls.dial(
        connection_id="conn12345",
        from_="+15557654321",
        to="+15551234567",
        webhook_url="https://your-webhook.url/events",
    )
    print(response.data)


asyncio.run(main())
```

Functionality between the synchronous and asynchronous clients is otherwise identical.

### With aiohttp

By default, the async client uses `httpx` for HTTP requests. However, for improved concurrency performance you may also use `aiohttp` as the HTTP backend.

You can enable this by installing `aiohttp`:

```sh theme={null}
# install from PyPI
pip install telnyx[aiohttp]
```

Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:

```python theme={null}
import asyncio
from telnyx import DefaultAioHttpClient
from telnyx import AsyncTelnyx


async def main() -> None:
    async with AsyncTelnyx(
        api_key="My API Key",
        http_client=DefaultAioHttpClient(),
    ) as client:
        response = await client.calls.dial(
            connection_id="conn12345",
            from_="+15557654321",
            to="+15551234567",
            webhook_url="https://your-webhook.url/events",
        )
        print(response.data)


asyncio.run(main())
```
