Django Revolution
Zero-config TypeScript & Python client generator for Django REST Framework
Django Revolution - Zero-Config TypeScript & Python Client Generator
Zero-config TypeScript & Python client generator for Django REST Framework ๐
โจ What is Django Revolution?
The fastest way to generate fully-authenticated TypeScript + Python clients from Django REST Framework.
- ๐งฉ Organize your API into zones (
public
,admin
,mobile
, etc.) - โ๏ธ Generate strongly typed clients with one command
- ๐ Built-in support for Bearer tokens, refresh logic, and API keys
- ๐ Zero config for Swagger/OpenAPI URLs, frontend integration, and monorepos
- ๐ฏ Optional monorepo integration - works with or without monorepo structure
- ๐ Dynamic zone management - no static files, everything generated in-memory
- ๐จ Rich CLI interface - interactive commands with beautiful output
- โก Multithreaded generation - parallel processing for faster client generation
- ๐งช Comprehensive testing - full test suite with pytest
- ๐ง Ready-to-use Pydantic configs - type-safe configuration with IDE support
No boilerplate. No manual sync. Just clean clients in seconds.
๐งช Example: Instantly Get a Typed API Client
import API from '@myorg/api-client';const api = new API('https://api.example.com');api.setToken('your-access-token');const profile = await api.public.getProfile();const items = await api.public.listItems();
๐ Auth, โ๏ธ Headers, ๐ Refresh โ handled automatically.
โ Without Django Revolution
Manually update OpenAPI spec โ Run generator โ Fix broken types โ Sync clients โ Write token logic โ Repeat on every change.
โ With Django Revolution
One command. Done.
๐ Data Flow Architecture
Diagram
Click to view fullscreen
๐ฏ Ready-to-Use Pydantic Configs
No more manual configuration! Django Revolution provides pre-built, typed configurations:
DRF + Spectacular Config
from django_revolution.drf_config import create_drf_config# One function call - everything configured!drf_config = create_drf_config(title="My API",description="My awesome API",version="1.0.0",schema_path_prefix="/apix/",enable_browsable_api=False,enable_throttling=True,)# Get Django settingssettings = drf_config.get_django_settings()REST_FRAMEWORK = settings['REST_FRAMEWORK']SPECTACULAR_SETTINGS = settings['SPECTACULAR_SETTINGS']
Zone Configuration
from django_revolution.app_config import ZoneConfig, get_revolution_config# Typed zone definitionszones = {'public': ZoneConfig(apps=['accounts', 'billing', 'payments', 'support', 'public'],title='Public API',description='API for public client applications',public=True,auth_required=False,version='v1'),'internal': ZoneConfig(apps=['system', 'mailer'],title='Internal API',description='Internal API for backend services',public=False,auth_required=True,version='v1'),'admin': ZoneConfig(apps=['admin_panel', 'services'],title='Admin API',description='Administrative API endpoints',public=False,auth_required=True,version='v1')}# Option 1: With monorepo (uncomment to enable)# from django_revolution.app_config import MonorepoConfig# monorepo = MonorepoConfig(# enabled=True,# path=str(BASE_DIR.parent.parent.parent / 'monorepo'),# api_package_path='packages/api/src'# )# return get_revolution_config(project_root=BASE_DIR, zones=zones, debug=DEBUG, monorepo=monorepo)# Option 2: Without monorepo (current setup)return get_revolution_config(project_root=BASE_DIR, zones=zones, debug=DEBUG)
Benefits:
- โ Type-safe - Full Pydantic validation
- โ Zero boilerplate - Pre-configured defaults
- โ Environment-aware - Auto-detects paths and settings
- โ IDE support - Autocomplete and error checking
- โ Production-ready - Optimized for client generation
- โ Flexible - Works with or without monorepo
๐ 5-Minute Setup
1. Install
pip install django-revolution
2. Add to Django Settings
# settings.pyINSTALLED_APPS = ['drf_spectacular','django_revolution', # Add this line]
3. Easy Configuration with Ready-to-Use Configs ๐ฏ
Django Revolution provides pre-built Pydantic configurations that you can import and use directly:
DRF + Spectacular Configuration (services.py)
# api/settings/config/services.pyfrom django_revolution.drf_config import create_drf_configclass SpectacularConfig(BaseModel):"""API documentation configuration using django_revolution DRF config."""title: str = Field(default='API')description: str = Field(default='RESTful API')version: str = Field(default='1.0.0')schema_path_prefix: str = Field(default='/apix/')enable_browsable_api: bool = Field(default=False)enable_throttling: bool = Field(default=False)def get_django_settings(self) -> Dict[str, Any]:"""Get drf-spectacular settings using django_revolution config."""# Use django_revolution DRF config - zero boilerplate!drf_config = create_drf_config(title=self.title,description=self.description,version=self.version,schema_path_prefix=self.schema_path_prefix,enable_browsable_api=self.enable_browsable_api,enable_throttling=self.enable_throttling,)return drf_config.get_django_settings()
Zone Configuration (revolution.py)
# api/settings/config/revolution.pyfrom django_revolution.app_config import (DjangoRevolutionConfig,ZoneConfig,MonorepoConfig,get_revolution_config)def create_revolution_config(env) -> Dict[str, Any]:"""Get Django Revolution configuration as dictionary."""# Define zones with typed Pydantic modelszones = {'public': ZoneConfig(apps=['accounts', 'billing', 'payments', 'support', 'public'],title='Public API',description='API for public client applications',public=True,auth_required=False,version='v1'),'internal': ZoneConfig(apps=['system', 'mailer'],title='Internal API',description='Internal API for backend services',public=False,auth_required=True,version='v1'),'admin': ZoneConfig(apps=['admin_panel', 'services'],title='Admin API',description='Administrative API endpoints',public=False,auth_required=True,version='v1')}# Option 1: Without monorepo (simplest setup)project_root = env.root_dirreturn get_revolution_config(project_root=project_root, zones=zones, debug=env.debug)# Option 2: With monorepo integration# monorepo = MonorepoConfig(# enabled=True,# path=str(env.root_dir.parent / 'monorepo'),# api_package_path='packages/api/src'# )# return get_revolution_config(project_root=project_root, zones=zones, debug=env.debug, monorepo=monorepo)
4. Multithreaded Generation โก
Django Revolution supports multithreaded generation for faster processing of multiple zones:
Enable Multithreading (Default: Enabled)
# settings.pyDJANGO_REVOLUTION = {'enable_multithreading': True, # Enable parallel processing'max_workers': 20, # Maximum worker threads (default: 20)# ... other settings}
CLI Options
# Use 10 worker threadspython manage.py revolution --generate --max-workers 10# Disable multithreadingpython manage.py revolution --generate --no-multithreading# Interactive mode with multithreading optionspython manage.py revolution --interactive
Performance Benefits
- Parallel schema generation - Multiple zones processed simultaneously
- Concurrent client generation - TypeScript and Python clients generated in parallel
- Parallel monorepo sync - Multiple zones synced to monorepo simultaneously
- Smart fallback - Automatically uses sequential generation for single zones
- Configurable workers - Adjust based on your system capabilities
- Optimized index.ts generation - Created after all clients are ready
Example Performance
# Sequential generation (3 zones)$ time python manage.py revolution --generate --no-multithreadingโ Generation completed in 45.2s# Multithreaded generation (3 zones, 4 workers)$ time python manage.py revolution --generate --max-workers 4โ Generation completed in 18.7s (2.4x speedup)# Full pipeline with monorepo sync (3 zones, 8 workers)$ time python manage.py revolution --generate --max-workers 8โ Generation completed in 12.3s (3.7x speedup)
Multithreading Architecture
Diagram
Click to view fullscreen
Worker Thread Guidelines
System Type | Recommended Workers | Use Case |
---|---|---|
Development | 4-8 | Local development |
CI/CD | 8-16 | Automated builds |
Production | 16-32 | High-performance servers |
Large Projects | 32-64 | Enterprise applications |
5. Generate Clients
# Generate everything (interactive mode)python manage.py revolution# Generate specific zonespython manage.py revolution --zones client admin# TypeScript onlypython manage.py revolution --typescript# Without monorepo syncpython manage.py revolution --no-monorepo
๐งฌ What Does It Generate?
Language | Location | Structure |
---|---|---|
TypeScript | openapi/clients/typescript/ | public/ , admin/ โ index.ts , types.ts , services/ |
Python | openapi/clients/python/ | public/ , admin/ โ client.py , models/ , setup.py |
๐ก Each zone gets its own NPM/PyPI-style package. Ready to publish or import.
โก๏ธ TypeScript Client Auth & Usage
Django Revolution automatically generates a smart TypeScript API client with built-in authentication and token management:
- Zone-based organization - All endpoints grouped by zones (client, admin, internal, etc.)
- Authentication ready - Bearer tokens, refresh tokens, custom headers out of the box
- Simple integration - Works with React, Next.js, Vue, or any frontend framework
- Type-safe - Full TypeScript support with autocomplete
Example Usage:
import API from '@myorg/api-client';const api = new API('https://api.example.com');// Authenticationapi.setToken('your-access-token', 'your-refresh-token');// Call any endpointconst user = await api.public.getCurrentUser();const products = await api.public.listProducts();// Check authentication statusif (api.isAuthenticated()) {// User is logged in}// Change API URLapi.setApiUrl('https://api.newhost.com');
Features included:
- โ Automatic token management (localStorage)
- โ Custom headers support
- โ API key authentication
- โ Zone-based endpoint organization
- โ TypeScript types for all endpoints
- โ Error handling and validation
No need to write authentication logic - everything is handled automatically!
๐ Auto-Generated URLs
Django Revolution automatically generates all necessary URLs for your API zones:
# urls.pyfrom django_revolution import add_revolution_urlsurlpatterns = [# Your existing URLspath('admin/', admin.site.urls),]# Django Revolution automatically adds:# - /api/public/schema/ (Swagger UI)# - /api/public/schema.yaml (OpenAPI spec)# - /api/admin/schema/ (Swagger UI)# - /api/admin/schema.yaml (OpenAPI spec)# - /openapi/archive/ (Generated clients)urlpatterns = add_revolution_urls(urlpatterns)
Generated URLs:
/api/{zone}/schema/
- Interactive Swagger UI/api/{zone}/schema.yaml
- OpenAPI specification/openapi/archive/
- Download generated clients
๐งช CLI Toolbox
Django Management Commands
# Generate all clients (interactive mode)python manage.py revolution# Specific zonespython manage.py revolution --zones public admin# Generator optionspython manage.py revolution --typescriptpython manage.py revolution --pythonpython manage.py revolution --no-archive# Monorepo optionspython manage.py revolution --no-monorepo# Utility commandspython manage.py revolution --statuspython manage.py revolution --list-zonespython manage.py revolution --validatepython manage.py revolution --clean# New validation commandspython manage.py revolution --validate-zonespython manage.py revolution --show-urlspython manage.py revolution --test-schemas
Standalone CLI (Interactive)
# Interactive CLI with rich interfacedjango-revolution# Or run directlypython -m django_revolution.cli
The standalone CLI provides an interactive interface with:
- ๐ฏ Zone selection with checkboxes
- ๐ง Client type selection (TypeScript/Python)
- ๐ฆ Archive creation options
- ๐ Real-time progress tracking
- โ Generation summary with results table
Development Scripts
Interactive Development CLI:
# Main development interfacepython scripts/dev_cli.py# Or install and use as package commandpip install -e .dev-cli
Individual Scripts:
# Version managementpython scripts/version_manager.py getpython scripts/version_manager.py bump --bump-type patch# Generate requirements filespython scripts/generate_requirements.py# Interactive publishingpython scripts/publisher.py# Test generation./scripts/test_generation.sh
Package Commands (after installation):
# Version managementversion-manager getversion-manager bump --bump-type minor# Publishingpublisher# Requirements generationgenerate-requirements
New CLI Features
Zone Validation & Testing:
# Validate each zone with detailed loggingpython manage.py revolution --validate-zones# Show URL patterns for each zonepython manage.py revolution --show-urls# Test schema generation for each zonepython manage.py revolution --test-schemas
Rich Output Examples:
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ ๐งช Validation โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎโ Detailed Zone Validation โโฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ==================================================๐ Validating zone: public------------------------------โ Zone configuration: Public APIApps (1):โ apps.public_apiโ URL patterns: 1 patternsโ Schema patterns: 2 patternsโ Zone 'public' is valid๐ Validation Summary:Valid zones: 2Invalid zones: 0๐ All zones are valid!
๐ช Multi-Monorepo Integration (Optional)
Django Revolution supports multiple monorepo configurations with pnpm:
With Multiple Monorepos
# settings.py - With multiple monorepo configurationsfrom django_revolution.app_config import MonorepoConfig, MonorepoSettings# Configure multiple monoreposmonorepo_settings = MonorepoSettings(enabled=True,configurations=[# Main frontend monorepoMonorepoConfig(name="frontend",enabled=True,path=str(BASE_DIR.parent / 'monorepo'),api_package_path='packages/api'),# Mobile app monorepoMonorepoConfig(name="mobile",enabled=True,path=str(BASE_DIR.parent / 'mobile-monorepo'),api_package_path='packages/api-client'),# Admin panel monorepoMonorepoConfig(name="admin",enabled=False, # Disabled for nowpath=str(BASE_DIR.parent / 'admin-monorepo'),api_package_path='packages/admin-api'),])DJANGO_REVOLUTION = get_revolution_config(project_root=BASE_DIR,zones=zones,monorepo=monorepo_settings)
With Single Monorepo
# settings.py - With single monorepo (simplest)from django_revolution.app_config import MonorepoConfig, MonorepoSettingsmonorepo_settings = MonorepoSettings(enabled=True,configurations=[MonorepoConfig(name="frontend",enabled=True,path=str(BASE_DIR.parent / 'monorepo'),api_package_path='packages/api'),])DJANGO_REVOLUTION = get_revolution_config(project_root=BASE_DIR,zones=zones,monorepo=monorepo_settings)
Without Monorepo
# settings.py - Without monorepo (simplest)DJANGO_REVOLUTION = get_revolution_config(project_root=BASE_DIR,zones=zones)
Auto-generated monorepo structure:
# pnpm-workspace.yaml (auto-generated)packages:- 'packages/**'- 'packages/api/**' # Added automatically
Package.json dependencies:
{"dependencies": {"@markolofsen/public-api-client": "workspace:*","@markolofsen/admin-api-client": "workspace:*"}}
Generated locally:
openapi/clients/typescript/
- TypeScript clientsopenapi/clients/python/
- Python clientsopenapi/archive/
- Versioned archives
๐ Comparison Table
Feature | Django Revolution | drf-spectacular + generators | openapi-generator-cli | Fern.dev | Manual Setup |
---|---|---|---|---|---|
Zone-based architecture | โ UNIQUE | โ | โ | โ | โ |
Dynamic zone management | โ UNIQUE | โ | โ | โ | โ |
Automatic URL generation | โ UNIQUE | โ | โ | โ | โ |
Monorepo integration | โ OPTIONAL | โ | โ | โ | โ |
Django management commands | โ UNIQUE | โ | โ | โ | โ |
Rich CLI interface | โ UNIQUE | โ | โ | โ | โ |
Zone validation & testing | โ UNIQUE | โ | โ | โ | โ |
Archive management | โ UNIQUE | โ | โ | โ | โ |
TypeScript + Python clients | โ | โ | โ | โ | โ |
DRF native integration | โ SEAMLESS | โ | โ ๏ธ (via schema) | โ | โ |
Ready-to-use Pydantic configs | โ UNIQUE | โ | โ | โ | โ |
Zero configuration | โ UNIQUE | โ | โ | โ | โ |
Environment variables | โ Pydantic | โ | โ | โ | โ |
CLI interface | โ Rich output | โ | โ | โ | โ |
Multithreaded generation | โ UNIQUE | โ | โ | โ | โ |
Comprehensive testing | โ UNIQUE | โ | โ | โ | โ |
โ When to Use
โ Perfect For
- Large Django projects with multiple API audiences
- Monorepo architectures with frontend/backend separation
- Teams needing consistent API client generation
- Projects requiring zone-based API organization
- Automated CI/CD pipelines
- Simple projects without monorepo (optional integration)
โ Not For
- Simple single-zone APIs (overkill)
- Non-Django projects (use Fern.dev instead)
- Manual control freaks (use drf-spectacular + generators)
๐ง Power Features
Dynamic Zone Management
No more static files! Django Revolution uses in-memory dynamic module generation:
- โ Zero static files - Everything generated dynamically
- โ Zone caching - Fast repeated generation
- โ Module registry - Automatic cleanup and management
- โ URL pattern validation - Real-time validation
- โ Schema testing - Test generation before production
Archive Management
# Automatic versioning with timestamped archivesopenapi/archive/โโโ files/โ โโโ 2024-01-15_14-30-00/โ โ โโโ public.zipโ โ โโโ admin.zipโ โโโ 2024-01-15_15-45-00/โ โโโ public.zipโ โโโ admin.zipโโโ latest/โโโ public.zipโโโ admin.zip
Each archive contains both TypeScript and Python clients:
typescript/
- Generated TypeScript clientpython/
- Generated Python client
Custom Templates
'generators': {'typescript': {'custom_templates': './templates/typescript'},'python': {'custom_templates': './templates/python'}}
Programmatic Usage
from django_revolution import OpenAPIGenerator, get_settingsconfig = get_settings()generator = OpenAPIGenerator(config)summary = generator.generate_all(zones=['public', 'admin'])
๐ FAQ
Q: Is this production-ready?
โ
Yes. Used in monorepos and multi-tenant production apps.
Q: What if I use DRF with custom auth?
Use setHeaders()
or setApiKey()
to inject custom logic.
Q: Can I use this in non-monorepo setups?
Absolutely! Monorepo integration is completely optional. Just don't pass the monorepo
parameter.
Q: What if I need only TypeScript clients?
Use --typescript
flag to generate only TS clients.
Q: Does it support custom OpenAPI decorators?
Yes, built on drf-spectacular
so all extensions apply.
Q: How do I use the ready-to-use Pydantic configs?
Simply import and use: from django_revolution.drf_config import create_drf_config
and from django_revolution.app_config import ZoneConfig, get_revolution_config
.
Q: Are the Pydantic configs type-safe?
Yes! Full Pydantic v2 validation with IDE autocomplete and error checking.
Q: How do I disable monorepo integration?
Either don't pass the monorepo
parameter to get_revolution_config()
, or use the --no-monorepo
flag when running the command.
Q: What's new in the latest version?
- ๐ Dynamic zone management - No more static files, everything generated in-memory
- ๐จ Rich CLI interface - Beautiful interactive commands with progress tracking
- โ Zone validation & testing - Validate zones and test schema generation
- ๐ง Unified CLI architecture - Single codebase for Django commands and standalone CLI
- ๐ Enhanced output - Rich tables and progress indicators
- โก Multithreaded generation - Parallel processing for faster client generation
- ๐งช Comprehensive testing - Full test suite with pytest and proper mocking
Q: How does the dynamic zone system work?
Django Revolution creates URL configuration modules in-memory using Python's importlib
and exec
. This eliminates the need for static .py
files and provides better performance and flexibility.
Q: How does multithreading improve performance?
Multithreading allows parallel processing of multiple zones, schema generation, and client generation. For 3 zones, you can see 2-3x speedup compared to sequential processing.
๐ค Contributing
# Development setupgit clone https://github.com/markolofsen/django-revolution.gitcd django-revolutionpip install -e ".[dev]"# Run testspytestblack django_revolution/isort django_revolution/
๐ Support
- Documentation: https://revolution.unrealos.com/
- Issues: https://github.com/markolofsen/django-revolution/issues
- Discussions: https://github.com/markolofsen/django-revolution/discussions
๐ License
Non-Commercial License - see LICENSE file for details.
For commercial use, please contact Unrealos Inc. at licensing@unrealos.com
Made with โค๏ธ by the Unrealos Team
Django Revolution - The ONLY tool that makes Django API client generation truly automated and zone-aware.