Membit Python Client
The Membit Python client provides powerful social media analytics and monitoring capabilities for your Python applications. Easily integrate trending discussion discovery, cluster analysis, and social post search with a simple and intuitive API.
Installation
pip install membit-python
Or with uv:
uv add membit-python
Quick Start
Basic Usage
from membit import MembitClient
# Initialize the client with API key
client = MembitClient(api_key="your_api_key_here")
# Or use environment variable MEMBIT_API_KEY
# client = MembitClient()
# Search for trending discussion clusters
clusters = client.cluster_search("artificial intelligence", limit=5)
print(clusters)
Features
🔥 Trending Discussion Clusters
Find and analyze trending discussions across social platforms with intelligent clustering.
🔍 Deep Cluster Analysis
Dive deeper into specific discussions to understand context and participants.
📱 Social Post Search
Search for individual social media posts on specific topics.
⚡ Async Support
Full async/await support for high-performance applications.
📊 Multiple Response Formats
Get data in JSON format for applications or LLM-optimized text for AI workflows.
Usage Examples
Finding Trending Discussion Clusters
from membit import MembitClient
# Initialize client with API key
client = MembitClient(api_key="your_api_key_here")
# Or use environment variable MEMBIT_API_KEY
# client = MembitClient()
# Search for trending clusters
clusters = client.cluster_search("artificial intelligence", limit=5)
# clusters is a dict containing trending discussion clusters
for cluster in clusters.get("clusters", []):
print(f"Cluster: {cluster['label']}")
Getting Detailed Cluster Information
from membit import MembitClient
# Initialize client with API key
client = MembitClient(api_key="your_api_key_here")
# First, find clusters
clusters = client.cluster_search("climate change")
# Get detailed info about the first cluster
if clusters.get("clusters"):
cluster_label = clusters["clusters"][0]["label"]
cluster_details = client.cluster_info(label=cluster_label, limit=10)
print(cluster_details)
Searching for Individual Posts
from membit import MembitClient
# Initialize client with API key
client = MembitClient(api_key="your_api_key_here")
# Search for specific social posts
posts = client.post_search("machine learning breakthrough", limit=20)
# Access individual social media posts
for post in posts.get("posts", []):
print(f"Post: {post}")
Using Different Response Formats
from membit import MembitClient
# Initialize client with API key
client = MembitClient(api_key="your_api_key_here")
# Get JSON response (default)
json_response = client.cluster_search("space exploration", output_format="json")
# Returns: dict with structured data
# Get LLM-optimized text response
llm_response = client.cluster_search("space exploration", output_format="llm")
# Returns: str with formatted text optimized for AI processing
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"][:3]
]
cluster_details = await asyncio.gather(*tasks)
for details in cluster_details:
print(details)
# Run the async function
asyncio.run(analyze_topics())
API Reference
MembitClient(api_key=None, api_url=None)
Initialize the Membit client.
Parameters:
api_key(str, optional): Your Membit API key. If not provided, usesMEMBIT_API_KEYenvironment variable.api_url(str, optional): Custom API URL. Uses default Membit API URL if not provided.
cluster_search(q, limit=10, output_format="json", timeout=60)
Get trending discussions across social platforms. Useful for finding topics of interest and understanding live conversations.
Parameters:
q(str): Search query stringlimit(int, optional): Maximum number of results to return (default: 10)output_format(str, optional): Response format -"json"or"llm"(default:"json")timeout(int, optional): Request timeout in seconds (default: 60, max: 120)
Returns:
dict: Trending discussion clusters (whenoutput_format="json")str: Formatted text response (whenoutput_format="llm")
cluster_info(label, limit=10, output_format="json", timeout=60)
Dive deeper into a specific trending discussion cluster. Useful for understanding the context and participants of a particular conversation.
Parameters:
label(str): Cluster label obtained fromcluster_searchlimit(int, optional): Maximum number of results to return (default: 10)output_format(str, optional): Response format -"json"or"llm"(default:"json")timeout(int, optional): Request timeout in seconds (default: 60, max: 120)
Returns:
dict: Detailed cluster information (whenoutput_format="json")str: Formatted text response (whenoutput_format="llm")
post_search(q, limit=10, output_format="json", timeout=60)
Search for raw social posts. Useful when you need to find specific posts (not recommended for finding trending discussions).
Parameters:
q(str): Search query stringlimit(int, optional): Maximum number of results to return (default: 10)output_format(str, optional): Response format -"json"or"llm"(default:"json")timeout(int, optional): Request timeout in seconds (default: 60, max: 120)
Returns:
dict: Raw social posts (whenoutput_format="json")str: Formatted text response (whenoutput_format="llm")
Error Handling
The client includes comprehensive error handling:
from membit import MembitClient, MissingAPIKeyError
try:
# Initialize client with API key
client = MembitClient(api_key="your_api_key_here")
result = client.cluster_search("python programming")
except MissingAPIKeyError:
print("Please provide a valid API key")
except TimeoutError:
print("Request timed out")
except Exception as e:
print(f"An error occurred: {e}")
Requirements
- Python: >=3.10
- Dependencies:
requests>=2.25.0(for synchronous client)httpx>=0.28.1(for asynchronous client)
Examples
Complete working examples are available in the examples/ directory:
examples/client.py- Synchronous client usageexamples/async_client.py- Asynchronous client usage
Running Examples
# Set your API key
export MEMBIT_API_KEY="your_api_key_here"
# Install dependencies
uv sync
# Run synchronous example
uv run examples/client.py
# Run asynchronous example
uv run examples/async_client.py
Development
Installing for Development
git clone <repository-url>
cd membit-python
uv sync
Running Tests
uv run pytest
Contributing
We welcome contributions! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License.
Support
For support or questions about the Membit Python client, please reach out to our support team.
Metadata
Release files for membit-python 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| membit_python-0.0.2.tar.gz | 14.0 kB | Without provenance | Details for membit_python-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| membit_python-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for membit_python-0.0.2-py3-none-any.whl |
Total release size: 22.0 kB
Release files / membit_python-0.0.2.tar.gz
| Download URL | membit_python-0.0.2.tar.gz |
|---|---|
| Size | 14.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1ffc85311dc6e790abf1ab32abcde70c00a3020ae5788b6af6d5ea90fc50359b
|
|
BLAKE2b-256 checksum How to use checksums |
ba455a15b902ed25354f9c889ffbf86d77a097a485787aac1713758c770fa4af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.14
|
Release files / membit_python-0.0.2-py3-none-any.whl
| Download URL | membit_python-0.0.2-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d4937b9ccfb0b8b4c021c965ef534d37b1c3929fcbc04ea9cfcf5a4eace557ec
|
|
BLAKE2b-256 checksum How to use checksums |
7f42df2f8410bdc3b48326e75744079dc1a2a72263489393b8a7b0ed65c8a5f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.14
|
Security for membit-python 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.