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

# Contacts

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

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

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

client = MailGlyph("sk_your_secret_key")
```

## List contacts (`contacts.list`)

Use cursor pagination for large lists:

```python theme={null}
page1 = client.contacts.list(
    limit=50,
    subscribed=True,
    search="john",
)

print(len(page1.data), page1.has_more, page1.cursor)
```

Fetch the next page with `cursor`:

```python theme={null}
if page1.has_more and page1.cursor:
    page2 = client.contacts.list(
        limit=50,
        cursor=page1.cursor,
    )

    print(len(page2.data))
```

## Create a contact (`contacts.create`)

```python theme={null}
created = client.contacts.create(
    email="user@example.com",
    subscribed=True,
    data={"firstName": "John", "plan": "premium"},
)

print(created.id, created.meta.is_new if created.meta else None)
```

## Get one contact (`contacts.get`)

```python theme={null}
contact = client.contacts.get(created.id)

print(contact.email, contact.subscribed)
```

## Update a contact (`contacts.update`)

```python theme={null}
updated = client.contacts.update(
    created.id,
    subscribed=False,
    data={"plan": "pro"},
)

print(updated.subscribed, updated.data)
```

## Count contacts (`contacts.count`)

```python theme={null}
subscribed_count = client.contacts.count(subscribed=True)
search_count = client.contacts.count(search="john")

print(subscribed_count, search_count)
```

## Delete a contact (`contacts.delete`)

```python theme={null}
client.contacts.delete(created.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.contacts.list(limit=20)
        created = await client.contacts.create(email="new@example.com", data={"source": "sdk"})
        fetched = await client.contacts.get(created.id)
        updated = await client.contacts.update(fetched.id, subscribed=False)
        total = await client.contacts.count(subscribed=False)
        await client.contacts.delete(updated.id)
        print(total)
```

See full details in the [Contacts API reference](https://docs.mailglyph.com/api-reference/contacts/listContacts.md).


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