Skip to main content

Python client SDK for NornWeave - Inbox-as-a-Service API for AI Agents

Project description

NornWeave Python Client

The NornWeave Python library provides convenient access to the NornWeave APIs from Python.

Table of Contents

Installation

pip install nornweave-client

Or install from source using uv (recommended) or pip:

cd clients/python

# Using uv (recommended)
uv pip install -e .

# Or with pip
pip install -e .

Usage

Instantiate and use the client with the following:

from nornweave_client import NornWeave

client = NornWeave(base_url="http://localhost:8000")

# Create an inbox
inbox = client.inboxes.create(name="Support", email_username="support")
print(f"Created inbox: {inbox.email_address}")

# List inboxes
for inbox in client.inboxes.list():
    print(inbox.name)

# Get an inbox
inbox = client.inboxes.get(inbox_id="...")

# Delete an inbox
client.inboxes.delete(inbox_id="...")

# Send a message
response = client.messages.send(
    inbox_id="...",
    to=["recipient@example.com"],
    subject="Hello",
    body="This is the message body in **Markdown**."
)

# List messages
for message in client.messages.list(inbox_id="..."):
    print(message.content_clean)

# List threads
for thread in client.threads.list(inbox_id="..."):
    print(f"{thread.subject} - {thread.message_count} messages")

# Get thread with messages
thread = client.threads.get(thread_id="...")
for msg in thread.messages:
    print(f"{msg.role}: {msg.content}")

# Search messages
results = client.search.query(query="invoice", inbox_id="...")
for result in results:
    print(result.content_clean)

Async Client

The SDK also exports an async client so that you can make non-blocking calls to our API.

import asyncio
from nornweave_client import AsyncNornWeave

client = AsyncNornWeave(base_url="http://localhost:8000")

async def main() -> None:
    inbox = await client.inboxes.create(name="Support", email_username="support")
    print(f"Created inbox: {inbox.email_address}")

asyncio.run(main())

Exception Handling

When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error will be thrown.

from nornweave_client import ApiError

try:
    client.inboxes.get(inbox_id="nonexistent")
except ApiError as e:
    print(e.status_code)  # 404
    print(e.body)         # {"detail": "Inbox not found"}

Specific exception types:

  • NotFoundError - 404 responses
  • ValidationError - 422 responses (invalid request data)
  • RateLimitError - 429 responses
  • ServerError - 5xx responses

Advanced

Access Raw Response Data

The SDK provides access to raw response data, including headers, through the .with_raw_response property.

response = client.inboxes.with_raw_response.create(
    name="Support",
    email_username="support"
)
print(response.headers)      # httpx.Headers
print(response.status_code)  # 201
print(response.data)         # Inbox object

Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).

A request is deemed retryable when any of the following HTTP status codes is returned:

  • 408 (Timeout)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

Use the max_retries request option to configure this behavior.

client.inboxes.create(
    name="Support",
    email_username="support",
    request_options={"max_retries": 1}
)

Timeouts

The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.

from nornweave_client import NornWeave

# Client-level timeout
client = NornWeave(
    base_url="http://localhost:8000",
    timeout=20.0,
)

# Request-level timeout override
client.inboxes.create(
    name="Support",
    email_username="support",
    request_options={"timeout": 5.0}
)

Custom Client

You can override the httpx client to customize it for your use-case. Some common use-cases include support for proxies and transports.

import httpx
from nornweave_client import NornWeave

client = NornWeave(
    base_url="http://localhost:8000",
    httpx_client=httpx.Client(
        proxy="http://my.test.proxy.example.com",
        transport=httpx.HTTPTransport(local_address="0.0.0.0"),
    ),
)

For async:

import httpx
from nornweave_client import AsyncNornWeave

client = AsyncNornWeave(
    base_url="http://localhost:8000",
    httpx_client=httpx.AsyncClient(
        proxy="http://my.test.proxy.example.com",
    ),
)

Pagination

Paginated requests will return a SyncPager or AsyncPager, which can be used as generators for the underlying objects.

# Iterate over all items
for inbox in client.inboxes.list():
    print(inbox.name)

# Paginate page-by-page
for page in client.inboxes.list().iter_pages():
    print(f"Page with {len(page.items)} items")
    for inbox in page.items:
        print(inbox.name)

# Async iteration
async for inbox in async_client.inboxes.list():
    print(inbox.name)

Releasing

Instruction for Python client developers.

Version Bumping

cd clients/python

# Patch release (0.1.0 → 0.1.1)
uv version patch

# Minor release (0.1.1 → 0.2.0)
uv version minor

# Major release (0.2.0 → 1.0.0)
uv version major

Publishing

  1. Bump version and commit:

    uv version patch
    git add pyproject.toml uv.lock
    git commit -m "chore: release v$(grep '^version' pyproject.toml | cut -d'"' -f2)"
    
  2. Create and push tag:

    VERSION=$(grep '^version' pyproject.toml | cut -d'"' -f2)
    git tag "v$VERSION"
    git push origin main --tags
    
  3. GitHub Actions automatically publishes to PyPI with attestations.

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

nornweave_client-0.1.0.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

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

nornweave_client-0.1.0-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file nornweave_client-0.1.0.tar.gz.

File metadata

  • Download URL: nornweave_client-0.1.0.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nornweave_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b5ee670828b9554a4429c0627cff3b471e7a3f4533abb1245e3d0a97d921233c
MD5 00886f11b78eac99fa5ae1fc27e1c6fe
BLAKE2b-256 6da06523d21669970b33ac9dac7e89ea5bee1a0a3dc0306ad6089b9888b84545

See more details on using hashes here.

Provenance

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

Publisher: release.yml on DataCovey/nornweave

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

File details

Details for the file nornweave_client-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for nornweave_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b623d717ba49d5b4c2e57007a9276c53ae1d8eb4621ab1cae9b0730ec25dbea
MD5 2493725b2b3dce9b37e215d95510efe3
BLAKE2b-256 fdbb40711c7f0ac8d03fa03fcdb46ebd67f60f5475f093a1015153bd521c3bab

See more details on using hashes here.

Provenance

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

Publisher: release.yml on DataCovey/nornweave

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