Python client for Membrain AI Safety Gateway — drop-in replacement for OpenAI SDK
Project description
membrain-client
Python client for the Membrain 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
pip install membrain-client
Quick Start
Synchronous
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
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
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 >= 0.27
License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file membrain_client-0.1.0.tar.gz.
File metadata
- Download URL: membrain_client-0.1.0.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b84da473a28fc214a247965f2de4884df1efd5d44496a5042d976c08ba42ffe0
|
|
| MD5 |
64f03455dee619c18ac6954f8bf2f517
|
|
| BLAKE2b-256 |
319dd73eedaf61800ff5fbb658aa61a02ec8cc43c422c40c8603f88d32dbe55f
|
Provenance
The following attestation bundles were made for membrain_client-0.1.0.tar.gz:
Publisher:
pypi-publish.yml on mrpintcom/membrain
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
membrain_client-0.1.0.tar.gz -
Subject digest:
b84da473a28fc214a247965f2de4884df1efd5d44496a5042d976c08ba42ffe0 - Sigstore transparency entry: 1675626771
- Sigstore integration time:
-
Permalink:
mrpintcom/membrain@089d3d76ffc292a9a4bada8f1986122b7b6a83c3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/mrpintcom
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
self-hosted -
Publication workflow:
pypi-publish.yml@089d3d76ffc292a9a4bada8f1986122b7b6a83c3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file membrain_client-0.1.0-py3-none-any.whl.
File metadata
- Download URL: membrain_client-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbd5e7c6a44cee123d433eca3bff27b0088684470ef078ee7f5690bf04f26f82
|
|
| MD5 |
393f5d7b16f5b2a3c9ce49a7076527c3
|
|
| BLAKE2b-256 |
9beb5910d610704c6f615a00d0076a619418a894a8f391bfbcf5061d4f7cec59
|
Provenance
The following attestation bundles were made for membrain_client-0.1.0-py3-none-any.whl:
Publisher:
pypi-publish.yml on mrpintcom/membrain
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
membrain_client-0.1.0-py3-none-any.whl -
Subject digest:
dbd5e7c6a44cee123d433eca3bff27b0088684470ef078ee7f5690bf04f26f82 - Sigstore transparency entry: 1675626777
- Sigstore integration time:
-
Permalink:
mrpintcom/membrain@089d3d76ffc292a9a4bada8f1986122b7b6a83c3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/mrpintcom
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
self-hosted -
Publication workflow:
pypi-publish.yml@089d3d76ffc292a9a4bada8f1986122b7b6a83c3 -
Trigger Event:
push
-
Statement type: