frappex-client v0.1.1

Start here

Frequently asked questions#

Short answers, each with a link to the full guide. Tap a question to open it.

General#

What is frappex-client?

A Python library for working with a Frappe or ERPNext site from code that runs outside it. It wraps the site's REST API in plain methods such as get_doc, get_list, insert and call, for both normal and asyncio code. See Why frappex-client.

How is it different from the requests library?

requests sends any HTTP request to any website, and you write every detail yourself. frappex-client already knows Frappe's REST API: it builds the URLs, sends the credentials, encodes filters, walks through pages, turns Frappe's error replies into exceptions and retries only when that is safe.

customer = client.get_doc("Customer", "Acme Corporation")

replaces the URL building, headers, status checks and JSON decoding you would otherwise write each time.

How is it different from the old frappe-client?

The official frappe-client repository is archived and was never published to PyPI. frappex-client is maintained, installable with pip, fully typed, supports asyncio, and is tested against Frappe 14, 15 and 16 on every change.

Is it an official Frappe project?

No. It is an independent, MIT-licensed community project and is not affiliated with or endorsed by Frappe Technologies.

Is it free to use in commercial projects?

Yes. The MIT licence allows commercial use, modification and redistribution; keep the licence notice with the code.

Why was it renamed from frappix?

The name frappix already belongs to an established Frappe community project by another author. To avoid confusion, the library was renamed to frappex-client in version 0.1.1. If you installed frappix, run pip uninstall frappix and pip install frappex-client, then import frappex_client. See the changelog.

Using it#

Can I use it inside a Frappe app?

Not to talk to the same site. Code inside a Frappe app already has frappe.get_doc, frappe.get_list and the rest, with direct database access. Calling your own site over HTTP would be slower, need an API key, and save changes outside your current transaction.

To reach a different Frappe site from inside a Frappe app, for example another company's ERPNext, frappex-client is the right tool.

Can I use it from Flask, FastAPI or Django?

Yes. Any Python program can use it: web apps, scripts, workers, cron jobs and bots. Use Client in synchronous code such as Flask or Django, and AsyncClient in asyncio code such as FastAPI. See Async client and the FastAPI recipe.

Does it work with ERPNext, HRMS and my custom apps?

Yes. You connect to a Frappe site, and through it you can use the DocTypes and whitelisted methods of every app installed on that site, including ERPNext, HRMS and your own apps.

Can one program talk to several Frappe sites?

Yes. Create one client per site:

from frappex_client import Client, TokenAuth

erp = Client("https://erp.example.com", TokenAuth(erp_key, erp_secret))
hr = Client("https://hr.example.com", TokenAuth(hr_key, hr_secret))
Which Python and Frappe versions are supported?

Python 3.10 to 3.14, and Frappe 14, 15 and 16. Every change is tested against fresh sites of all three Frappe versions. See Compatibility.

How do I get an API key and secret?

On the site, open User, choose the user the program should act as, then Settings → API Access → Generate Keys. Copy the secret straight away; it is shown only once. See Getting started.

Which way of logging in should I use?

Use TokenAuth (API key and secret) for servers, scripts and jobs. Use BearerAuth if your site issues OAuth tokens, PasswordAuth only when a program must act as a person without an API key, and no auth at all for public data. See Authentication.

How it behaves#

Why does it never retry an insert or update?

If the connection drops after the site saved a document but before the reply arrived, a retry would create a second document. frappex-client cannot tell the two cases apart, so it raises TransportError and lets you check first. Reads and rate-limited requests are retried automatically. See Retries.

How do I read more than 20 rows?

Use iter_list. It fetches page after page in a stable order until every matching row has been read:

for row in client.iter_list("Customer", fields=["name", "territory"]):
    print(row["name"])

get_list returns a single page. See Lists, filters and paging.

What happens when the site returns an error?

You get a specific exception: NotFoundError for 404, PermissionDeniedError for 403, ValidationError for invalid data and so on. Each one carries the site's own message in server_messages. Every exception derives from FrappexError. See Errors.

Can I run reports?

Query and Script Reports work through call:

report = client.call(
    "frappe.desk.query_report.run",
    {"report_name": "General Ledger", "filters": {"company": "Acme"}},
    http_method="GET",
)

Reports set to run in the background ("prepared reports") return a status instead of rows. A dedicated helper is planned.

Can I download print formats as PDF?

Not yet. Frappe's PDF endpoint returns a file rather than JSON, which call cannot read. It is planned for a later release.

Does it support realtime updates or the /api/v2 routes?

Not yet. frappex-client uses the /api/resource and /api/method routes, which every supported Frappe version serves, and does not speak Socket.IO.

Security#

Can I turn off certificate verification?

No, by design. Turning it off lets anyone on the network read your API secret. If your site uses a private certificate authority, pass its bundle instead:

client = Client("https://erp.internal", auth, verify="/etc/ssl/certs/company-ca.pem")

See Configuration.

Will my API secret appear in logs or error messages?

No. Secrets are masked in repr, str, log lines and exception messages, and frappex-client never logs headers, query strings or request bodies. See Security model.

How do I report a security problem?

Privately, never in a public issue: report a vulnerability on GitHub.

Troubleshooting#

I get AuthenticationError (HTTP 401)

The key, secret, token or password is wrong, revoked or expired. Check you are using the pair from the right site, and generate a new secret if it was rotated.

I get PermissionDeniedError (HTTP 403)

The user behind your credentials lacks a role for that DocType or method. Grant the role on the site, or use a different user. Without credentials, protected data always raises this.

I get ValidationError (HTTP 417)

The site refused the data, for example because a mandatory field is missing or a link points to a record that does not exist. The reason is in the exception:

from frappex_client import ValidationError

try:
    client.insert("Customer", {"customer_name": "Acme"})
except ValidationError as error:
    print(error.server_messages)
I get UnexpectedResponseError about a redirect or a reply that is not JSON

base_url probably points somewhere other than the site's API, such as a login page, a proxy, or http:// that redirects to https://. Use the root address of the site, for example https://erp.example.com, without /app or /api.

It refuses my http:// address

Plain HTTP sends your secret unencrypted, so it is refused by default. For a site on your own machine, opt in:

client = Client("http://localhost:8000", auth, allow_insecure_http=True)
My bench hosts several sites on one port

Send the site's name as the Host header. See Configuration.

Requests are slow or time out

Ask only for the fields you need with fields=[...], page large lists with iter_list, and give slow report or export clients a longer timeout. See Retries and timeouts.

The project#

What is planned next?

Bulk insert and update, report and PDF helpers, webhook signature verification and /api/v2 support are being considered. Tell us what you need most in a GitHub issue.

How can I contribute?

Bug reports, fixes, tests and documentation are all welcome. See Contributing.

Found a mistake? Open an issue.