--- id: djangorestframework-role-filters version: "1.1.0" license: unclear license_treatment: permissive maintenance: dormant --- # djangorestframework-role-filters — django-rest-framework-role-filters License: permissive · Maintenance: dormant · Downloads: 867.1K/mo ## 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 above — 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 pip install djangorestframework-role-filters uv add djangorestframework-role-filters poetry add djangorestframework-role-filters ## Installing 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: unspecified - Install friction: low - Maintenance: dormant - Downloads: 867.1K/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags django rest framework role permissions, role-based access control drf, django viewset role filters, role-based serializer selection, django rest framework rbac, role-based queryset filtering, drf role-based authorization, rbac, django-rest-framework, permissions [View on SkillFed](https://skillfed.io/packages/djangorestframework-role-filters) · [View on PyPI](https://pypi.org/project/djangorestframework-role-filters/)