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

# Events

> Track events and list event names with the MailGlyph Python SDK.

Use a **public key** for tracking events, and a **secret key** for listing event names.

## Track an event (`events.track`)

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

tracker = MailGlyph("pk_your_public_key")

result = tracker.events.track(
    email="user@example.com",
    event="purchase",
    subscribed=True,
    data={"product": "premium", "amount": 99},
)

print(result.contact, result.event, result.timestamp)
```

## List event names (`events.get_names`)

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

client = MailGlyph("sk_your_secret_key")

event_names = client.events.get_names()
print(event_names)
```

## Key-type mismatch example

```python theme={null}
from mailglyph import MailGlyph
from mailglyph.exceptions import AuthenticationError

client = MailGlyph("pk_your_public_key")

try:
    client.events.get_names()
except AuthenticationError as error:
    print(error.message)
```

## Async equivalents

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


async def run() -> None:
    async with AsyncMailGlyph("pk_your_public_key") as tracker:
        result = await tracker.events.track(email="user@example.com", event="signup")
        print(result.event)

    async with AsyncMailGlyph("sk_your_secret_key") as client:
        names = await client.events.get_names()
        print(names)
```

The Python SDK exposes `events.get_names()` only (there is no `list_names()` alias).

See endpoint details in the [Track event API reference](https://docs.mailglyph.com/api-reference/public-api/trackEvent.md) and [List event names API reference](https://docs.mailglyph.com/api-reference/events/listEventNames.md).


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