Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

membrain_client-0.1.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

membrain_client-0.1.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

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

Hashes for membrain_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b84da473a28fc214a247965f2de4884df1efd5d44496a5042d976c08ba42ffe0
MD5 64f03455dee619c18ac6954f8bf2f517
BLAKE2b-256 319dd73eedaf61800ff5fbb658aa61a02ec8cc43c422c40c8603f88d32dbe55f

See more details on using hashes here.

Provenance

The following attestation bundles were made for membrain_client-0.1.0.tar.gz:

Publisher: pypi-publish.yml on mrpintcom/membrain

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for membrain_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dbd5e7c6a44cee123d433eca3bff27b0088684470ef078ee7f5690bf04f26f82
MD5 393f5d7b16f5b2a3c9ce49a7076527c3
BLAKE2b-256 9beb5910d610704c6f615a00d0076a619418a894a8f391bfbcf5061d4f7cec59

See more details on using hashes here.

Provenance

The following attestation bundles were made for membrain_client-0.1.0-py3-none-any.whl:

Publisher: pypi-publish.yml on mrpintcom/membrain

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page