Skip to main content

Official Python SDK for the Loomal API — identity, mail, vault, calendar, and Loomal Pay (x402 paywall) for AI agents

Project description

Loomal Python SDK

The official Python SDK for the Loomal API -- identity, mail, vault, calendar, and Loomal Pay for AI agents.

PyPI version Python 3.9+ License: MIT

Installation

pip install loomal-sdk          # core SDK
pip install loomal-sdk[fastapi] # core SDK + FastAPI paywall middleware

The distribution is loomal-sdk on PyPI, but the import name is loomal.

Loomal Pay paywall (FastAPI)

Charge USDC per call on top of any FastAPI route. The dependency does the two-call x402 flow against api.loomal.ai for you.

from fastapi import FastAPI, Depends
from loomal.paywall import require_payment

app = FastAPI()

@app.get(
    "/api/search",
    dependencies=[Depends(require_payment(amount="0.01"))],
)
def search():
    return {"results": [...]}

The dependency reads your seller API key from LOOMAL_API_KEY (or SELLER_LOOMAL_API_KEY) by default. Pass api_key= to override.

Settled payments return a signed receipt and an on-chain USDC transfer on Base. See the full payments guide for the protocol shape and webhook configuration.

For non-FastAPI frameworks, the lower-level helpers are exposed too:

from loomal.paywall import build_challenge_async, verify_and_settle_async, PaywallConfig, PaywallRouteOptions

Webhook signature verification

Loomal sends X-Loomal-Signature: sha256=<hex> (HMAC-SHA256 of the raw request body) along with X-Loomal-Event / X-Loomal-Idempotency-Key. The signing secret is generated by Loomal when you register an endpoint in the Console and shown to you exactly once.

import os
from fastapi import FastAPI, HTTPException, Request
from loomal.webhook import verify_webhook

app = FastAPI()

@app.post("/webhooks/loomal")
async def webhook(request: Request):
    raw = await request.body()
    ok = verify_webhook(
        raw,
        request.headers.get("x-loomal-signature"),
        os.environ["LOOMAL_WEBHOOK_SECRET"],
    )
    if not ok:
        raise HTTPException(400, "invalid signature")
    # de-dupe on x-loomal-idempotency-key, then handle the event.
    # Today the only event type is `payment.received`.

Quick start

from loomal import Loomal

client = Loomal(api_key="loid-...")

me = client.identity.whoami()
print(me.email)

client.mail.send(
    to=["colleague@example.com"],
    subject="Hello from my agent",
    text="Sent via the Loomal Python SDK.",
)

Async usage

from loomal import AsyncLoomal

async with AsyncLoomal(api_key="loid-...") as client:
    me = await client.identity.whoami()
    await client.mail.send(
        to=["colleague@example.com"],
        subject="Hello",
        text="Sent asynchronously.",
    )

Authentication

Pass your API key directly, or set the LOOMAL_API_KEY environment variable:

# Explicit
client = Loomal(api_key="loid-...")

# From environment
import os
os.environ["LOOMAL_API_KEY"] = "loid-..."
client = Loomal()

Both Loomal and AsyncLoomal support context managers for automatic resource cleanup:

with Loomal() as client:
    me = client.identity.whoami()

Usage

Identity

me = client.identity.whoami()
print(me.email, me.display_name)

Vault

The vault is password-manager-style encrypted secret storage (AES-256-GCM at rest). Use client.vault.store() for arbitrary types, or the typed helpers below.

# Simple API key
client.vault.store_api_key("stripe", "sk_live_...")

# OAuth-style client credentials (client id + secret)
client.vault.store_api_key("twitter", {
    "clientId": "abc123",
    "secret": "def456",
})

# Credit card (encrypted at rest — this is a secret vault, not a payment processor)
client.vault.store_card("personal-visa", {
    "cardholder": "Jane Doe",
    "number": "4242 4242 4242 4242",
    "expMonth": "12",
    "expYear": "2029",
    "cvc": "123",
    "zip": "94103",
}, metadata={"brand": "Visa"})

# Shipping address
client.vault.store_shipping_address("home", {
    "name": "Autonomous Agent",
    "line1": "1 Demo Way",
    "city": "San Francisco",
    "state": "CA",
    "postcode": "94103",
    "country": "US",
})

Supported credential types: LOGIN, API_KEY, OAUTH, TOTP, SSH_KEY, DATABASE, SMTP, AWS, CERTIFICATE, CARD, SHIPPING_ADDRESS, CUSTOM.

More resources

The SDK also exposes client.mail, client.calendar, client.logs, and client.did. See the full reference at docs.loomal.ai for request/response shapes, pagination, and end-to-end examples.

Error handling

All API errors raise LoomalError with structured fields:

from loomal import LoomalError

try:
    client.mail.send(to=["a@b.com"], subject="Hi", text="Hello")
except LoomalError as e:
    print(e.status)   # HTTP status code
    print(e.code)     # Error code string
    print(e.message)  # Human-readable message

Types

The SDK returns typed dataclasses, not raw dictionaries. API responses are automatically converted from camelCase to snake_case.

Type Description
IdentityResponse Agent identity details
MessageResponse Email message
ThreadResponse Thread summary
ThreadDetailResponse Thread with messages
CredentialMetadata Vault credential metadata
CredentialWithData Credential with decrypted data
ActivityLog Single activity log entry
LogsStats Aggregated log statistics
TotpResponse Generated TOTP code
DidDocument DID document

Note: The from field in message responses is exposed as from_addrs since from is a reserved keyword in Python.

Requirements

  • Python 3.9+
  • httpx (installed automatically)

Links

License

MIT

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

loomal_sdk-0.6.0.tar.gz (30.7 kB view details)

Uploaded Source

Built Distribution

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

loomal_sdk-0.6.0-py3-none-any.whl (26.5 kB view details)

Uploaded Python 3

File details

Details for the file loomal_sdk-0.6.0.tar.gz.

File metadata

  • Download URL: loomal_sdk-0.6.0.tar.gz
  • Upload date:
  • Size: 30.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for loomal_sdk-0.6.0.tar.gz
Algorithm Hash digest
SHA256 eb1b28ec279c7e2b60657566b08053db48e7da6056d8d0a3d73806877b411fb0
MD5 25ecaf0a6dfff5a0dbbd2e14e0eb05f0
BLAKE2b-256 98321e4c682000f7f47c5892897e86891199d888460196c105a3e1f289e7a4ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for loomal_sdk-0.6.0.tar.gz:

Publisher: publish.yml on loomal-ai/loomal-python

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

File details

Details for the file loomal_sdk-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: loomal_sdk-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 26.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for loomal_sdk-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 09a491fca55215a7ebc67eebfb448d6e3f6fc9745d7699394a913fb8c637b353
MD5 fdd981634fcf87767aab275dac595a0e
BLAKE2b-256 aaf858ed7ec9f1858ffbeb70efcb8205a765a7995cfd527f0c13c71c815e311e

See more details on using hashes here.

Provenance

The following attestation bundles were made for loomal_sdk-0.6.0-py3-none-any.whl:

Publisher: publish.yml on loomal-ai/loomal-python

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