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.0.tar.gz
(17.6 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.0-py3-none-any.whl
(13.7 kB
view details)
File details
Details for the file moltspay-0.2.0.tar.gz.
File metadata
- Download URL: moltspay-0.2.0.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3af255ae22b6172ba749477051cd0d856f585930c679c9619242328f71b5035f
|
|
| MD5 |
bf607559b3ef276fc38a336c627acaa5
|
|
| BLAKE2b-256 |
922204d7f7c884bb8c09230ae59b8651a8701a28b0fe205c7ff5ebbe310648d0
|
File details
Details for the file moltspay-0.2.0-py3-none-any.whl.
File metadata
- Download URL: moltspay-0.2.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
624d149fd0d78037df1f4d20c846cfb049eee908ae8171668cef1dc4190bdbb8
|
|
| MD5 |
23e028754d2d7c11380adab78115b488
|
|
| BLAKE2b-256 |
6c13bc9f2fc9daca29cfe661683d833979f4f352befb1272aed843d6b2175200
|