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 servicesMoltsPayDiscoverTool- 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
- Docs: https://moltspay.com
- NPM (Node.js): https://npmjs.com/package/moltspay
- GitHub: https://github.com/Yaqing2023/moltspay-python
License
MIT
Project details
Release history Release notifications | RSS feed
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.2.tar.gz
(18.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
moltspay-0.2.2-py3-none-any.whl
(14.3 kB
view details)
File details
Details for the file moltspay-0.2.2.tar.gz.
File metadata
- Download URL: moltspay-0.2.2.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40e52c2186459d0615288e371d791ff79b7d9015d1f2627e261d9519bd8e35b7
|
|
| MD5 |
644cd2510edfce16b68a2e72dcf6a7d9
|
|
| BLAKE2b-256 |
22dca94475ae687b29bc5254c49d3a17610cc391b5927b481ebbcd8d89ae12d5
|
File details
Details for the file moltspay-0.2.2-py3-none-any.whl.
File metadata
- Download URL: moltspay-0.2.2-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebdaff0f23223ee56457fd210161663eabd1da938b31823d952ea3e67d920815
|
|
| MD5 |
2136ac2fbf6a5985d490b4bf2bb00b19
|
|
| BLAKE2b-256 |
147adca014a593a500b2c88bddd91be6443760e92160ab3091f2c2460dea631e
|