djangorestframework-csv provides tools to integrate CSV rendering and parsing into Django REST Framework APIs. It enables DRF serializers to output data as CSV and allows DRF parsers to consume CSV data. The current version is 3.0.2, with releases tending to be driven by Django and DRF compatibility updates rather than a fixed cadence.
pip install djangorestframework-csvVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to integrate `CSVRenderer` into a Django REST Framework `APIView` to output a list of dictionary objects as CSV. When an endpoint using this renderer is accessed with a `.csv` format suffix (e.g., `/products.csv`), the response will be a CSV file. For very large datasets, consider using `CSVStreamingRenderer`.
Ensure your project is running on Python 3.6 or newer (as per general DRF recommendations).
Always check the `djangorestframework-csv` documentation or release notes for precise compatibility with your Django and DRF versions, especially before upgrading either framework.
For static headers: `class MyRenderer(CSVRenderer): header = ['id', 'name']`. For dynamic headers, override the `get_header` method or pass `renderer_context`.
Replace `CSVRenderer` with `CSVStreamingRenderer` in your `renderer_classes` for endpoints returning potentially large amounts of data to enable streaming.