Django authentication backend that automatically creates a superuser on first login
Project description
๐ Django Create Initial User
Effortless superuser creation for Django projects
Skip the hassle of python manage.py createsuperuser and jump straight into development!
๐ Quick Start โข ๐ Documentation โข ๐ง Installation โข ๐ค Contributing
๐ Why Django Create Initial User?
๐ค Before (The Old Way)# Every. Single. Time.
python manage.py migrate
python manage.py createsuperuser
# Enter username: admin
# Enter email: admin@example.com
# Enter password: ********
# Enter password (again): ********
Result: Repetitive setup, broken automation, frustrated developers |
๐ After (The Django Create Initial User Way)# settings.py - One time setup
if DEBUG:
AUTHENTICATION_BACKENDS.insert(0,
'create_initial_superuser.backends.CreateInitialSuperUserBackend'
)
Result: ๐ฏ Login with ANY credentials โ โจ Instant superuser โ ๐ Start coding! |
โจ Features That Make You Go "Wow!"
| ๐ฏ Smart Creation | ๐ก๏ธ Security First | ๐ง Zero Config | ๐งช Battle Tested |
|---|---|---|---|
| Only creates superuser when none exist | DEBUG-mode only by default | Works out of the box | 100% test coverage |
| Auto-detects email usernames | Proper password hashing | No database changes | Supports Django 3.2-5.0 |
| Transparent warning system | Production-safe defaults | Type-hinted codebase | Python 3.9-3.12 ready |
๐ Quick Start
๐ฆ Installation
# Using pip
pip install django-create-initial-user
# Using uv (recommended)
uv add django-create-initial-user
# Using poetry
poetry add django-create-initial-user
โ๏ธ Configuration
Add to your Django settings.py:
# Add to INSTALLED_APPS
INSTALLED_APPS = [
# ... your apps
'create_initial_superuser',
]
# Configure authentication backend
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
]
# ๐ฅ The magic happens here!
if DEBUG:
AUTHENTICATION_BACKENDS.insert(0,
'create_initial_superuser.backends.CreateInitialSuperUserBackend'
)
๐ Usage
- Start your Django project normally
- Navigate to
/admin/ - Login with ANY credentials you want for your superuser
- โจ BOOM! You're now logged in as a superuser!
# That's literally it. No manage.py commands needed! ๐
๐ฌ See It In Action
sequenceDiagram
participant Dev as ๐จโ๐ป Developer
participant Django as ๐ฏ Django App
participant Backend as ๐ Auth Backend
participant DB as ๐๏ธ Database
Dev->>Django: Navigate to /admin/
Django->>Dev: Show login form
Dev->>Django: Submit credentials (admin/secret123)
Django->>Backend: authenticate(admin, secret123)
Backend->>DB: Check for superusers
DB->>Backend: No superusers found!
Backend->>DB: Create superuser(admin, secret123)
DB->>Backend: โ
Superuser created
Backend->>Django: Return authenticated user
Django->>Dev: ๐ Welcome to Django Admin!
The entire flow happens transparently - no manual steps required!
๐ Comparison Matrix
| Feature | Manual createsuperuser | Fixtures | Django Create Initial User |
|---|---|---|---|
| ๐ Zero Setup Time | โ | โ ๏ธ | โ |
| ๐ Works Every Time | โ | โ ๏ธ | โ |
| ๐ก๏ธ Production Safe | โ | โ ๏ธ | โ |
| ๐ฏ Custom Credentials | โ | โ | โ |
| ๐ง Smart Email Detection | โ ๏ธ | โ | โ |
| ๐งช Test Friendly | โ | โ | โ |
| ๐ง No Database Changes | โ | โ | โ |
๐ฏ Perfect For
๐โโ๏ธ Rapid PrototypingSkip admin setup |
๐ณ Docker DevelopmentNo interactive prompts |
๐ Teaching DjangoStudents focus on concepts |
๐ CI/CD PipelinesAutomated testing |
๐ก๏ธ Security Features
# ๐ Built-in Security Measures
โ
DEBUG mode only by default
โ
Proper password hashing (Django's make_password)
โ
Transparent operation (warning messages)
โ
No backdoors or hardcoded credentials
โ
Production deployment warnings
โ
Comprehensive security documentation
๐จ Security Note: This package is designed for development environments. While it can be used in production for initial deployment, we recommend removing it from
AUTHENTICATION_BACKENDSafter creating your production superuser.
๐ Documentation
| ๐ Guide | ๐ Link | ๐ Description |
|---|---|---|
| ๐ Quick Start | Getting Started | Get up and running in 2 minutes |
| โ๏ธ Configuration | Settings Guide | Advanced configuration options |
| ๐ก๏ธ Security | Security Guide | Best practices and considerations |
| ๐ API Reference | API Docs | Complete API documentation |
| ๐ Troubleshooting | FAQ | Common issues and solutions |
| ๐ค Contributing | Contributing Guide | Help make this package better |
๐จ Advanced Usage
๐ง Custom Configuration Examples
Production-Ready Setup
# settings.py
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
]
# Only enable in development
if DEBUG or os.getenv('ENABLE_INITIAL_SUPERUSER'):
AUTHENTICATION_BACKENDS.insert(0,
'create_initial_superuser.backends.CreateInitialSuperUserBackend'
)
Docker Compose Integration
# docker-compose.yml
services:
web:
build: .
environment:
- DEBUG=True
- ENABLE_INITIAL_SUPERUSER=1
ports:
- "8000:8000"
Custom User Model Support
# models.py
from django.contrib.auth.models import AbstractUser
class CustomUser(AbstractUser):
email = models.EmailField(unique=True)
# The backend automatically works with any user model! ๐
๐งช Testing & Quality
# Run the comprehensive test suite
git clone https://github.com/rsp2k/django-create-initial-user.git
cd django-create-initial-user
# Quick test (using our dev script)
python dev-test.py
# Full test matrix (all Python/Django versions)
tox
# Security scan
make security
๐ Test Coverage
- โ 100% line coverage across all modules
- โ Edge case testing (missing credentials, DEBUG=False, etc.)
- โ Security validation (password hashing, warning messages)
- โ Integration testing with Django's auth system
- โ Multi-version compatibility testing
๐ Performance & Compatibility
๐ Python Support
๐ฏ Django Support
๐ค Contributing
Love this project? Here's how you can help! ๐
๐ Star the RepoShow your support by |
๐ Report IssuesFound a bug? |
๐ Submit PRsCode contributions |
๐ป Development Setup
# ๐ Quick development setup
git clone https://github.com/rsp2k/django-create-initial-user.git
cd django-create-initial-user
# Option 1: Automated setup (recommended)
make dev-setup
# Option 2: Manual setup with uv
uv venv # Creates .venv virtual environment
uv pip install -e ".[dev]" # Install with dev dependencies
uv run pre-commit install # Install git hooks
# Option 3: Complete pre-commit setup with validation
python setup-precommit.py # Interactive setup and validation
# Run tests and quality checks
make test # Or: python dev-test.py
make lint # Or: uv run pytest tests/
# You're ready to contribute! ๐
๐ Recognition & Stats
๐ Downloads
|
๐ Community
|
๐ Activity
|
๐ Success Stories
"This package saved me hours of setup time during a 48-hour hackathon. Absolute game-changer!"
โ Sarah Chen, Full-Stack Developer
"We use this in all our Django training courses. Students can focus on learning Django instead of admin setup."
โ Dr. Rodriguez, Computer Science Professor
"Perfect for our Docker-based CI/CD pipeline. No more interactive superuser creation breaking our builds!"
โ Mike Thompson, DevOps Engineer
๐ License & Legal
This project is licensed under the MIT License - see the LICENSE file for details.
ยฉ 2025 Django Create Initial User Contributors
๐ Links & Resources
| ๐ Resource | ๐ Link |
|---|---|
| ๐ฆ PyPI Package | pypi.org/project/django-create-initial-user |
| ๐ Documentation | docs.django-create-initial-user.com |
| ๐ Issue Tracker | GitHub Issues |
| ๐ฌ Discussions | GitHub Discussions |
| ๐ง Email Support | support@django-create-initial-user.com |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_create_initial_user-1.2.1.tar.gz.
File metadata
- Download URL: django_create_initial_user-1.2.1.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36a4ea1acb09eb57bdfbaf0cf21d4ee23a8b10dd23c94262a643797efd730ba4
|
|
| MD5 |
1355888de4e9df1d87c9452e96e8ac06
|
|
| BLAKE2b-256 |
d6afa8b9f1b5f82f24e34fca433ebf69929074196923a3b91b865a4e3765ee2b
|
Provenance
The following attestation bundles were made for django_create_initial_user-1.2.1.tar.gz:
Publisher:
publish.yml on rsp2k/django-create-initial-user
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_create_initial_user-1.2.1.tar.gz -
Subject digest:
36a4ea1acb09eb57bdfbaf0cf21d4ee23a8b10dd23c94262a643797efd730ba4 - Sigstore transparency entry: 232933263
- Sigstore integration time:
-
Permalink:
rsp2k/django-create-initial-user@037fc3ff04e459eedca11ab9c019eb126e5cd316 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/rsp2k
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@037fc3ff04e459eedca11ab9c019eb126e5cd316 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file django_create_initial_user-1.2.1-py3-none-any.whl.
File metadata
- Download URL: django_create_initial_user-1.2.1-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7807ce77940c32ea1cf2efd8a4b6e5f76508a43b89d15af28565c5d49bb094a8
|
|
| MD5 |
c6b6f45e538fd5f2aae9ec4dbf3fcac9
|
|
| BLAKE2b-256 |
f7fff10e85c2224ae3582447c9342452377600b79bc4880775510fc3f66706b9
|
Provenance
The following attestation bundles were made for django_create_initial_user-1.2.1-py3-none-any.whl:
Publisher:
publish.yml on rsp2k/django-create-initial-user
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_create_initial_user-1.2.1-py3-none-any.whl -
Subject digest:
7807ce77940c32ea1cf2efd8a4b6e5f76508a43b89d15af28565c5d49bb094a8 - Sigstore transparency entry: 232933270
- Sigstore integration time:
-
Permalink:
rsp2k/django-create-initial-user@037fc3ff04e459eedca11ab9c019eb126e5cd316 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/rsp2k
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@037fc3ff04e459eedca11ab9c019eb126e5cd316 -
Trigger Event:
workflow_dispatch
-
Statement type: