frappex-client v0.1.1

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
orders.py
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")
3Frappe versions tested live on every change
97%test coverage, 190+ unit tests
1runtime dependency: httpx
0ways to switch TLS checks off

The 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

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.

  1. Your codeerp.get_doc("ToDo", "T/1")
  2. Operationpath /api/resource/ToDo/T%2F1, names safely encoded
  3. TransportHTTPS, timeout, size limit, no redirects
  4. Retry policyreads and 429s only, bounded backoff
  5. DecodeJSON → document, or the right exception

Read the architecture →

Quick start

From zero to your first call

  1. Install

    pip install frappex-client
    
  2. Create an API key

    In your site, open User → your user → Settings → API Access and click Generate Keys. Copy the secret: it is shown once.

  3. 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())