Skip to main content

Natural Payments SDK

Project description

Natural Payments Python SDK

Official Python SDK for Natural Payments - AI agent payment infrastructure.

Installation

pip install naturalpay
# or
uv add naturalpay

Quick Start

from naturalpay import NaturalClient

client = NaturalClient(api_key="sk_ntl_sandbox_xxx")

# Create a payment
payment = await client.payments.create(
    agent_id="agt_123",
    instance_id="instance_456",
    amount=5000,
    customer_party_id="pty_456",
    recipient="alice@example.com",
    memo="Payment for consulting",
    idempotency_key="unique-key-for-this-payment",
)

print(f"Payment created: {payment.transaction_id}")

# Check balance
balance = await client.wallet.balance()
print(f"Available: ${balance.available_usd}")

Sync Client

from naturalpay import NaturalClientSync

client = NaturalClientSync(api_key="sk_ntl_sandbox_xxx")
payment = client.payments.create(
    agent_id="agt_123",
    instance_id="instance_456",
    amount=5000,
    customer_party_id="pty_456",
    recipient="alice@example.com",
    memo="Payment for consulting",
    idempotency_key="unique-key-for-this-payment",
)

Configuration

Environment Variables

  • NATURAL_API_KEY - Your API key (starts with sk_ntl_dev_ or sk_ntl_prod_)
  • NATURAL_SERVER_URL - API base URL (default: https://api.natural.co)

Client Options

client = NaturalClient(
    api_key="sk_ntl_dev_xxx",             # API key
    base_url="https://api.natural.co",  # Custom base URL
    timeout=30.0,                     # Request timeout in seconds
)

Resources

Payments

# Create a payment
payment = await client.payments.create(
    agent_id="agt_123",
    amount=10000,
    customer_party_id="pty_456",
    recipient="alice@example.com",  # email, phone, or party ID (pty_xxx)
    memo="Payment description",
    idempotency_key="unique-key-for-this-payment",
    instance_id="instance_789",  # required when agent_id is provided
)

Wallet

# Get wallet balance
balance = await client.wallet.balance()

# Withdraw funds
withdrawal = await client.wallet.withdraw(
    amount=50000,
    external_funding_source_id="efs_xxx",
    idempotency_key="wd_unique_key",
)

Transactions

from naturalpay import TransactionTypeFilter

# List all transactions
transactions = await client.transactions.list(
    limit=100,
    agent_id="agt_123",
    instance_id="instance_789",  # required when agent_id is provided
)

# List only transfers
transfers = await client.transactions.list(
    transaction_type=TransactionTypeFilter.TRANSFER,
)

# List only payments
payments = await client.transactions.list(
    transaction_type=TransactionTypeFilter.PAYMENT,
)

Agents

# List agents
agents = await client.agents.list(status="ACTIVE", limit=50)

# Create an agent
agent = await client.agents.create(
    name="Shopping Assistant",
    description="Handles shopping tasks",
)

# Update an agent
updated = await client.agents.update(
    "agt_xxx",
    name="Updated Name",
    status="REVOKED",
)

# Delete an agent
await client.agents.delete("agt_xxx")

Delegations

# List agent delegations
delegations = await client.delegations.list(limit=50)

# Get delegation details
delegation = await client.delegations.get("adl_xxx")

Customers

# List customers who have delegated to you
customers = await client.customers.list(limit=50)

MCP Integration

The SDK includes a thin MCP proxy that connects AI agents to the hosted Natural MCP server.

CLI Usage

# Using uvx (recommended)
uvx naturalpay mcp serve

# Or using python module
python -m naturalpay mcp serve

# With explicit options
uvx naturalpay mcp serve --api-key sk_ntl_sandbox_xxx --mcp-url https://mcp.natural.co

Claude Desktop / Cursor Config

{
  "mcpServers": {
    "natural": {
      "command": "uvx",
      "args": ["naturalpay", "mcp", "serve"],
      "env": { "NATURAL_API_KEY": "sk_ntl_..." }
    }
  }
}

Environment Variables

Variable Default Description
NATURAL_API_KEY (required) API key
NATURAL_MCP_URL https://mcp.natural.co MCP server endpoint

Internal Dev (local MCP server)

NATURAL_MCP_URL=http://localhost:8080 uvx naturalpay mcp serve

Error Handling

from naturalpay import (
    NaturalError,
    AuthenticationError,
    InvalidRequestError,
    PaymentError,
    InsufficientFundsError,
    RecipientNotFoundError,
    RateLimitError,
    ServerError,
)

try:
    await client.payments.create(...)
except AuthenticationError:
    # Handle authentication issues (401)
    ...
except InsufficientFundsError:
    # Handle insufficient balance
    ...
except RecipientNotFoundError:
    # Handle invalid recipient
    ...
except RateLimitError as e:
    # Handle rate limiting (429)
    print(f"Retry after: {e.retry_after}s")
except ServerError:
    # Handle server errors (5xx)
    ...
except NaturalError as e:
    # Handle other API errors
    print(f"Error: {e.message}, Code: {e.code}")

Type Support

This SDK uses Pydantic models and provides full type definitions:

from naturalpay import (
    AccountBalance,
    Transaction,
    TransactionTypeFilter,
    TransactionListResponse,
    Agent,
    AgentDelegation,
    WithdrawResponse,
)

Documentation

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

naturalpay-0.1.2.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

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

naturalpay-0.1.2-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

Details for the file naturalpay-0.1.2.tar.gz.

File metadata

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

File hashes

Hashes for naturalpay-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c0c6e8f3b0ed9ebbb67a562e3209b7ff0d9af0c7dca1a4073ed50e11bd1649f4
MD5 0a6b2ebb6f191bf078063fa601ea1c4e
BLAKE2b-256 3272de2bda866856212701f319f17ef6badaf5fd6c45c5f594429aeed1f11c67

See more details on using hashes here.

Provenance

The following attestation bundles were made for naturalpay-0.1.2.tar.gz:

Publisher: release.yml on naturalpay/naturalpay-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 naturalpay-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: naturalpay-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 28.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for naturalpay-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c47da75fb0eabb0c187e65e7a0b1314f056f53400bbbd5700c4c7d64d2f08e28
MD5 bc4606c84615b614f42f7f392e48d222
BLAKE2b-256 ef74e7892933cd396c5b39d550e1c54705027e81284954bcf89a6fb6aa611986

See more details on using hashes here.

Provenance

The following attestation bundles were made for naturalpay-0.1.2-py3-none-any.whl:

Publisher: release.yml on naturalpay/naturalpay-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