Registry / web-framework / edx-drf-extensions

edx-drf-extensions

JSON →
library10.6.0pypypiunverified

edX DRF Extensions provides a collection of utility classes, authenticators, permissions, and exception handlers designed to extend Django REST Framework for use within the Open edX ecosystem. It is currently at version 10.6.0, with a frequent release cadence tied to Django and Python version compatibility and Open edX platform development.

pip install edx-drf-extensions
INSTALL
IMPORT
SIG · EDX-DRF-EXTENSIONS
E
edx-drf-extensions
web-frameworkpythonv10.6.0
Install
7.6s avg
Import
Disk
111MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v10.6.0 · 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.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 108.5MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 7.6s · import 0.000s · 111MB
111MB installed
● package 111MB
Code
Verified usage

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

JwtCookieAuthentication
from edx_rest_framework_extensions.auth.jwt.authentication import JwtCookieAuthentication
from edx_rest_framework_extensions.auth.jwt.authentication import JwtCookieAuthentication

This quickstart demonstrates how to apply `JwtCookieAuthentication` to a Django REST Framework ViewSet, allowing JWT-based authentication via cookies. It also shows how the `exception_handler` can be used (typically configured in `settings.py`) to provide consistent error responses. The `cause_handled_error` action simulates an exception that would be processed by the custom handler.

import os from rest_framework import viewsets, status from rest_framework.response import Response from rest_framework.decorators import action from django.http import Http404 # Ensure these imports are correct for your installed version from edx_drf_extensions.auth.jwt.authentication import JwtCookieAuthentication from edx_drf_extensions.exception_handler import exception_handler # In a Django settings.py file, you'd typically configure DRF: # REST_FRAMEWORK = { # 'DEFAULT_AUTHENTICATION_CLASSES': [ # 'edx_drf_extensions.auth.jwt.authentication.JwtCookieAuthentication', # 'rest_framework.authentication.SessionAuthentication', # ], # 'EXCEPTION_HANDLER': 'edx_drf_extensions.exception_handler.exception_handler' # } class MyTestViewSet(viewsets.ViewSet): """A simple DRF view demonstrating edx-drf-extensions authentication.""" authentication_classes = [JwtCookieAuthentication] # Permission classes would typically be added here, e.g., IsAuthenticated def list(self, request): if request.user.is_authenticated: return Response({"message": f"Hello {request.user.username}, authenticated via JWT!"}, status=status.HTTP_200_OK) return Response({"message": "Authentication failed."}, status=status.HTTP_401_UNAUTHORIZED) @action(detail=False, methods=['get']) def cause_handled_error(self, request): """Endpoint to demonstrate the custom exception handler.""" # This error will be caught by DRF's exception handling, if configured. raise Http404("The requested resource was not found. (Handled by edx-drf-extensions)") print("Quickstart code demonstrates applying JwtCookieAuthentication to a DRF ViewSet.") print("It also hints at configuring the custom exception_handler in settings.py.") print("To run fully, integrate into a Django/DRF project and configure REST_FRAMEWORK.")
Debug
Known issues
breakingPython 3.8 support was dropped in version 10.4.0. Projects using older Python versions must upgrade their environment or stick to `edx-drf-extensions < 10.4.0`.
fix
Upgrade your Python environment to 3.9 or higher, or pin `edx-drf-extensions` to a version prior to 10.4.0.
affects: >=10.4.0
breakingThe behavior of JWT authentication changed significantly in v10.0.0, making 'forgiving JWTs' the default. This means JWTs that fail verification due to expiry or other issues might be silently ignored if another authentication method succeeds, which could alter security assumptions.
fix
Review your authentication backend configuration and `edx-drf-extensions` settings. If you rely on strict JWT validation, ensure it's explicitly enforced, or adjust your system's authentication flow to account for 'forgiving' behavior.
affects: >=10.0.0
gotchaThere were several changes, reverts, and fixes related to JWT vs session user checks around versions 9.1.0-9.1.2. Upgrading between these minor versions, or to/from 10.0.0, could lead to unexpected authentication behavior or regressions.
fix
Thoroughly test authentication after upgrading, especially if your application relies on both JWT and session authentication. Refer to the specific changelogs for each version for detailed behavioral changes.
affects: 9.1.0-10.1.0
gotchaVersion 10.6.0 added support for Django 5.2. If you are using an older version of `edx-drf-extensions` with Django 5.x, you may encounter compatibility issues or `DeprecationWarnings` from Django. Older `edx-drf-extensions` versions are not guaranteed to support newer Django releases.
fix
Ensure your `edx-drf-extensions` version is compatible with your Django version. Upgrade to the latest `edx-drf-extensions` (10.6.0+) if using Django 5.2.
affects: <10.6.0 with Django >=5.0
Upgrade
Version history
10.6.0latest on PyPI · released Apr 4, 2025
Audit
Dependencies
DjangorequiredCore framework dependency for any Django application.
djangorestframeworkrequiredThe library extends Django REST Framework; it is a fundamental dependency.
Agent activity
25 hits · last 30 days
node
24
OpenAI (training)
1
Resources
edx-drf-extensions — pip install edx-drf-extensions · libregistry