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

pip install membit-python
Or with uv:
uv add membit-python
Discover trending topics and clusters of related content. Ideal for understanding what’s trending and grouping related discussions.

Usage

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

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

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:
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:
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 the examples/ directory:
  • examples/client.py — Synchronous client usage
  • examples/async_client.py — Asynchronous client usage