Documents#
A document is one record of a DocType: one Customer, one Sales Invoice,
one ToDo. frappex-client returns each document as a plain dict with exactly the
fields the API sends, so doc["name"], doc["modified"] and child tables work
the way they do in Frappe.
| Method | HTTP request | Returns |
|---|---|---|
get_doc(doctype, name) |
GET /api/resource/{doctype}/{name} |
the document |
insert(doctype, values) |
POST /api/resource/{doctype} |
the saved document |
update(doctype, name, values) |
PUT /api/resource/{doctype}/{name} |
the saved document |
delete(doctype, name) |
DELETE /api/resource/{doctype}/{name} |
None |
Read a document#
customer = client.get_doc("Customer", "Acme Corporation")
print(customer["customer_name"], customer["territory"])
customer = await client.get_doc("Customer", "Acme Corporation")
print(customer["customer_name"], customer["territory"])
The reply includes every field the user is allowed to read, the standard
fields (name, owner, creation, modified, docstatus) and child tables.
A missing document raises NotFoundError; a document the user may not read
raises PermissionDeniedError.
Create a document#
todo = client.insert(
"ToDo",
{
"description": "Call the supplier",
"priority": "High",
"date": "2026-12-01",
},
)
print(todo["name"]) # the name the site assigned
todo = await client.insert(
"ToDo",
{
"description": "Call the supplier",
"priority": "High",
"date": "2026-12-01",
},
)
print(todo["name"])
The site validates the document, applies defaults, runs its naming rule and
returns the saved document. Pass "name" yourself only for DocTypes whose
naming rule is "Set by user" (prompt).
Inserts are never retried
If the connection drops after the request is sent, frappex-client cannot know
whether the document was created, so it raises TransportError instead of
trying again. See Retries for how
to make an insert safe to repeat.
Child tables#
Child rows go in as a list of dicts under the table field's name:
order = client.insert(
"Sales Order",
{
"customer": "Acme Corporation",
"delivery_date": "2026-12-15",
"items": [
{"item_code": "WIDGET-01", "qty": 10, "rate": 250},
{"item_code": "WIDGET-02", "qty": 4, "rate": 990},
],
},
)
for row in order["items"]:
print(row["idx"], row["item_code"], row["amount"])
Update a document#
update sends only the fields you pass; other fields keep their values.
saved = client.update("ToDo", todo["name"], {"status": "Closed"})
print(saved["status"], saved["modified"])
Updating a child table replaces the whole table. Read the document, change the rows, and send the full list back:
order = client.get_doc("Sales Order", "SO-0001")
order["items"][0]["qty"] = 12
client.update("Sales Order", "SO-0001", {"items": order["items"]})
Concurrent edits
If someone else saved the document after you read it, Frappe may reject
the save with a "document has been modified" error, which frappex-client raises
as ValidationError. Read the document again and reapply your change.
Delete a document#
client.delete("ToDo", todo["name"])
Deleting a submitted document (docstatus 1) fails; cancel it first. Deleting a document that other records link to raises an error naming the link.
Names with special characters#
Document names can contain /, spaces, #, ?, % and non-ASCII text, for
example INV/2026/0001. frappex-client percent-encodes every name, so it always
addresses exactly that document and can never reach a different endpoint:
client.get_doc("Sales Invoice", "INV/2026/0001")
# GET /api/resource/Sales%20Invoice/INV%2F2026%2F0001
The names . and .. are refused with ConfigurationError before any
request is sent.
Single DocTypes#
A Single DocType (such as System Settings) has exactly one record whose name is the DocType itself:
settings = client.get_doc("System Settings", "System Settings")
print(settings["time_zone"])
Next#
- Lists, filters and paging to find documents.
- Values and counts to read single fields cheaply.
- Submit, cancel and rename for submittable DocTypes.