Why frappex-client#
Every Frappe and ERPNext site has a REST API. frappex-client is the Python package for the other end of that connection: the code that runs outside your site and reads or writes its data.
The problem#
Frappe publishes no maintained Python client on PyPI. The official
frappe-client repository is archived and was never published to PyPI, so
projects that talk to a Frappe site usually do one of two things:
- install an unmaintained package, or
- write raw HTTP calls with
requestsand solve the same problems again.
The second option looks simple until it meets production:
import json
import requests
response = requests.get(
"https://erp.example.com/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,
},
timeout=30,
)
response.raise_for_status()
customers = response.json()["data"]
That code only reads the first 20 customers. A 417 error tells you nothing
about which field was wrong, because the message is buried in Frappe's
_server_messages JSON. If the request is ever retried after a timeout, an
insert can create the same document twice. And nothing stops a teammate from
adding verify=False to get past a certificate error.
What frappex-client does instead#
customers = list(
erp.iter_list("Customer", filters={"territory": "India"}, fields=["name", "customer_name"])
)
| Problem with hand-written calls | What frappex-client does |
|---|---|
No asyncio support for FastAPI, bots and other async programs |
AsyncClient with exactly the same methods as Client |
| The API returns 20 rows by default; reading everything needs a loop | iter_list walks every page in a stable order |
| Errors arrive as Frappe's own JSON and must be decoded | A typed exception per failure, with the server's message attached |
| A retried insert can create a duplicate document | Only safe requests are retried; writes never are |
| TLS checks get switched off and keys end up in logs | HTTPS only, certificate checks always on, secrets masked |
| No editor help | Fully typed and checked with mypy --strict |
| Hard to test the code that talks to the ERP | Plug in an httpx mock transport |
Design principles#
Small surface, deep behaviour. Seventeen methods cover documents, lists, values, workflow, methods and files. Everything else (encoding, paging, retries, error decoding, sessions) happens behind them.
One implementation, two clients. The Frappe wire format is written once as
plain functions with no network code. Client and AsyncClient are thin
shells that only differ in how they send a request, so they cannot drift
apart. See Architecture.
Safe by default, not by configuration. The secure behaviour is the only behaviour. There is no switch to disable certificate checks, follow redirects or retry a write.
One dependency. frappex-client depends on httpx and nothing else.
Tested against the real thing. Every change runs an integration suite against fresh Frappe 14, 15 and 16 sites, plus 190+ unit tests, CodeQL, secret scanning and a dependency audit.
When not to use it#
- Code running inside a Frappe app. Server-side code already has
frappe.get_doc,frappe.get_listand the rest. Going over HTTP would only add latency. - Realtime events. frappex-client does not speak Socket.IO.
- Reports and print formats. There are no dedicated helpers yet; call the
underlying whitelisted method with
call. - The
/api/v2routes. frappex-client uses/api/resourceand/api/method, which every supported version serves. v2 support is planned.
Is it official?#
No. frappex-client is an independent community project under the MIT licence. It is not affiliated with or endorsed by Frappe Technologies.
Ready? Get started →