Lists, filters and paging#
Two methods query documents:
get_listreturns one page, like a SQL query withLIMITandOFFSET.iter_listyields every matching row, fetching one page at a time.
One page with get_list#
rows = client.get_list(
"Sales Invoice",
fields=["name", "customer", "grand_total", "status"],
filters={"status": "Unpaid"},
order_by="due_date asc",
limit=50,
)
| Argument | Default | Meaning |
|---|---|---|
fields |
only name |
Fields to return. Use ["*"] for every column of the main table. |
filters |
none | Conditions every row must meet. |
or_filters |
none | Conditions of which a row must meet at least one. |
order_by |
the DocType's default sort | SQL-style sort clause, such as "posting_date desc". |
limit |
20 |
Maximum rows to return. Must be at least 1. |
offset |
0 |
Rows to skip. |
parent |
none | Parent DocType, required when listing a child table. |
Note
Without fields, Frappe returns only the name of each row. Ask for the
fields you need: it is faster than fetching every document with get_doc.
Filters#
Filters can be written as a dictionary or as a list. Both mean the same.
filters = {
"status": "Open", # equals
"grand_total": [">", 1000], # operator and value
"customer": ["like", "%Acme%"],
"posting_date": ["between", ["2026-01-01", "2026-03-31"]],
}
filters = [
["status", "=", "Open"],
["grand_total", ">", 1000],
["customer", "like", "%Acme%"],
["posting_date", "between", ["2026-01-01", "2026-03-31"]],
]
The list form also allows filtering on a child table field, by putting the child DocType first:
filters = [["Sales Invoice Item", "item_code", "=", "WIDGET-01"]]
Operators#
| Operator | Example value | Matches |
|---|---|---|
=, != |
"Open" |
equal, not equal |
>, <, >=, <= |
1000 |
comparisons; dates as "YYYY-MM-DD" |
like, not like |
"%Acme%" |
SQL pattern; % matches anything |
in, not in |
["Open", "Overdue"] |
any of the values |
between |
["2026-01-01", "2026-03-31"] |
inclusive range |
is |
"set" or "not set" |
field has a value, or is empty |
in never matches empty fields
In SQL, NULL IN (...) is never true, so ["status", "in", ["", "Open"]]
skips rows whose status is NULL. Use ["status", "is", "not set"] to
find empty fields.
OR conditions#
Every condition in filters must hold. To accept rows that meet any of a set
of conditions, use or_filters; it combines with filters using AND:
rows = client.get_list(
"ToDo",
filters={"owner": "jane@example.com"},
or_filters={"priority": "High", "date": ["<", "2026-12-01"]},
)
# owner is Jane AND (priority is High OR date is before 1 Dec)
Reading every row with iter_list#
iter_list takes the same arguments as get_list, except that limit and
offset are replaced by page_size. It yields rows one by one and fetches the
next page only when you reach it.
for invoice in client.iter_list(
"Sales Invoice",
fields=["name", "outstanding_amount"],
filters={"docstatus": 1, "outstanding_amount": [">", 0]},
page_size=200,
):
remind(invoice)
async for invoice in client.iter_list(
"Sales Invoice",
fields=["name", "outstanding_amount"],
filters={"docstatus": 1, "outstanding_amount": [">", 0]},
page_size=200,
):
await remind(invoice)
Why the order is stable#
Paging with OFFSET over a list sorted by modification time breaks as soon as a row
is edited during the walk: the row jumps to the top, and every later page
shifts by one, so one row is skipped and another repeated. Unless you pass
order_by, iter_list sorts by creation asc, name asc, which edits never
change.
Rows created or deleted during the walk can still shift pages. For an
exact snapshot of a fast-changing table, filter on a fixed window such as
{"creation": ["<", start_time]}.
To collect everything into a list:
customers = list(client.iter_list("Customer", fields=["name", "customer_name"]))
Listing child table rows#
Child DocTypes need the parent argument and the read permission of the
parent DocType:
rows = client.get_list(
"Sales Invoice Item",
parent="Sales Invoice",
fields=["parent", "item_code", "qty"],
filters={"item_code": "WIDGET-01"},
)
Counting#
To count rows without fetching them, use get_count.