> ## 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.

# Templates

> List, get, create, update, and delete Lettr-managed templates and fetch rendered HTML with the client.templates resource in the Python SDK.

The `client.templates` resource manages Lettr-managed templates. To *send* a template, pass `template_slug` to `client.emails.send()` — see [Sending Emails](https://docs.lettr.com/quickstart/python/quickstart.md#sending-emails).

```python theme={null}
import lettr

client = lettr.Lettr("lttr_your_api_key")
```

## List Templates

```python theme={null}
template_list = client.templates.list(per_page=10)
for template in template_list.templates:
    print(f"{template.name} ({template.slug})")
```

> [card] [API Reference](https://docs.lettr.com/api-reference/templates/list-templates.md)
>
> GET /templates

## Get a Template

```python theme={null}
template = client.templates.get("welcome-email")
print(template.html)

# Or fetch only the rendered HTML for a project
html = client.templates.get_html(project_id=1, slug="welcome-email")
```

## Create a Template

Provide `html` **or** `json` (the TOPOL.io editor format), not both:

```python theme={null}
template = client.templates.create(
    name="Welcome Email",
    html="<h1>Hello {{NAME}}!</h1><p>Welcome aboard.</p>",
    project_id=123,          # optional
    folder_id=5,             # optional
    purpose="campaign",      # optional; "transactional" by default
)
```

> [!WARNING]
>
> **`purpose` is set once and cannot be changed.** Omit it and you get a transactional template, which a [campaign](https://docs.lettr.com/learn/campaigns/introduction.md) cannot use — and `purpose` is not accepted by the update endpoint, so the only remedy is to copy the template in the app. If the content is going to an audience, set it now. See [Transactional vs. Marketing Templates](https://docs.lettr.com/learn/templates/projects.md#transactional-vs-marketing-templates).

> [card] [API Reference](https://docs.lettr.com/api-reference/templates/create-template.md)
>
> POST /templates

## Update & Delete

Updating a template creates a new version:

```python theme={null}
client.templates.update(
    "welcome-email",
    html="<h1>Hi {{NAME}}!</h1><p>Updated content.</p>",
)

client.templates.delete("welcome-email")
client.templates.delete("welcome-email", project_id=123)  # within a project
```

## Get Merge Tags

Retrieve the variables a template expects — useful for validating data before sending:

```python theme={null}
merge_tags = client.templates.get_merge_tags("welcome-email")
for tag in merge_tags.merge_tags:
    print(f"{tag.key} (required: {tag.required}, type: {tag.type})")
```

> [card] [API Reference](https://docs.lettr.com/api-reference/templates/get-merge-tags.md)
>
> GET /templates/{slug}/merge-tags

## What's Next

> [card] [Template Language](https://docs.lettr.com/learn/templates/template-language.md)
>
> Merge tag syntax, conditionals, loops

> [card] [Sending Emails](https://docs.lettr.com/quickstart/python/quickstart.md)
>
> Send a template with substitution data


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.