frappex-client v0.1.1

Guides

Calling methods#

Frappe exposes Python functions decorated with @frappe.whitelist() at /api/method/<dotted.path>. call invokes them and returns what they return.

result = client.call("frappe.client.get_count", {"doctype": "ToDo"}, http_method="GET")

Your own app's API#

Suppose your custom app has this server code:

# myapp/api.py, inside your Frappe app
import frappe


@frappe.whitelist()
def monthly_summary(year, month):
    return {"orders": 42, "revenue": 125000}


@frappe.whitelist(methods=["POST"])
def approve_order(order, note=None):
    doc = frappe.get_doc("Sales Order", order)
    doc.add_comment("Comment", note or "Approved")
    return {"ok": True}

From any Python program:

summary = client.call("myapp.api.monthly_summary", {"year": 2026, "month": 11}, http_method="GET")
print(summary["revenue"])

client.call("myapp.api.approve_order", {"order": "SO-0001", "note": "Checked stock"})
summary = await client.call(
    "myapp.api.monthly_summary", {"year": 2026, "month": 11}, http_method="GET"
)
print(summary["revenue"])

await client.call("myapp.api.approve_order", {"order": "SO-0001", "note": "Checked stock"})

GET or POST#

http_method="POST" (default) http_method="GET"
Arguments travel as a JSON body query-string parameters
Nested values sent as JSON lists and dicts are JSON-encoded strings
Retried automatically no yes, on network errors and 502/503/504
Use for anything that changes data read-only methods

Use GET for methods that only read, so a flaky network is handled for you. Keep the default POST for anything that writes: a repeated POST could apply the change twice.

Note

A method whitelisted with methods=["POST"] refuses GET, and one limited to GET refuses POST. Frappe answers with an error that frappex-client raises as an APIError subclass.

Return values#

call returns the message field of Frappe's reply, already decoded: a dict, list, string, number, or None for a method that returns nothing.

Errors from your methods#

frappe.throw and exceptions raised in your method come back as frappex-client exceptions with the message attached:

from frappex_client import PermissionDeniedError, ValidationError

try:
    client.call("myapp.api.approve_order", {"order": "SO-0001"})
except ValidationError as error:
    print(error.server_messages)  # ("Order SO-0001 is already approved",)
except PermissionDeniedError:
    print("not allowed")

Method names#

The method must be a dotted Python path such as myapp.api.approve_order. Anything else (slashes, spaces, ..) raises ConfigurationError before a request is sent, so a method name can never be used to reach another route.

Guest methods#

Methods whitelisted with allow_guest=True can be called without credentials, using a client with guest access.

Found a mistake? Open an issue.