v0.1.1 · Python 3.10+ · MIT · Frappe 14, 15, 16
Talk to Frappe & ERPNext from Python. Typed, async‑ready, secure by default.
frappex-client is a small, fully typed client for the Frappe REST API. One import gives you a blocking and an asyncio client with the same methods, real exceptions instead of raw JSON errors, pagination that just works, and retries that never duplicate a record.
pip install frappex-client
from frappex_client import Client, TokenAuth, NotFoundError
with Client(ERP_URL, TokenAuth(key, secret)) as erp:
order = erp.insert("Sales Order", order_data)
erp.submit("Sales Order", order["name"])
for row in erp.iter_list(
"Sales Order",
fields=["name", "grand_total"],
filters={"status": "To Deliver"},
):
print(row["name"], row["grand_total"])
try:
erp.get_doc("Customer", "Nobody")
except NotFoundError:
print("no such customer")
from frappex_client import AsyncClient, TokenAuth, NotFoundError
async with AsyncClient(ERP_URL, TokenAuth(key, secret)) as erp:
order = await erp.insert("Sales Order", order_data)
await erp.submit("Sales Order", order["name"])
async for row in erp.iter_list(
"Sales Order",
fields=["name", "grand_total"],
filters={"status": "To Deliver"},
):
print(row["name"], row["grand_total"])
try:
await erp.get_doc("Customer", "Nobody")
except NotFoundError:
print("no such customer")
httpxThe difference
Stop hand-rolling HTTP calls to your ERP
The same query, written twice. frappex-client builds the URL, encodes the filters, sends the credentials, checks the status and decodes the reply, and it raises an exception you can actually catch.
Without frappex-client
import json, requests
r = requests.get(
f"{url}/api/resource/Customer",
headers={"Authorization": f"token {key}:{secret}"},
params={
"filters": json.dumps({"territory": "India"}),
"fields": json.dumps(["name", "customer_name"]),
"limit_page_length": 20, # and then loop for page 2…
},
timeout=30,
)
r.raise_for_status() # 417? 409? which field failed?
customers = r.json()["data"]
With frappex-client
customers = list(erp.iter_list(
"Customer",
filters={"territory": "India"},
fields=["name", "customer_name"],
))
# every page, in a stable order;
# ValidationError / ConflictError /
# PermissionDeniedError on failure
Everything you need
Small API, carefully engineered
Sync and async, one API
Client and AsyncClient share one implementation, so they can never drift apart.
Typed exceptions
401, 403, 404, 409, 417, 429 and 5xx each become their own exception, with the server's message attached.
Retries that are safe
Reads and rate-limited calls are retried with backoff. Writes never are, so a retry can't create a duplicate.
Pagination built in
iter_list walks every page in a stable order, so edits during the walk don't skip or repeat rows.
Secure by default
HTTPS only, certificate checks always on, no redirects followed, secrets masked in every log and repr.
Files, private first
Upload, attach and stream files. Uploads are private unless you say otherwise.
Fully typed
Checked with mypy --strict and shipped with py.typed, so your editor autocompletes everything.
Easy to test against
Plug in an httpx mock transport and test your own code without a Frappe site.
Under the hood
One call, end to end
Every method is a pure description of a request plus a parser for the reply. The two clients only differ in how they send it.
- Your code
erp.get_doc("ToDo", "T/1") - Operationpath
/api/resource/ToDo/T%2F1, names safely encoded - TransportHTTPS, timeout, size limit, no redirects
- Retry policyreads and 429s only, bounded backoff
- DecodeJSON → document, or the right exception
Use cases
Built for code that lives outside your site
Sync other systems
Push customers and orders from a webshop, CRM or form backend into ERPNext.
Async web apps
Share one AsyncClient across a FastAPI service and serve ERP data fast.
Reports and pipelines
Stream every row of a DocType to CSV, a warehouse or a dashboard.
Scheduled jobs
Cron jobs and workers that create, update and reconcile records safely.
Your own API
Call the whitelisted methods of your custom Frappe apps with typed errors.
Monitoring
Health-check any site without credentials using guest access.
Quick start
From zero to your first call
Install
pip install frappex-clientCreate an API key
In your site, open User → your user → Settings → API Access and click Generate Keys. Copy the secret: it is shown once.
Make the call
import os from frappex_client import Client, TokenAuth auth = TokenAuth(os.environ["ERP_KEY"], os.environ["ERP_SECRET"]) with Client("https://erp.example.com", auth) as erp: print(erp.get_logged_user())