Registry / web-framework / djangorestframework-csv

djangorestframework-csv

JSON →
library3.0.2pypypi✓ verified 29d ago

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-csv
INSTALL
IMPORT
SIG · DJANGORESTFRAMEWOR
D
djangorestframework-csv
web-frameworkpythonv3.0.2
Install
3.8s avg
Import
—
Disk
70MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v3.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 70.8MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 3.8s · import 0.000s · 71MB
70MB installed
● package 70MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CSVRenderer
✓ from rest_framework_csv.renderers import CSVRenderer
✗ from rest_framework_csv import CSVRenderer
CSVParser
✓ from rest_framework_csv.parsers import CSVParser
✗ from rest_framework_csv import CSVParser

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`.

from rest_framework.response import Response from rest_framework.views import APIView from rest_framework_csv.renderers import CSVRenderer class ProductListView(APIView): renderer_classes = (CSVRenderer, ) def get(self, request, *args, **kwargs): # In a real application, this would come from a database query # or a DRF serializer output. products = [ {'id': 1, 'name': 'Laptop', 'price': 1200.00}, {'id': 2, 'name': 'Mouse', 'price': 25.00}, {'id': 3, 'name': 'Keyboard', 'price': 75.00} ] return Response(products) # To integrate this, you would typically add it to a Django URLconf, e.g.: # from django.urls import path # urlpatterns = [ # path('products.csv', ProductListView.as_view(), name='product-csv'), # ] # When accessing /products.csv, the API will return CSV data.
Debug
Known issues
breakingPython 2 support was completely removed in version 3.0.0. Projects using older Python versions must upgrade to Python 3.
fix
Ensure your project is running on Python 3.6 or newer (as per general DRF recommendations).
affects: >=3.0.0
gotchaEnsure compatibility with your Django and Django REST Framework versions. Version 3.0.0 and above officially support Django 2.x, 3.x, 4.x and DRF 3.x. Older `djangorestframework-csv` versions might have narrower compatibility ranges.
fix
Always check the `djangorestframework-csv` documentation or release notes for precise compatibility with your Django and DRF versions, especially before upgrading either framework.
affects: <3.0.0
gotchaWhen rendering CSV, the default headers are automatically derived from dictionary keys or serializer fields. To specify custom headers or control field order, set the `header` attribute on your `CSVRenderer` subclass, or dynamically provide headers via `renderer_context={'header': ['field_a', 'field_b']}`.
fix
For static headers: `class MyRenderer(CSVRenderer): header = ['id', 'name']`. For dynamic headers, override the `get_header` method or pass `renderer_context`.
affects: All
gotchaFor very large datasets, using `CSVRenderer` can consume significant memory as it loads all data into memory before rendering. Use `CSVStreamingRenderer` instead to stream data, which reduces memory footprint and improves performance for large exports.
fix
Replace `CSVRenderer` with `CSVStreamingRenderer` in your `renderer_classes` for endpoints returning potentially large amounts of data to enable streaming.
affects: All
Upgrade
Version history
3.0.2latest on PyPI · released Dec 12, 2023
Audit
Dependencies
DjangorequiredRequired for any Django project and DRF integration.
djangorestframeworkrequiredCore dependency; this library extends DRF's functionality.
Agent activity
6 hits · last 30 days
node
4
OpenAI (training)
1
Resources
djangorestframework-csv — pip install djangorestframework-csv · libregistry