AlexanderCollins/TurboDRF

The dead simple Django REST Framework API generator with role-based permissions

TurboDRF

PyPI Version Tests Coverage License

Dead simple Django REST Framework API generator with role-based permissions.

Turn your Django models into fully-featured REST APIs with a mixin and a method. Zero boilerplate.

Install

pip install turbodrf

# Optional: faster JSON rendering (7x faster than stdlib)
pip install turbodrf[fast]

Quick Start

1. Add to settings:

INSTALLED_APPS = [
    'rest_framework',
    'turbodrf',
]

2. Add the mixin to your model:

from django.db import models
from turbodrf.mixins import TurboDRFMixin

class Book(models.Model, TurboDRFMixin):
    title = models.CharField(max_length=200)
    author = models.ForeignKey(Author, on_delete=models.CASCADE)
    price = models.DecimalField(max_digits=10, decimal_places=2)

    searchable_fields = ['title']

    @classmethod
    def turbodrf(cls):
        return {
            'fields': {
                'list': ['title', 'author__name', 'price'],
                'detail': ['title', 'author__name', 'author__email', 'price']
            }
        }

3. Add the router:

from turbodrf.router import TurboDRFRouter

router = TurboDRFRouter()

urlpatterns = [
    path('api/', include(router.urls)),
]

Done. You now have a full REST API with search, filtering, pagination, and field selection:

GET    /api/books/                          # List
GET    /api/books/1/                        # Detail
POST   /api/books/                          # Create
PUT    /api/books/1/                        # Update
DELETE /api/books/1/                        # Delete
GET    /api/books/?search=django            # Search
GET    /api/books/?price__lt=20             # Filter
GET    /api/books/?fields=title,price       # Select fields

Documentation

  • Configuration -- all turbodrf() options, field selection, nested fields
  • Permissions -- role-based, field-level, and Django default permissions
  • Performance -- compiled read path, fast JSON rendering, benchmarking
  • Filtering & Search -- filtering, search, ordering, OR queries
  • Integrations -- allauth, Keycloak, drf-api-tracking
  • Security -- sensitive fields, secure defaults, error responses
  • Management Commands -- turbodrf_check, turbodrf_benchmark, turbodrf_explain

License

MIT License. See LICENSE for details.

Stars
39
100.00% more than last month
Forks
0
Open Issues
0