Metadata-Version: 2.4
Name: membrain-client
Version: 0.1.0
Summary: Python client for Membrain AI Safety Gateway — drop-in replacement for OpenAI SDK
Project-URL: Homepage, https://membrn.ai
Project-URL: Repository, https://github.com/mrpintcom/membrain-engine
Project-URL: Documentation, https://github.com/mrpintcom/membrain-engine
Project-URL: Issues, https://github.com/mrpintcom/membrain-engine/discussions
Author: mrpintcom
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: ai,gateway,llm,membrain,openai,pii,proxy,safety
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Security
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Description-Content-Type: text/markdown

# membrain-client

Python client for the [Membrain](https://membrn.ai) AI Safety Gateway. Drop-in replacement for the OpenAI Python SDK that routes requests through Membrain for PII detection, policy enforcement, cost tracking, and audit logging.

## Installation

```bash
pip install membrain-client
```

## Quick Start

### Synchronous

```python
from membrain_client import MembrainClient

client = MembrainClient(
    base_url="http://localhost:8001",
    api_key="mb-your-api-key",
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)
```

### Async

```python
import asyncio
from membrain_client import AsyncMembrainClient

async def main():
    client = AsyncMembrainClient(
        base_url="http://localhost:8001",
        api_key="mb-your-api-key",
    )
    response = await client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": "Hello!"}],
    )
    print(response.choices[0].message.content)
    await client.aclose()

asyncio.run(main())
```

### Streaming

```python
from membrain_client import MembrainClient

client = MembrainClient(base_url="http://localhost:8001", api_key="mb-your-api-key")

stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Tell me a joke."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")
```

## Configuration

| Parameter | Default | Description |
|---|---|---|
| `base_url` | `http://localhost:8001` | Membrain gateway URL |
| `api_key` | `None` | Membrain API key |
| `user_id` | `None` | User identifier for audit trails |
| `project` | `None` | Project scope for multi-tenant setups |
| `timeout` | `120.0` | Request timeout in seconds |
| `max_retries` | `3` | Retry count for 429/5xx errors |

## Requirements

- Python 3.10+
- [httpx](https://www.python-httpx.org/) >= 0.27

## License

Apache-2.0