This version is in beta. Some features may change before release.

CSV export

Download any resource as CSV with ?format=csv, same filters, search, and field selection as the JSON list.

CSV export

Any list endpoint can return CSV instead of JSON. Add ?format=csv:

Code
http
GET /api/order/?format=csv
Code
http
HTTP/1.1 200 OK
Content-Type: text/csv; charset=utf-8
Content-Disposition: attachment; filename="order.csv"
 
id,customer,total
1,Ada,42
2,"Grace, Inc.",17

It's the same data as the JSON list: same authentication gate, and every query option works: filters, ?search=, ?include=, and ?fields=. Only the serialization differs.

Code
http
GET /api/order/?status=paid&search=ada&fields=id,customer&format=csv

What you get

  • Columns follow the model's field order, after any hidden / sparse-field scrubbing. Computed fields are appended.
  • Cells: scalars verbatim, null → empty, objects/arrays → compact JSON. Values with commas or quotes are quoted/escaped per RFC 4180.
  • Capped at 1 000 rows. CSV export is subject to the same MAX_LIST_ROWS (1 000) ceiling as the JSON list. This prevents full-table buffering on large datasets. Pair it with filters to stay under the cap, or add a paginator with a higher limit if you need bigger exports.
Info

The inverse, CSV import, ships as the importcsv management command. An admin "export selected rows" bulk action (waiting on the bulk-action UI) and Excel (.xlsx) are not in this slice yet; see planning/features.md #61.

See also

restcsvexportdownload