djangorestframework-role-filters
django-rest-framework-role-filters
What it is and what it does
This package extends Django REST Framework with a role-based filtering system that lets you define different access rules per user role in a declarative way. Instead of writing multiple conditional checks throughout your viewset code, you create role filter classes that specify which actions are allowed, how to filter the queryset, which serializer to use, and how to configure it—then attach them to your viewset. The framework automatically applies the right rules based on the user's role.
You define role filters by subclassing RoleFilter and setting a role_id, then implement methods like get_allowed_actions(), get_queryset(), get_serializer_class(), and get_serializer() to customize behavior per role. Your viewset inherits from RoleFilterModelViewSet and implements get_role_id() to determine the current user's role. The package handles permission checks and queryset/serializer selection automatically, keeping your view code clean and your role logic centralized.
Use it for:
- Multi-tenant SaaS where admins see all data but regular users see only their own records
- API with tiered access levels requiring different allowed actions per tier
- REST API where different roles need different serializer fields exposed to each role
- Reducing permission-check boilerplate in viewsets by centralizing role logic in filter classes
- Filtering querysets dynamically based on user role without writing conditional logic in each view
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds role-based access control to Django REST Framework viewsets, allowing you to define different permissions, querysets, and serializers per user role without scattered conditional logic.
Yes, if you are building a Django REST Framework API with role-based access control and want to avoid scattered permission checks. The package is stable, has low install friction, and carries no known vulnerabilities. The main caveat is dormant maintenance—last updated 2023-10-06—so if you need active support or compatibility with very recent Django/DRF versions, verify compatibility first. For established projects with stable dependencies, this is a solid choice.
Install
djangorestframework-role-filters on PyPI
pip
pip install djangorestframework-role-filtersuv
uv add djangorestframework-role-filterspoetry
poetry add djangorestframework-role-filtersInstalling djangorestframework-role-filters
Before you install
Low friction: pure Python wheel with only djangorestframework as a runtime dependency. Maintenance is dormant—last commit was 2023-10-06—but the package is marked Production/Stable and has seen no recent changes needed.
License in practice
MIT license (permissive) means you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install djangorestframework-role-filters
from djangorestframework_role_filters.role_filters import RoleFilter
from djangorestframework_role_filters.viewsets import RoleFilterModelViewSet
class UserRoleFilter(RoleFilter):
role_id = 'user'
def get_allowed_actions(self, request, view, obj=None):
return ['list', 'retrieve']
class MyViewSet(RoleFilterModelViewSet):
role_filter_classes = [UserRoleFilter]
def get_role_id(self, request):
return request.user.role.role_id
Verify before relying
- Whether the package works with current versions of Django and djangorestframework (last tested against versions unspecified)
- Performance characteristics when handling many role filters or complex permission logic
- Whether dormant maintenance status means security patches or bug fixes are unlikely if issues arise
Package facts
| License | not declared (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — djangorestframework |
| Maintenance | dormant — 1,043 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 867,136/month — #4,858 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: djangorestframework_role_filters-1.1.0-py3-none-any.whl
Keywords: djangorestframework, rest, role, permission
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
drf-access-policyDeclares access control rules for Django REST…
permissive · top 15,000 on PyPI
dry-rest-permissionsDefines rules-based permissions for Django REST…
permissive · top 15,000 on PyPI
django-prbacImplements parameterized role-based access…
unclear · top 15,000 on PyPI
adrfAdds async/await support to Django REST…
permissive · top 15,000 on PyPI
django-zen-queriesPrevents unintended database queries in Django…
permissive · top 15,000 on PyPI
bridgekeeperBridgekeeper provides a permissions system for…
permissive · top 15,000 on PyPI
djangorestframework-guardianIntegrates django-guardian's object-level…
permissive · top 15,000 on PyPI
drf-nested-routersProvides routers and serializer fields for…
permissive · top 5,000 on PyPI
djangorestframeworkBuilds web APIs on top of Django with…
permissive · top 1,000 on PyPI
djangorestframework-filtersExtends Django REST Framework with advanced…
permissive · top 15,000 on PyPI