drf-excel
Django REST Framework renderer for Excel spreadsheet (xlsx) files.
What it is and what it does
drf-excel is a Django REST Framework renderer that converts API responses into Excel spreadsheets (.xlsx files). It integrates with DRF's standard renderer pipeline, allowing views to serve Excel exports alongside JSON and other formats. The package uses OpenPyXL to build the spreadsheets and provides a mixin (XLSXFileMixin) to handle HTTP headers and filename configuration.
The package supports extensive styling of headers, column headers, body rows, and individual columns through view attributes or dynamic methods. It can apply fonts, colors, borders, alignment, and number formats to cells. Additional features include auto-filtering on header rows, per-column styling overrides, sheet view options (like right-to-left layout), and the ability to use serializer field labels as column headers instead of field names.
Use it for:
- Export REST API query results to Excel for business reporting and data analysis workflows
- Generate styled Excel reports with custom headers, logos, and formatted data cells from API endpoints
- Provide end users with downloadable spreadsheets of filtered or paginated API data with proper filenames
- Create multi-column exports with per-column number formatting (dates, currency, scientific notation) from serialized data
- Build data export features that respect API permissions and serializer field definitions automatically
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds an Excel spreadsheet (xlsx) renderer to Django REST Framework, allowing API views to export data directly as formatted Excel files using OpenPyXL.
Yes. drf-excel is actively maintained, has low install friction, carries a permissive license, and solves a common need for Django REST Framework users. It integrates cleanly into DRF's renderer architecture and supports modern Python versions (3.10–3.14) and current Django releases. No known vulnerabilities. Install it if you need to export API data to Excel.
Install
drf-excel on PyPI
pip
pip install drf-exceluv
uv add drf-excelpoetry
poetry add drf-excelInstalling drf-excel
Before you install
Low friction install with just two runtime dependencies (djangorestframework and openpyxl). Active maintenance with a release 8 days ago and 240 repository stars indicate ongoing support.
License in practice
BSD-3-Clause permissive license allows use in commercial and proprietary projects with minimal restrictions; attribution required.
Quickstart
pip install drf-excel
# In settings.py REST_FRAMEWORK config:
REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
'drf_excel.renderers.XLSXRenderer',
),
}
# In views.py:
from drf_excel.mixins import XLSXFileMixin
from drf_excel.renderers import XLSXRenderer
class MyViewSet(XLSXFileMixin, ReadOnlyModelViewSet):
renderer_classes = (XLSXRenderer,)
filename = 'export.xlsx'
Requires Django REST Framework >= 3.14 and OpenPyXL >= 2.4; Python >= 3.10.
Verify before relying
- Whether column-level formatting (fonts, borders, fills) works correctly with all OpenPyXL versions >= 2.4
- Performance characteristics when exporting large datasets (row count thresholds)
- Compatibility with custom pagination classes beyond the documented None requirement
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — djangorestframework, openpyxl |
| Maintenance | actively maintained — 8 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 150,715/month — #10,959 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: drf_excel-2.6.0-py3-none-any.whl
Keywords: djangorestframework, django rest framework, excel, spreadsheet, rest, restful, api, xls, xlsx, openpyxl
Tags
More WWW/HTTP packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
h11h11 is a pure-Python HTTP/1.1 protocol…
permissive · top 100 on PyPI
httpxHTTPX is a fully featured HTTP client library…
permissive · top 100 on PyPI
httpcoreA minimal low-level HTTP client library that…
permissive · top 100 on PyPI
aiohttpaiohttp is an async HTTP client and server…
permissive · top 100 on PyPI
xlsx2htmlConverts Excel spreadsheets (.xlsx files) to…
permissive · top 15,000 on PyPI
openpyxlopenpyxl reads and writes Excel 2010…
permissive · top 1,000 on PyPI
xlsxwriterXlsxWriter creates Excel 2007+ XLSX files from…
permissive · top 1,000 on PyPI
drf-orjson-rendererProvides a high-performance JSON renderer and…
permissive · top 15,000 on PyPI
djangorestframework-csvAdds CSV rendering and parsing capabilities to…
permissive · top 5,000 on PyPI
django-queryset-csvExports Django QuerySet data to CSV format with…
copyleft · top 15,000 on PyPI
xls2xlsxConverts legacy Excel files (.xls), HTML…
permissive · top 5,000 on PyPI
robotframework-excellibProvides Robot Framework keywords for reading,…
permissive · top 15,000 on PyPI
tableschema-to-templateConverts a Frictionless Table Schema into an…
permissive · top 15,000 on PyPI
openpyxl-stubsProvides type stubs for openpyxl to enable…
permissive · top 15,000 on PyPI