encode

django-rest-framework

Django REST framework is a toolkit for building Web APIs on Django, offering a browsable API, serialization, authentication, and permission control to turn Django projects into REST services.

3.18.3
Published at
22d ago
30,210
Stars
278
Download
Synced at
8d ago

Latest release

3.18.3Oct 6, 2026, 09:34 PM
Downloads slow? Switch the source anytime above

README

Project Overview

Django REST framework (DRF) is a powerful and flexible toolkit for building Web APIs on top of Django. It provides serializers, viewsets, routers, and an authentication system to expose model data as REST endpoints quickly. Its signature browsable API lets developers inspect and test endpoints right in the browser, greatly speeding up development and integration work.

Item Value
Language Python
Base framework Django
Type Web API toolkit
License BSD

Turns Django models into REST endpoints you can debug right in the browser.

Key Features

  • Browsable API: a built-in web UI to view and test endpoints in the browser
  • Serialization: validation and (de)serialization for both ORM and non-ORM data sources
  • Authentication: session and token auth built in, extendable to OAuth1a and OAuth2
  • Permissions: fine-grained permission classes per request or per object
  • Generic views: generic views and viewsets for fast CRUD
  • Automatic routing: routers generate RESTful URL configurations automatically
  • Throttling: built-in rate limiting to protect backend resources
  • Pagination: multiple pagination schemes out of the box

Target Audience

  • Django developers
  • Backend teams serving mobile or frontend clients
  • Builders of open platform APIs
  • Enterprise system integration engineers
  • Learners studying REST API design

Quick Start

  1. Install dependencies: pip install django djangorestframework
  2. Create a project and migrate
django-admin startproject example .
python manage.py migrate
python manage.py createsuperuser
  1. Register the app in settings.py
INSTALLED_APPS = [
    'rest_framework',
]
  1. Define a serializer and viewset, then wire the router
from django.contrib.auth.models import User
from django.urls import include, path
from rest_framework import routers, serializers, viewsets

class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ['url', 'username', 'email', 'is_staff']

class UserViewSet(viewsets.ModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer

router = routers.DefaultRouter()
router.register(r'users', UserViewSet)

urlpatterns = [
    path('', include(router.urls)),
]
  1. Start the server: python manage.py runserver, then open http://127.0.0.1:8000/

Core Advantages

  • Great developer experience: the browsable API removes the need for a frontend during integration
  • Highly customizable: swap serializers, views, and permissions layer by layer
  • Mature ecosystem: thorough docs and community solutions for most scenarios
  • Seamless with Django: reuses the ORM, auth, and settings systems

System Requirements

Item Requirement
Language Python 3.10+
Framework Django 5.2 or later
OS Linux, macOS, Windows

Notes

  • Version pairing: only the latest patch release of each Python and Django series is officially supported, keep them in sync
  • Query performance: generic viewsets can trigger extra queries, optimize with select_related and prefetch_related

Release history

Sort