OpenClaw Python Integration: SDK, API & Custom Skills Guide (2026)
Python is the most popular language for AI development, and OpenClaw provides first-class Python support. Whether you want to call OpenClaw from a Python script, build custom skills, or integrate with LangChain and CrewAI, this guide covers everything you need.
1. OpenClaw Python SDK
Installation
pip install openclaw-sdk
Basic Usage
from openclaw import OpenClaw
client = OpenClaw(
base_url="http://localhost:3000", # Your OpenClaw gateway
api_key="your-api-key"
)
# Send a message and get a response
response = client.chat("Summarize my latest emails")
print(response.text)
# Use a specific model
response = client.chat(
"Translate this to French",
model="claude-sonnet-4-6"
)
Conversation Context
# Maintain conversation history
conv = client.conversation()
conv.say("What's the weather in Tokyo?")
conv.say("What about tomorrow?") # Remembers context
2. REST API Integration
If you prefer direct HTTP calls, OpenClaw exposes a REST API:
import requests
response = requests.post(
"http://localhost:3000/api/v1/chat",
headers={"Authorization": "Bearer your-api-key"},
json={
"message": "Search for recent AI papers on arXiv",
"model": "claude-sonnet-4-6",
"tools": ["web-search", "browser"]
}
)
result = response.json()
print(result["reply"])
Async Support
import aiohttp
import asyncio
async def ask_openclaw(question: str) -> str:
async with aiohttp.ClientSession() as session:
async with session.post(
"http://localhost:3000/api/v1/chat",
headers={"Authorization": "Bearer your-api-key"},
json={"message": question}
) as resp:
data = await resp.json()
return data["reply"]
# Run async
answer = asyncio.run(ask_openclaw("What are today's top HN stories?"))
3. Custom Skill Development in Python
OpenClaw skills extend your agent's capabilities. You can write skills in Python and register them with the gateway.
Basic Skill Structure
# skills/stock_price.py
from openclaw.skills import skill, SkillContext
@skill(
name="stock-price",
description="Get real-time stock prices",
parameters={
"symbol": {"type": "string", "description": "Stock ticker symbol"}
}
)
async def get_stock_price(ctx: SkillContext, symbol: str) -> str:
import yfinance as yf
stock = yf.Ticker(symbol)
price = stock.info.get("currentPrice", "N/A")
return f"{symbol}: ${price}"
Registering Skills
# Register with OpenClaw gateway
openclaw skills register ./skills/stock_price.py
Once registered, you can ask your AI: "What's the current price of AAPL?" and it will automatically invoke your skill.
Advanced Skill with Multiple Tools
# skills/data_analyzer.py
from openclaw.skills import skill, SkillContext
import pandas as pd
@skill(
name="analyze-csv",
description="Analyze CSV data and generate insights",
parameters={
"file_path": {"type": "string", "description": "Path to CSV file"},
"question": {"type": "string", "description": "Analysis question"}
}
)
async def analyze_csv(ctx: SkillContext, file_path: str, question: str) -> str:
df = pd.read_csv(file_path)
summary = f"Dataset: {len(df)} rows, {len(df.columns)} columns\n"
summary += f"Columns: {', '.join(df.columns)}\n"
summary += f"\nBasic stats:\n{df.describe().to_string()}"
# Use the AI to interpret the data
interpretation = await ctx.ask_ai(
f"Given this data summary:\n{summary}\n\nAnswer: {question}"
)
return interpretation
4. Integration with LangChain
Use OpenClaw as a tool within LangChain agents (see also our Top 20 AI Agents ranking for how LangChain compares):
from langchain.tools import Tool
from openclaw import OpenClaw
client = OpenClaw(base_url="http://localhost:3000", api_key="your-key")
openclaw_tool = Tool(
name="OpenClaw",
description="Send tasks to OpenClaw AI assistant for execution",
func=lambda q: client.chat(q).text
)
# Use in a LangChain agent
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o")
agent = initialize_agent(
tools=[openclaw_tool],
llm=llm,
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
)
agent.run("Use OpenClaw to check my unread Slack messages")
5. Integration with CrewAI
Use OpenClaw as a tool in CrewAI agent crews:
from crewai import Agent, Task, Crew
from crewai_tools import tool
from openclaw import OpenClaw
client = OpenClaw(base_url="http://localhost:3000", api_key="your-key")
@tool("OpenClaw Messenger")
def send_via_openclaw(message: str, platform: str = "slack") -> str:
"""Send a message through OpenClaw to any connected platform."""
return client.send(platform=platform, message=message).status
researcher = Agent(
role="Research Analyst",
goal="Research market trends and report findings",
tools=[send_via_openclaw],
)
task = Task(
description="Research AI agent market trends and send a summary to Slack",
agent=researcher,
)
crew = Crew(agents=[researcher], tasks=[task])
crew.kickoff()
6. Environment Setup Best Practices
# .env file
OPENCLAW_BASE_URL=http://localhost:3000
OPENCLAW_API_KEY=your-api-key
OPENCLAW_DEFAULT_MODEL=claude-sonnet-4-6
# Load environment variables
from dotenv import load_dotenv
from openclaw import OpenClaw
load_dotenv()
client = OpenClaw() # Reads from environment variables
Conclusion
OpenClaw's Python integration lets you leverage the full power of the AI gateway from Python scripts, Jupyter notebooks, web applications, and AI frameworks like LangChain and CrewAI. Whether you're building custom skills, automating workflows, or integrating multiple AI tools, Python + OpenClaw is a powerful combination.
Get started by installing the SDK: pip install openclaw-sdk
Related Articles
OpenClaw vs CrewAI: Single Gateway vs Multi-Agent Orchestration in 2026
OpenClaw and CrewAI take fundamentally different approaches to AI agents. Compare their architecture, setup, platform integrations, and ideal use cases.
OpenClaw vs AutoGPT: Which AI Agent Framework Should You Choose in 2026?
A comprehensive comparison of OpenClaw and AutoGPT β architecture, privacy, extensibility, and real-world performance. Find out which open-source AI agent is right for you.
Best AI Agents in 2026: Top 20 AI Agent Tools Ranked
The definitive ranking of the 20 best AI agent frameworks and tools in 2026. From OpenClaw to AutoGPT, CrewAI to LangChain β features, pricing, and use cases compared.