Sellfern’s Python agent example shows how to wire Claude — via the Anthropic Python SDK — to Sellfern REST endpoints so Claude can answer natural language questions about your business. You describe what you want in plain English, and Claude decides which API calls to make, executes them against the live Sellfern API, and returns a structured answer.Documentation Index
Fetch the complete documentation index at: https://docs.sellfern.com/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- Python 3.11 or later
- A Sellfern API token with at least the
orders:readandanalytics:readscopes - An Anthropic API key (available at console.anthropic.com)
Setup
Navigate to the example directory
From the root of the Sellfern project directory, change into the Python agent example:
Set environment variables
SELLFERN_API_URL to http://localhost:3000 if you are running a local Sellfern instance.Example usage
How it works
The agent exposes two built-in tools to Claude:| Tool | Sellfern endpoint | Description |
|---|---|---|
list_orders | GET /api/v2/orders | Filter orders by status, store ID, or search query with pagination |
get_analytics_summary | GET /api/v2/analytics/summary | Revenue, order count, COGS, gross profit, and margin for a period |
- Your prompt is sent to Claude with both tool definitions attached.
- Claude returns a
tool_useblock specifying which tool to call and what arguments to pass. - The script executes the tool — a real HTTP call to
SELLFERN_API_URLusing your token. - The tool result is sent back to Claude as a
tool_resultmessage. - Steps 2–4 repeat until Claude produces a final text response with no further tool calls.
Extending the agent
To expose more Sellfern endpoints as tools, follow the three-step pattern from the README:- Write a Python function that calls the endpoint using
_sellfern_get(for GET requests) or a_sellfern_posthelper you add for mutations. - Add a tool definition to the
TOOLSlist using the same JSON schema format as the existing tools. - Add a dispatch branch in
run_tool()that maps the tool name to your new function.
PATCH /api/v2/orders/:id/status→update_order_statusPOST /api/v2/orders/bulk-status→bulk_update_order_statusGET /api/v2/analytics/by-store→get_analytics_by_storeGET /api/v2/fulfillment/queue→list_fulfillment_queue
The Python agent is a thin wrapper around Sellfern’s REST API — it does not have its own data store or cache. Every tool call makes a live HTTP request to
SELLFERN_API_URL, so the results are always up to date. The REST API is the source of truth.