Skip to main content

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

Metadata

Release files for membrain-client 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for membrain-client 0.1.0
File Size Uploaded Provenance Actions
membrain_client-0.1.0.tar.gz 17.6 kB With provenance Details for membrain_client-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for membrain-client 0.1.0
File Interpreter ABI Platform Actions
membrain_client-0.1.0-py3-none-any.whl Python 3 none any Details for membrain_client-0.1.0-py3-none-any.whl

Total release size: 31.0 kB

Release files / membrain_client-0.1.0.tar.gz

Download URL membrain_client-0.1.0.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b84da473a28fc214a247965f2de4884df1efd5d44496a5042d976c08ba42ffe0
BLAKE2b-256 checksum
How to use checksums
319dd73eedaf61800ff5fbb658aa61a02ec8cc43c422c40c8603f88d32dbe55f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 30, 2026.

Transparency log

Release files / membrain_client-0.1.0-py3-none-any.whl

Download URL membrain_client-0.1.0-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dbd5e7c6a44cee123d433eca3bff27b0088684470ef078ee7f5690bf04f26f82
BLAKE2b-256 checksum
How to use checksums
9beb5910d610704c6f615a00d0076a619418a894a8f391bfbcf5061d4f7cec59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 30, 2026.

Transparency log

Security for membrain-client 0.1.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for membrain_client-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 30, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page