Skip to main content

Python SDK for MoltsPay - Agent-to-Agent Payments. LangChain compatible.

Project description

MoltsPay Python SDK

Python SDK for MoltsPay - Agent-to-Agent Payments.

Installation

pip install moltspay

Quick Start

from moltspay import MoltsPay

# Initialize (auto-creates wallet if not exists)
client = MoltsPay()
print(f"Wallet address: {client.address}")

# Discover services
services = client.discover("https://juai8.com/zen7")
for svc in services:
    print(f"{svc.id}: {svc.price} {svc.currency}")

# Pay for a service
result = client.pay(
    "https://juai8.com/zen7",
    "text-to-video",
    prompt="a cat dancing on the beach"
)
print(result.result)

Features

  • Auto wallet management - Creates wallet on first run, compatible with Node.js CLI
  • Spending limits - Set per-transaction and daily limits
  • x402 protocol - Native support for HTTP 402 payment flow
  • Gasless payments - Uses EIP-2612 permits, no ETH needed for clients
  • LangChain integration - Use as a tool in LangChain agents

Wallet Management

from moltspay import MoltsPay

# Wallet auto-created at ~/.moltspay/wallet.json
client = MoltsPay()

# Check limits
limits = client.limits()
print(f"Max per tx: {limits.max_per_tx}")
print(f"Spent today: {limits.spent_today}")

# Update limits
client.set_limits(max_per_tx=20, max_per_day=200)

Async Support

import asyncio
from moltspay import AsyncMoltsPay

async def main():
    async with AsyncMoltsPay() as client:
        result = await client.pay(
            "https://juai8.com/zen7",
            "text-to-video",
            prompt="a cat dancing"
        )
        print(result.result)

asyncio.run(main())

Error Handling

from moltspay import MoltsPay, InsufficientFunds, LimitExceeded, PaymentError

client = MoltsPay()

try:
    result = client.pay(...)
except InsufficientFunds as e:
    print(f"Need {e.required} USDC, have {e.balance}")
except LimitExceeded as e:
    print(f"Exceeds {e.limit_type} limit: {e.amount} > {e.limit}")
except PaymentError as e:
    print(f"Payment failed: {e}")

LangChain Integration

Use MoltsPay as a tool in your LangChain agents:

pip install moltspay[langchain]
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
from moltspay.integrations.langchain import MoltsPayTool

llm = ChatOpenAI(model="gpt-4")
tools = [MoltsPayTool()]

agent = initialize_agent(
    tools, 
    llm, 
    agent=AgentType.OPENAI_FUNCTIONS,
    verbose=True
)

# Agent can now pay for AI services!
result = agent.run("Generate a video of a cat dancing on the beach")

Two tools available:

  • MoltsPayTool - Pay for and execute services
  • MoltsPayDiscoverTool - Discover available services and prices
from moltspay.integrations.langchain import get_moltspay_tools

tools = get_moltspay_tools()  # Returns both tools

CLI Compatibility

Wallet format is compatible with Node.js CLI:

# Create wallet with Node CLI
npx moltspay init --chain base

# Use same wallet in Python
python -c "from moltspay import MoltsPay; print(MoltsPay().address)"

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

moltspay-0.2.1.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

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

moltspay-0.2.1-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file moltspay-0.2.1.tar.gz.

File metadata

  • Download URL: moltspay-0.2.1.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for moltspay-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3ed62b8b44f12116dc2e10192ab87758f34a3f0b62140d7c6195f2652aa1d6c7
MD5 b06c1fceae5c25d9f0ed425b996d3089
BLAKE2b-256 474decf5d967e9f45c6244bf9b77a4c88cca6ddc2f9e706a6fd275cd67f9cb63

See more details on using hashes here.

File details

Details for the file moltspay-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: moltspay-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for moltspay-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cee466bb4e951693ec8ef4210d47c6e6b3aff49d1bfff30a509784a5ccd57e6c
MD5 37aadd5ced33f3f6b401526aa58790a4
BLAKE2b-256 eb0f1eb777c14b4a07da8bd745c967d138f31ecead587ab5c92a6459bc84e641

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