Transform your Django development from chaos to zen in minutes, not months.
Django-CFG is the production-ready configuration framework that eliminates Django's biggest pain points. Say goodbye to 500-line settings.py
files and hello to type-safe, YAML-powered, intelligent configuration that just works.
π― See it in action β Complete sample project with blog, shop, newsletter campaigns, lead management, multi-database routing, and beautiful admin interface.
- 500+ line settings files that nobody wants to touch
- Zero type safety - typos break production
- Manual everything - databases, caching, admin, APIs
- Environment hell - different configs everywhere
- Ugly admin interface stuck in 2010
- No API documentation without hours of setup
- Type-safe configuration with Pydantic validation
- 100% type-safe with full IDE support
- Smart automation that knows what you need
- Environment detection that just works
- Beautiful modern admin with Tailwind CSS
- Auto-generated API docs and client libraries
# Using Poetry (recommended)
poetry add django-cfg
# Using pip
pip install django-cfg
# Using pipenv
pipenv install django-cfg
1. Create config.py
:
from django_cfg import DjangoConfig
class MyConfig(DjangoConfig):
project_name: str = "MyAwesomeApp"
secret_key: str = "your-secret-key"
debug: bool = True
project_apps: list[str] = ["accounts", "blog", "shop"]
config = MyConfig()
2. Update settings.py
:
from .config import config
globals().update(config.get_all_settings())
3. Run your project:
python manage.py runserver
That's it! π You now have:
- β Beautiful admin interface with Unfold + Tailwind CSS
- β Built-in support ticket system with chat interface
- β Newsletter campaigns with email tracking & analytics
- β Lead management system with CRM integration
- β Auto-generated API documentation
- β Environment-aware configuration
- β Type-safe settings with full IDE support
- β Production-ready security defaults
Feature | Traditional Django | Django-CFG |
---|---|---|
π Configuration | 500+ lines of settings hell | Type-safe & organized |
π Type Safety | Pray and hope | 100% validated |
π¨ Admin Interface | Ugly 2010 design | Modern Unfold + Tailwind |
π Dashboard | Basic admin index | Real-time metrics & widgets |
ποΈ Multi-Database | Manual routing nightmare | Smart auto-routing |
β‘ Commands | Terminal only | Beautiful web interface |
π API Docs | Hours of manual setup | Auto-generated OpenAPI |
π¦ Client Generation | Write clients manually | Auto TS/Python clients |
π« Support System | Build from scratch | Built-in tickets & chat |
π€ User Management | Basic User model | OTP auth & profiles |
π§ Notifications | Manual SMTP/webhooks | Email & Telegram modules |
π Deployment | Cross fingers | Production-ready defaults |
π‘ IDE Support | Basic syntax highlighting | Full IntelliSense paradise |
π Config Errors | Runtime surprises | Compile-time validation |
π Developer Joy | Constant frustration | Pure coding bliss |
Full Pydantic validation with IDE autocomplete and compile-time error checking.
Modern Django Unfold admin with Tailwind CSS, dark mode, and custom dashboards.
Live metrics, system health, and custom widgets that update automatically.
Automatic database routing based on app labels with connection pooling.
Run Django management commands from a beautiful web interface with real-time logs.
OpenAPI/Swagger docs generated automatically with zone-based architecture.
TypeScript and Python API clients generated per zone automatically.
Complete ticket management with modern chat interface, email notifications, and admin integration.
Built-in accounts system with OTP authentication, user profiles, activity tracking, and registration sources.
Email, Telegram, Support ticket system, Newsletter campaigns, Lead management, and advanced User management ready out of the box.
Automatic dev/staging/production detection with appropriate defaults.
Django-CFG includes powerful management commands for development and operations:
Command | Description | Example |
---|---|---|
check_settings |
Validate configuration and settings | python manage.py check_settings |
create_token |
Generate API tokens and keys | python manage.py create_token --user admin |
generate |
Generate API clients and documentation | python manage.py generate --zone client |
migrator |
Smart database migrations with routing | python manage.py migrator --apps blog,shop |
script |
Run custom scripts with Django context | python manage.py script my_script.py |
show_config |
Display current configuration | python manage.py show_config --format yaml |
show_urls |
Display all URL patterns | python manage.py show_urls --zone client |
superuser |
Create superuser with smart defaults | python manage.py superuser --email admin@example.com |
test_email |
Test email configuration | python manage.py test_email --to test@example.com |
test_telegram |
Test Telegram bot integration | python manage.py test_telegram --chat_id 123 |
support_stats |
Display support ticket statistics | python manage.py support_stats --format json |
test_newsletter |
Test newsletter sending functionality | python manage.py test_newsletter --email test@example.com |
newsletter_stats |
Display newsletter campaign statistics | python manage.py newsletter_stats --format json |
leads_stats |
Display lead conversion statistics | python manage.py leads_stats --format json |
validate_config |
Deep validation of all settings | python manage.py validate_config --strict |
Django-CFG automatically detects your environment and applies appropriate settings:
Environment | Detection Method | Cache Backend | Email Backend | Database SSL | Debug Mode |
---|---|---|---|---|---|
Development | DEBUG=True or local domains |
Memory/Redis | Console | Optional | True |
Testing | pytest or test in command |
Dummy Cache | In-Memory | Disabled | False |
Staging | STAGING=True or staging domains |
Redis | SMTP | Required | False |
Production | PRODUCTION=True or prod domains |
Redis | SMTP | Required | False |
Comprehensive logging with environment-aware configuration:
# Automatic log configuration based on environment
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
'style': '{',
},
'simple': {
'format': '{levelname} {message}',
'style': '{',
},
},
'handlers': {
'file': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': 'django.log',
'formatter': 'verbose',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple',
},
},
'root': {
'handlers': ['console', 'file'],
'level': 'INFO',
},
}
Features:
- Environment-specific log levels
- Automatic file rotation
- Structured logging with JSON support
- Integration with monitoring systems
- Custom formatters for different outputs
Django-CFG provides ready-made Redoc/Swagger solutions for each API zone:
revolution: RevolutionConfig = RevolutionConfig(
zones={
"client": ZoneConfig(
apps=["accounts", "billing"],
title="Client API",
public=True,
),
"admin": ZoneConfig(
apps=["management", "reports"],
title="Admin API",
auth_required=True,
),
}
)
/api/client/docs/
- Interactive Swagger UI for client zone/api/client/redoc/
- Beautiful ReDoc documentation/api/admin/docs/
- Admin zone Swagger UI/api/admin/redoc/
- Admin zone ReDoc
# Generate TypeScript client for client zone
python manage.py generate --zone client --format typescript
# Generate Python client for admin zone
python manage.py generate --zone admin --format python
Django-CFG includes a complete support ticket system with modern chat interface:
- π― Ticket Management - Create, assign, and track support tickets
- π¬ Chat Interface - Beautiful Tailwind CSS chat UI for conversations
- π§ Email Integration - Automatic notifications for ticket updates
- π₯ User Management - Support for both staff and customer interactions
- π Dashboard Integration - Real-time metrics in Unfold admin
- π API Ready - RESTful API endpoints for all support operations
from django_cfg import DjangoConfig
class MyConfig(DjangoConfig):
project_name: str = "My App"
enable_support: bool = True # That's it!
config = MyConfig()
- β Admin Interface - Support section in sidebar with tickets & messages
- β Dashboard Cards - Live ticket statistics and quick actions
- β
API Endpoints -
/api/support/
zone with full CRUD operations - β Email Templates - Beautiful HTML emails with your branding
- β
Chat Interface - Modern
/support/chat/{ticket_uuid}/
pages
enable_support: bool = False # Removes from admin, API, and dashboard
Django-CFG includes a complete newsletter and email marketing system with tracking and analytics:
- π¬ Newsletter Management - Create, schedule, and manage email newsletters
- π₯ Subscription Management - User subscriptions with double opt-in and unsubscribe
- π Email Tracking - Open rates, click tracking, and engagement analytics
- π― Campaign System - Organize newsletters into campaigns with templates
- π Bulk Email - Send to thousands of subscribers with delivery tracking
- π API Ready - RESTful API endpoints for all newsletter operations
- π± Email Templates - Beautiful responsive HTML templates with tracking pixels
from django_cfg import DjangoConfig
class MyConfig(DjangoConfig):
project_name: str = "My App"
enable_newsletter: bool = True # That's it!
config = MyConfig()
- β Admin Interface - Newsletter section with campaigns, subscriptions & email logs
- β Dashboard Cards - Live newsletter statistics and recent campaigns
- β
API Endpoints -
/api/newsletter/
zone with full CRUD operations - β Email Templates - Responsive HTML emails with your branding and tracking
- β Tracking System - Automatic open/click tracking with UUID-based security
- β Subscription Forms - Ready-to-use subscription and unsubscribe endpoints
from django_cfg.apps.newsletter.services.email_service import NewsletterEmailService
# Send newsletter with tracking
service = NewsletterEmailService()
result = service.send_newsletter_email(
newsletter=newsletter,
subject="Monthly Update",
email_title="Our Latest News",
main_text="Check out what's new this month!",
button_text="Read More",
button_url="https://example.com/news",
send_to_all=True # Send to all subscribers
)
enable_newsletter: bool = False # Removes from admin, API, and dashboard
Django-CFG includes a comprehensive lead collection and CRM system for capturing and managing potential customers:
- π Lead Capture - Collect leads from contact forms, landing pages, and API
- π·οΈ Lead Sources - Track where leads came from (web, mobile, ads, referrals)
- π Lead Scoring - Automatic scoring based on engagement and profile data
- π Status Management - Lead lifecycle from new to converted or closed
- π§ Email Integration - Automatic notifications for new leads and status changes
- π± API Ready - RESTful API endpoints for all lead operations
- π― CRM Integration - Ready for integration with external CRM systems
from django_cfg import DjangoConfig
class MyConfig(DjangoConfig):
project_name: str = "My App"
enable_leads: bool = True # That's it!
config = MyConfig()
- β Admin Interface - Leads section with lead management and source tracking
- β Dashboard Cards - Live lead statistics and conversion metrics
- β
API Endpoints -
/api/leads/
zone with full CRUD operations - β Contact Forms - Ready-to-use lead capture forms and endpoints
- β Email Notifications - Automatic alerts for new leads and status changes
- β Source Tracking - Automatic detection of lead sources and campaigns
from django_cfg.apps.leads.models import Lead, LeadSource
# Create lead from contact form
lead = Lead.objects.create(
name="John Doe",
email="john@example.com",
phone="+1234567890",
message="Interested in your services",
source=LeadSource.objects.get(name="Website Contact Form"),
status=Lead.LeadStatus.NEW
)
enable_leads: bool = False # Removes from admin, API, and dashboard
Django-CFG includes a comprehensive user management system with OTP authentication, profiles, and activity tracking:
- π OTP Authentication - Secure one-time password authentication via email
- π₯ Custom User Model - Extended user model with profiles and metadata
- π Activity Tracking - Complete audit trail of user actions and logins
- π Registration Sources - Track where users came from (web, mobile, API, etc.)
- π§ Email Integration - Beautiful welcome emails and OTP notifications
- π‘οΈ Security Features - Failed attempt tracking, account lockouts, and audit logs
- π± API Ready - RESTful API endpoints for all user operations
from django_cfg import DjangoConfig
class MyConfig(DjangoConfig):
project_name: str = "My App"
enable_accounts: bool = True # That's it!
# auth_user_model is automatically set to django_cfg_accounts.CustomUser
config = MyConfig()
- β
Custom User Model - Automatically sets
AUTH_USER_MODEL
todjango_cfg_accounts.CustomUser
- β Admin Interface - "Users & Access" section with users, groups, and registration sources
- β Dashboard Integration - User statistics and recent activity widgets
- β
API Endpoints -
/api/accounts/
zone with authentication, profiles, and OTP - β Email Templates - Welcome emails and OTP verification with your branding
- β Migration Safety - Smart migration ordering to avoid conflicts
from django_cfg.apps.accounts.services.otp_service import OTPService
# Request OTP for user
success, error = OTPService.request_otp("user@example.com")
# Verify OTP code
user = OTPService.verify_otp("user@example.com", "123456")
- Extended Profile - Additional fields for user metadata
- Activity Tracking - Automatic logging of user actions
- Registration Sources - Track user acquisition channels
- Security Audit - Failed login attempts and security events
enable_accounts: bool = False # Uses Django's default User model
Here's a complete production configuration:
from django_cfg import DjangoConfig, DatabaseConnection, UnfoldConfig, RevolutionConfig
class ProductionConfig(DjangoConfig):
"""π Production-ready configuration"""
# === Project Settings ===
project_name: str = "CarAPIS"
project_version: str = "2.0.0"
secret_key: str = env.secret_key
debug: bool = False
# === Multi-Database Setup ===
databases: dict[str, DatabaseConnection] = {
"default": DatabaseConnection(
engine="django.db.backends.postgresql",
name="carapis_main",
user=env.db_user,
password=env.db_password,
host=env.db_host,
port=5432,
sslmode="require",
),
"analytics": DatabaseConnection(
engine="django.db.backends.postgresql",
name="carapis_analytics",
user=env.db_user,
password=env.db_password,
host=env.db_host,
routing_apps=["analytics", "reports"],
),
}
# === Beautiful Admin ===
unfold: UnfoldConfig = UnfoldConfig(
site_title="CarAPIS Admin",
site_header="CarAPIS Control Center",
theme="auto",
dashboard_callback="api.dashboard.main_callback",
)
# === Built-in Modules ===
enable_support: bool = True # Automatic tickets, chat interface, email notifications
enable_accounts: bool = True # Advanced user management with OTP authentication
enable_newsletter: bool = True # Email marketing, campaigns, tracking & analytics
enable_leads: bool = True # Lead capture, CRM integration, source tracking
# === Multi-Zone API ===
revolution: RevolutionConfig = RevolutionConfig(
api_prefix="api/v2",
zones={
"public": ZoneConfig(
apps=["cars", "search"],
title="Public API",
description="Car data and search",
public=True,
),
"partner": ZoneConfig(
apps=["integrations", "webhooks"],
title="Partner API",
auth_required=True,
rate_limit="1000/hour",
),
}
)
config = ProductionConfig()
Django-CFG includes comprehensive testing utilities:
def test_configuration():
"""Test your configuration is valid"""
config = MyConfig()
settings = config.get_all_settings()
# Validate required settings
assert "SECRET_KEY" in settings
assert settings["DEBUG"] is False
assert "myapp" in settings["INSTALLED_APPS"]
# Test database connections
assert "default" in settings["DATABASES"]
assert settings["DATABASES"]["default"]["ENGINE"] == "django.db.backends.postgresql"
# Validate API configuration
assert "SPECTACULAR_SETTINGS" in settings
assert settings["SPECTACULAR_SETTINGS"]["TITLE"] == "My API"
poetry add django-cfg
# environment/config.dev.yaml
secret_key: "your-development-secret-key"
debug: true
database:
url: "postgresql://user:pass@localhost:5432/mydb"
redis_url: "redis://localhost:6379/0"
# config.py
from django_cfg import DjangoConfig
from .environment import env
class MyConfig(DjangoConfig):
project_name: str = "My Project"
secret_key: str = env.secret_key
debug: bool = env.debug
project_apps: list[str] = ["accounts", "blog"]
config = MyConfig()
# settings.py - Replace everything with this
from .config import config
globals().update(config.get_all_settings())
python manage.py check
python manage.py runserver
Result: Your 500-line settings.py
is now organized, fully type-safe, and production-ready! π
We welcome contributions! Here's how to get started:
git clone https://github.com/markolofsen/django-cfg.git
cd django-cfg
poetry install
poetry run pytest
# Run tests
poetry run pytest
# Format code
poetry run black .
# Type checking
poetry run mypy .
# Build package
poetry build
MIT License - see LICENSE file for details.
- Django - The web framework for perfectionists with deadlines
- Pydantic - Data validation using Python type hints
- Django Unfold - Beautiful modern admin interface
- Django Revolution - API generation and zone management
Made with β€οΈ by the UnrealOS Team
Django-CFG: Because configuration should be simple, safe, and powerful.
π Ready to transform your Django experience? Get started now!