Registry / web-framework / djangorestframework-recursive

djangorestframework-recursive

JSON →
library0.1.2pypiunverified

djangorestframework-recursive is a Python library that provides a `RecursiveField` for Django REST Framework serializers, enabling the serialization of tree, linked list, or directed acyclic graph structures. Maintained by @heywbj, the last release (0.1.2) was on July 4, 2017. Due to a lack of recent maintenance, users requiring compatibility with modern Django and Django REST Framework versions are advised to consider the actively maintained fork, `drf-recursive`.

pip install djangorestframework-recursive
INSTALL
IMPORT
SIG · DJANGORESTFRAMEWOR
D
djangorestframework-recursive
web-frameworkenv0.1.2
Install
3.7s avg
Import
800ms
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 v0.1.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.910 runs
installs and imports cleanly · install 0.0s · import 0.845s · 70.6MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 3.7s · import 0.754s · 71MB
70MB installed
● package 70MB
Code
Verified usage

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

RecursiveField
✓ from rest_framework_recursive.fields import RecursiveField

This quickstart demonstrates how to define a recursive serializer for a tree-like structure using `RecursiveField`. It assumes a conceptual `Category` model with a self-referential `parent` foreign key, allowing for nested children. The `RecursiveField` automatically handles the self-referencing serialization.

from rest_framework import serializers from rest_framework_recursive.fields import RecursiveField # Example Model (assuming you have a Django model like this) # class Category(models.Model): # name = models.CharField(max_length=100) # parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children') class CategorySerializer(serializers.Serializer): name = serializers.CharField(max_length=100) children = serializers.ListField(child=RecursiveField(), required=False) # Example usage with a dummy data structure # In a real application, you would pass Django model instances data = { 'name': 'Root', 'children': [ { 'name': 'Child 1', 'children': [ {'name': 'Grandchild 1.1'}, {'name': 'Grandchild 1.2'} ] }, {'name': 'Child 2'} ] } serializer = CategorySerializer(data=data) if serializer.is_valid(): print(serializer.data) else: print(serializer.errors)
Debug
Known issues
breakingThe `djangorestframework-recursive` library is no longer actively maintained. Its last release was in 2017, leading to potential incompatibility issues with modern Python (3.7+), Django (2.1+), and Django REST Framework (3.8+) versions.
fix
Consider using the actively maintained fork, `drf-recursive` (installable via `pip install drf-recursive`), which explicitly supports modern Python, Django, and DRF versions.
affects: 0.1.2 and earlier
gotchaDeeply nested or very wide recursive data structures can lead to `RecursionError: maximum recursion depth exceeded` during serialization, or significant performance degradation.
fix
Implement strategies to limit recursion depth, optimize database queries with `select_related` or `prefetch_related` for related objects, or consider alternative serialization approaches for extremely large graphs. Review Python's default recursion limit (`sys.getrecursionlimit()`).
affects: All versions
deprecatedThe original library explicitly supported Python 2.7. Using it with Python 2.7 is highly discouraged as Python 2.7 reached its end-of-life in 2020.
fix
Migrate your project to Python 3. If you need recursive serialization on Python 3, use the `drf-recursive` fork.
affects: 0.1.2 and earlier
Errors
Common errors & fixes
RecursionError: maximum recursion depth exceeded while calling a Python object
Attempting to serialize an excessively deep recursive structure without a proper depth limit or hitting Python's default recursion limit.
fix
Review your data structure for unintended cycles or extreme depth. Increase Python's recursion limit (`sys.setrecursionlimit(limit)`) if genuinely necessary, but be aware of performance implications. Consider flattening parts of the hierarchy or loading data in chunks.
ModuleNotFoundError: No module named 'rest_framework_recursive'
The `djangorestframework-recursive` package is not installed, or the fork `drf-recursive` was installed and the import path is incorrect.
fix
Ensure `djangorestframework-recursive` is installed via `pip install djangorestframework-recursive`. If you intended to use the fork, install `drf-recursive` and import `RecursiveField` from `django_rest_framework_recursive.fields` (note the different package name).
TypeError: 'RecursiveField' object is not iterable
Incorrect usage of `RecursiveField` within a serializer, for example, passing it directly as a field for a `many=True` relationship without wrapping it in a `ListField` or similar.
fix
For one-to-many or many-to-many recursive relationships, ensure `RecursiveField` is used as the `child` of a `serializers.ListField` or `serializers.ManyRelatedField`.
Upgrade
Version history
0.1.2latest on PyPI · released Jul 4, 2017
Audit
Dependencies
DjangorequiredCore framework dependency for ORM and web application structure. Tested against 1.8, 1.9, 2.0.
djangorestframeworkrequiredProvides the base serializer classes and functionality that djangorestframework-recursive extends. Tested against 3.3-3.7.
PythonrequiredThe language runtime. Tested against 2.7, 3.4, 3.6.
Agent activity
4 hits · last 30 days
node
4
Resources

No resource links recorded.

djangorestframework-recursive — pip install djangorestframework-recursive · libregistry