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

# Getting Started

> Send transactional emails from Python with the type-safe lettr SDK, featuring sync and async clients, type hints, and typed error handling.

Send transactional emails from your Python applications using the official Lettr Python SDK. The SDK provides a type-safe, intuitive interface for the Lettr API with full async support and comprehensive error handling.

The `lettr` package gives you a Pythonic API client that works with any Python application — Django, Flask, FastAPI, or standalone scripts. It follows Python conventions and integrates seamlessly with your existing codebase.

Using Cursor? [Jump straight in using this prompt](https://cursor.com/link/prompt?text=Help%20me%20add%20a%20Lettr%20sending%20example%20for%20Python%20using%20the%20lettr%20package%2C%20or%20migrate%20my%20current%20Python%20sending%20solution%20to%20Lettr%20using%20these%20docs%3A%20https%3A%2F%2Fdocs.lettr.com%2Fquickstart%2Fpython%2Fquickstart)

## Why Use the Python SDK?

Rather than making raw HTTP requests, the SDK provides:

* **Type hints** — Full type annotations for IDE autocompletion and type checking
* **Sync and async** — Both synchronous and asynchronous API clients
* **Pythonic interface** — Snake\_case naming and Python conventions
* **Error handling** — Typed exceptions for different error scenarios
* **Minimal dependencies** — Only requires `httpx` for HTTP requests

<Note>
  If you prefer not to use the SDK, you can also send emails via [SMTP](/quickstart/smtp/introduction) or make direct [HTTP API](/api-reference/emails/send-email) calls.
</Note>

## Prerequisites

Before you begin, make sure you have:

<CardGroup cols={2}>
  <Card title="API Key" icon="key" href="https://app.lettr.com/api-keys">
    Create an API key in the Lettr dashboard
  </Card>

  <Card title="Verified Domain" icon="globe" href="/learn/domains/sending-domains">
    Add and verify your sending domain
  </Card>
</CardGroup>

You'll also need:

* **Python 3.8 or later** installed
* **pip** for package management
* A verified sending domain in your [Lettr dashboard](https://app.lettr.com/domains)

## Quick Setup

Get started in three quick steps: install, configure, and send.

<Steps>
  <Step title="Install the SDK">
    ```bash theme={null}
    pip install lettr
    ```

    The SDK requires Python 3.8+ and automatically installs `httpx` as a dependency. For async support, httpx's async features are included by default.
  </Step>

  <Step title="Create a client">
    ```python theme={null}
    import lettr

    client = lettr.Lettr("your-api-key")

    # Verify the client is configured correctly
    auth = client.auth_check()
    print(f"Connected to Lettr (Team ID: {auth.team_id})")
    ```

    <Tip>
      Store your API key in environment variables, never hardcode it. API keys use the `lttr_` prefix followed by 64 hexadecimal characters.
    </Tip>
  </Step>

  <Step title="Send your first email">
    ```python theme={null}
    response = client.emails.send(
        from_email="sender@yourdomain.com",
        to=["recipient@example.com"],
        subject="Hello from Lettr",
        html="<h1>Hello!</h1><p>This is a test email.</p>",
    )

    print(f"Email sent! Request ID: {response.request_id}")
    print(f"Accepted: {response.accepted}")
    ```

    The response includes a `request_id` for tracking and the number of accepted recipients.
  </Step>
</Steps>

<Warning>
  The sender domain must be verified in your [Lettr dashboard](https://app.lettr.com/domains) before you can send emails. Sending from an unverified domain returns a validation error.
</Warning>

## Configuration

### Environment Variables

Read your API key from an environment variable:

```python theme={null}
import os
import lettr

api_key = os.environ.get("LETTR_API_KEY")
if not api_key:
    raise ValueError("LETTR_API_KEY environment variable is required")

client = lettr.Lettr(api_key)
```

### Using python-dotenv

Load environment variables from a `.env` file using `python-dotenv`:

```bash theme={null}
pip install python-dotenv
```

Create a `.env` file:

```env theme={null}
LETTR_API_KEY=lttr_your_api_key_here
```

Load it in your application:

```python theme={null}
from dotenv import load_dotenv
import os
import lettr

# Load .env file
load_dotenv()

client = lettr.Lettr(os.environ["LETTR_API_KEY"])
```

<Tip>
  Add `.env` to your `.gitignore` file to prevent accidentally committing your API key to version control.
</Tip>

### Custom HTTP Client

Use a custom httpx client with custom timeouts:

```python theme={null}
import httpx
import lettr

http_client = httpx.Client(timeout=30.0)
client = lettr.Lettr("your-api-key", http_client=http_client)
```

### Async Client

Use the async client for non-blocking operations:

```python theme={null}
import asyncio
import lettr

async def main():
    client = lettr.AsyncLettr("your-api-key")

    response = await client.emails.send(
        from_email="sender@yourdomain.com",
        to=["recipient@example.com"],
        subject="Hello",
        html="<p>Hello!</p>",
    )

    print(f"Email sent: {response.request_id}")

asyncio.run(main())
```

## Sending Emails

### Basic HTML Email

Send a simple HTML email:

```python theme={null}
response = client.emails.send(
    from_email="notifications@yourdomain.com",
    to=["user@example.com"],
    subject="Welcome to our service",
    html="<h1>Welcome!</h1><p>Thanks for signing up.</p>",
)

print(f"Email sent successfully (Request ID: {response.request_id})")
```

### With Display Name

Add a friendly display name to the sender address:

```python theme={null}
response = client.emails.send(
    from_email="notifications@yourdomain.com",
    from_name="Acme Corp",
    to=["user@example.com"],
    subject="Welcome to Acme",
    html="<h1>Hello!</h1>",
)
```

### Plain Text Email

Send a plain text email without HTML:

```python theme={null}
response = client.emails.send(
    from_email="notifications@yourdomain.com",
    to=["user@example.com"],
    subject="Plain text email",
    text="This is a plain text email.\n\nIt has no HTML formatting.",
)
```

### Multipart Emails (HTML + Text)

Send both HTML and plain text versions for maximum compatibility:

```python theme={null}
response = client.emails.send(
    from_email="notifications@yourdomain.com",
    to=["user@example.com"],
    subject="Multipart email",
    html="<h1>Hello!</h1><p>This is the HTML version.</p>",
    text="Hello!\n\nThis is the plain text version.",
)
```

<Tip>
  Providing both HTML and plain text ensures your emails are readable in all email clients, including text-only clients and accessibility tools.
</Tip>

## Explore the SDK

Beyond sending, the SDK manages every Lettr resource:

<CardGroup cols={2}>
  <Card title="Templates" icon="file-code" href="/quickstart/python/templates">
    Manage Lettr templates and merge tags
  </Card>

  <Card title="Domains" icon="globe" href="/quickstart/python/domains">
    Add, verify, and manage sending domains
  </Card>

  <Card title="Webhooks" icon="bell" href="/quickstart/python/webhooks">
    Manage webhook endpoints for delivery and engagement events
  </Card>

  <Card title="Audience" icon="users" href="/quickstart/python/audience">
    Lists, contacts, topics, properties, and segments
  </Card>

  <Card title="Campaigns" icon="paper-plane" href="/quickstart/python/campaigns">
    List, send, and schedule campaigns
  </Card>
</CardGroup>

## What's Next

<CardGroup cols={2}>
  <Card title="Advanced Features" icon="wand-magic-sparkles" href="/quickstart/python/advanced">
    Multiple recipients, attachments, templates, error handling, and more
  </Card>

  <Card title="Flask Integration" icon="flask" href="/quickstart/python/send-with-flask">
    Use Lettr with Flask applications
  </Card>

  <Card title="FastAPI Integration" icon="bolt" href="/quickstart/python/send-with-fastapi">
    Use Lettr with FastAPI applications
  </Card>

  <Card title="API Reference" icon="book" href="/api-reference/introduction">
    Complete API documentation
  </Card>
</CardGroup>
