skillfed

djangorestframework-role-filters

django-rest-framework-role-filters

djangorestframework-role-filters v1.1.0 867.1K downloads/30d#4,858 on PyPI97
Permissive license DORMANT released

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-filters

uv

uv add djangorestframework-role-filters

poetry

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

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentFramework :: DjangoIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Internet :: WWW/HTTPTopic :: Software Development :: Libraries :: Application FrameworksTopic :: Software Development :: Libraries :: Python Modules

Tags

django rest framework role permissionsrole-based access control drfdjango viewset role filtersrole-based serializer selectiondjango rest framework rbacrole-based queryset filteringdrf role-based authorization
rbacdjango-rest-frameworkpermissions

More Python Modules packages