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

# Templates

> Create, list, update, and delete templates with the MailGlyph Python SDK.

Use a **secret key** client for template methods.

```python theme={null}
from mailglyph import MailGlyph

client = MailGlyph("sk_your_secret_key")
```

## List templates (`templates.list`)

```python theme={null}
page = client.templates.list(
    limit=20,
    type="TRANSACTIONAL",
    search="welcome",
)

print(page.total, page.total_pages, len(page.data))
```

## Create a template (`templates.create`)

```python theme={null}
template = client.templates.create(
    name="Welcome",
    subject="Welcome to MailGlyph",
    body="<h1>Welcome</h1><p>Thanks for joining us.</p>",
    type="TRANSACTIONAL",
)

print(template.id, template.name)
```

## Get one template (`templates.get`)

```python theme={null}
fetched = client.templates.get(template.id)

print(fetched.subject, fetched.type)
```

## Update a template (`templates.update`)

```python theme={null}
updated = client.templates.update(
    template.id,
    subject="Welcome to MailGlyph!",
    body="<h1>Welcome!</h1><p>We are glad to have you.</p>",
)

print(updated.subject)
```

## Delete a template (`templates.delete`)

```python theme={null}
client.templates.delete(template.id)
```

## Async equivalents

```python theme={null}
from mailglyph import AsyncMailGlyph


async def run() -> None:
    async with AsyncMailGlyph("sk_your_secret_key") as client:
        page = await client.templates.list(limit=20)
        created = await client.templates.create(
            name="Welcome",
            subject="Welcome to MailGlyph",
            body="<h1>Welcome</h1>",
            type="TRANSACTIONAL",
        )
        fetched = await client.templates.get(created.id)
        updated = await client.templates.update(fetched.id, subject="Welcome!")
        await client.templates.delete(updated.id)
```

See full details in the [Templates API reference](https://docs.mailglyph.com/api-reference/templates/listTemplates.md).


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