Skip to main content

Django authentication backend that automatically creates a superuser on first login

Project description

๐Ÿ” Django Create Initial User

Effortless superuser creation for Django projects

Django Create Initial User Logo

๐Ÿงช Tests ๐Ÿ“ฆ PyPI ๐Ÿ Python ๐ŸŽฏ Django

๐Ÿ“ˆ Coverage โญ Stars ๐Ÿ“„ License ๐Ÿ”„ Downloads

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
  1. Start your Django project normally
  2. Navigate to /admin/
  3. Login with ANY credentials you want for your superuser
  4. โœจ 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 Prototyping

Skip admin setup
Jump straight to coding
Perfect for hackathons

๐Ÿณ Docker Development

No interactive prompts
Automated container setup
DevOps engineers love this

๐ŸŽ“ Teaching Django

Students focus on concepts
Not admin user creation
Educators' favorite tool

๐Ÿ”„ CI/CD Pipelines

Automated testing
No manual intervention
QA teams rejoice


๐Ÿ›ก๏ธ 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_BACKENDS after 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

๐Ÿ† Quality Metrics

Coverage Security Code 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

Python 3.9 Python 3.10 Python 3.11 Python 3.12

๐ŸŽฏ Django Support

Django 3.2 Django 4.0 Django 4.1 Django 4.2 Django 5.0


๐Ÿค Contributing

Love this project? Here's how you can help! ๐Ÿ’–

๐ŸŒŸ Star the Repo

Show your support by
starring the repository!
It really motivates us!

Star

๐Ÿ› Report Issues

Found a bug?
Have a feature idea?
We want to hear from you!

Issues

๐Ÿ”€ Submit PRs

Code contributions
are always welcome!
Check our contributing guide

PRs

๐Ÿ’ป 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

Downloads Thank you for using our package!

๐ŸŒŸ Community

Contributors Amazing contributors making this better

๐Ÿ”„ Activity

Commits Actively maintained and improved


๐ŸŽŠ 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.

License

ยฉ 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

๐ŸŽ‰ Thank You for Using Django Create Initial User!

If this package helped you, please consider giving it a โญ star on GitHub!

Star History Chart


Made with โค๏ธ by developers, for developers

Happy coding! ๐Ÿš€

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_create_initial_user-1.2.3.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_create_initial_user-1.2.3-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file django_create_initial_user-1.2.3.tar.gz.

File metadata

File hashes

Hashes for django_create_initial_user-1.2.3.tar.gz
Algorithm Hash digest
SHA256 1c3f66c2ef948b357218f69c70ed335ba730acc8169ccdd7bbd940af57f695a3
MD5 e84ca1c704bd7549b1b9e7c802a02744
BLAKE2b-256 06d492e30255df07417f4c534b6d3154afddfacdee37ca7baf75545b11c61809

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_create_initial_user-1.2.3.tar.gz:

Publisher: publish.yml on rsp2k/django-create-initial-user

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_create_initial_user-1.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_create_initial_user-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 87d3b97e01da4d14b349bd0312b3d456391e184a67f38b2d4ae7b8e41a71b61f
MD5 662a5ca3ffae840b1b0a2c28c0036ed0
BLAKE2b-256 8954d6488879d6f7c2aa42bb8383cc9ba671b48f2e49ba8cfcad7c9db433b217

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_create_initial_user-1.2.3-py3-none-any.whl:

Publisher: publish.yml on rsp2k/django-create-initial-user

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page