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

# Python SDK

> Use the Membit Python SDK to access real-time social context with simple sync/async APIs.

Membit's Python SDK provides a simple interface to the Membit API. Add intelligent search and content discovery directly to your apps with sync and async support.

## Installing

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

Or with uv:

```bash theme={null}
uv add membit-python
```

## Membit Cluster Search

Discover trending topics and clusters of related content. Ideal for understanding what's trending and grouping related discussions.

### Usage

```python theme={null}
from membit import MembitClient

client = MembitClient(api_key="your_api_key_here")
clusters = client.cluster_search("artificial intelligence", limit=3)
print(clusters)
```

## Membit Cluster Info

Fetch detailed information about a specific cluster. Use this to dive deeper into topics discovered via cluster search.

### Usage

```python theme={null}
from membit import MembitClient

client = MembitClient(api_key="your_api_key_here")
cluster_info = client.cluster_info("AI Learning Resources", limit=5, output_format="json")
print("Cluster Info:", cluster_info)
```

## Membit Post Search

Search for individual posts across the Membit corpus. Perfect for finding specific content and examples.

### Usage

```python theme={null}
from membit import MembitClient

client = MembitClient(api_key="your_api_key_here")
posts = client.post_search("machine learning", limit=10, output_format="json")
print("Found posts:", posts)
```

## Async Support

For applications that need high performance or handle multiple concurrent requests:

```python theme={null}
import asyncio
from membit import AsyncMembitClient

async def analyze_topics():
    client = AsyncMembitClient(api_key="your_api_key_here")

    # Search for trending clusters asynchronously
    clusters = await client.cluster_search("tech news", limit=5)

    # Get detailed info for multiple clusters concurrently
    if clusters.get("clusters"):
        tasks = [
            client.cluster_info(label=cluster["label"])
            for cluster in clusters["clusters"]
        ]
        cluster_details = await asyncio.gather(*tasks)

        for details in cluster_details:
            print(details)

# Run the async function
asyncio.run(analyze_topics())
```

## Defaults and Configuration

All search methods support these options (defaults shown):

* **limit**: 10 — Maximum number of results to return
* **output\_format**: "json" — "json" for structured data, "llm" for text
* **timeout**: 60 — Request timeout in seconds

## Environment Variables

You can set your API key via environment variable:

```bash theme={null}
export MEMBIT_API_KEY="<your-api-key>"
```

If `api_key` is not provided to the client, the SDK will automatically use `MEMBIT_API_KEY`.

## Examples

Complete working examples are available in [`membit-python`](https://github.com/bandprotocol/membit-python)'s `examples/` directory:

* `examples/client.py` — Synchronous client usage
* `examples/async_client.py` — Asynchronous client usage
