Skip to main content

Official NeutralAI Python SDK for masking sensitive prompt data before it reaches AI applications.

Project description

NeutralAI Python SDK

Package Status

Published on PyPI as neutralai-sdk.

Install

python -m pip install neutralai-sdk

For async web services and batch workers, install the async extra:

python -m pip install "neutralai-sdk[async]"

To work from a local checkout instead:

pip install -e ".[async]"

Point base_url at the hosted gateway (https://api.neutralai.co.uk) in production, or at your own gateway (e.g. http://localhost:8001) for local development.

Usage (sync)

from neutralai_sdk import NeutralAIClient

client = NeutralAIClient(base_url="https://api.neutralai.co.uk", api_key="test-key")
res = client.mask("My email is user@example.com", reversible=False)
print(res.masked_text)

Usage (async)

import asyncio
from neutralai_sdk import AsyncNeutralAIClient

async def main():
    async with AsyncNeutralAIClient(base_url="https://api.neutralai.co.uk", api_key="test-key") as client:
        res = await client.mask("Call me at +90 555 123 45 67")
        print(res.masked_text)

asyncio.run(main())

The async client keeps one httpx.AsyncClient open for connection pooling and retries transient 408, 429, and 5xx responses by default.

Usage (async streaming)

import asyncio
from neutralai_sdk import AsyncNeutralAIClient

async def main():
    async with AsyncNeutralAIClient(
        base_url="https://api.neutralai.co.uk",
        service_token="signed-service-token",
    ) as client:
        async for event in client.chat_stream(
            session_id="session-123",
            prompt="Summarize this text",
            provider="openai",
            model="gpt-4-turbo",
        ):
            if event.type == "token":
                print(event.token, end="")

asyncio.run(main())

Integration registry

The SDK includes a small dependency-free adapter registry for framework wrappers. The default registry exposes langchain, and teams can register their own adapters without adding optional framework dependencies to the core package.

from neutralai_sdk import NeutralAIClient, create_integration

client = NeutralAIClient(base_url="https://api.neutralai.co.uk", agent_token="agent-token")
guard = create_integration("langchain", client, target_agent_id="agent-target")
safe_input = guard.sanitize_input({"input": "Email alice@example.com"})

Supported Endpoints

  • POST /v1/shield/mask
  • POST /v1/shield/unmask
  • POST /v1/agents/mask
  • POST /v1/chat/stream

POST /v1/shield/unmask requires tenant-scoped authentication via API key or service token and only restores reversible vault tokens that still match the stored scope and TTL.

Async Throughput

Use asyncio.gather with one shared AsyncNeutralAIClient to run many requests concurrently while reusing pooled connections:

async with AsyncNeutralAIClient(base_url="https://api.neutralai.co.uk", api_key="...") as client:
    results = await asyncio.gather(*(client.mask(prompt) for prompt in prompts))

In internal local benchmarks with mocked 100 ms network latency, 50 concurrent async requests complete about 10x faster than the same requests issued sequentially through the sync client because the async version overlaps network wait time.

To reproduce the local latency benchmark shape:

python sdk/python/examples/async_benchmark.py

Observability Hooks

You can pass observability_hook to capture SDK request lifecycle events:

  • request_start
  • request_success
  • request_error

Diagnostics are redacted by default:

  • API keys/tokens are reported as <REDACTED>
  • prompt/tokenized values are summarized as <REDACTED len=N>

License

MIT — see LICENSE. This SDK is a thin, dependency-light HTTP client for the NeutralAI Gateway API; all PII detection and masking happens server-side.

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

neutralai_sdk-0.1.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

neutralai_sdk-0.1.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file neutralai_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: neutralai_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for neutralai_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 374cf36dceae30cef1151189e02a3ca5e50daabe0026d89fabeb94b482b3ae0a
MD5 ad810a91ffde5c0f4c13237316cf7070
BLAKE2b-256 cde05d048dfc061e91ea77a09d05e4d5dfeca974d6c3c9e7a3b3d14229c6369f

See more details on using hashes here.

File details

Details for the file neutralai_sdk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: neutralai_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for neutralai_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7b7128cad9cae5d7b14015de4ed5768d5f40a879801c09c323a5d1ae741c0fd9
MD5 a3f72c02dc939f9de99f8b8f4e971424
BLAKE2b-256 942ee7436197d198f5d406dbc9f03ff155c8c78543ecb9fa3c01ad0257bfce76

See more details on using hashes here.

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