Skip to main content

Django REST Framework Boilerplate Generator

Project description

drfbp

drfbp (Django REST Framework Boilerplate) is a Django app designed to streamline the development of REST APIs using Django and Django REST Framework. It provides powerful management commands to automate repetitive setup tasks, allowing developers to focus on core logic rather than boilerplate code.

⚡ Speed up your development.
🧱 Build smarter, not harder.
🧰 One toolbox, many commands.

✨ Features

  • Command-based Interface: Easily extendable via Django management commands.
  • 🔧 Boilerplate Generation: Quickly generate views, serializers, permissions, and URL configurations for your API.
  • ⚙️ Automated Formatting: Integrates with black and isort for consistent code style out of the box.
  • 🧩 DRF-Ready: Specifically designed for seamless integration with Django REST Framework.
  • 💼 Project-Friendly Output: Generates clean, modular code that fits well into real-world project structures.
  • 🔒 Secure Settings: Provides a management command to set up secure Django settings, including JWT authentication, CORS, and database configurations.
  • 📄 API Documentation: Automatically configures drf-spectacular for OpenAPI schema generation and Swagger UI documentation.

📦 Installation

Install from PyPI:

pip install drfbp

Or install locally for development:

pip install -e .

⚙️ Setup

To enable the included management commands, add drfbp to your Django project's INSTALLED_APPS:

# settings.py

INSTALLED_APPS = [
    # ...
    "drfbp",
]

🛠 Available Commands

📌 crud — Generate REST API boilerplate for a Django model

This command scaffolds the full API structure for any registered Django model, including views, serializers, permissions, and URL routes.

🔄 Usage

python manage.py crud <app> <model> <path>
  • app: The Django app label containing the model (e.g., blog).
  • model: The name of the model class (e.g., Post).
  • path: The output directory for the generated API files (e.g., api/blog/post).

💡 Example

python manage.py crud blog post api/blog/post

This command generates the following files:

  • api/blog/post/serializers.py: A DRF ModelSerializer for the specified model.
  • api/blog/post/views.py: A DRF ModelViewSet for handling CRUD operations.
  • api/blog/post/permissions.py: A customizable BasePermission class.
  • api/blog/post/urls.py: A router-based URL configuration for the API endpoint.

All generated files are import-ready and automatically formatted with isort and black.

📌 settings — Configure Django project settings and URL patterns

This command automates the setup of essential Django settings and URL configurations, including security, authentication, and API documentation.

🔄 Usage

python manage.py settings

💡 What it does:

  • Updates settings.py:
    • Configures SECRET_KEY, DEBUG, ALLOWED_HOSTS, CORS_ALLOWED_ORIGINS from environment variables.
    • Sets up security headers (SECURE_HSTS_SECONDS, SECURE_HSTS_INCLUDE_SUBDOMAINS, SECURE_SSL_REDIRECT, SESSION_COOKIE_SECURE, CSRF_COOKIE_SECURE).
    • Adds drfbp, rest_framework, rest_framework_simplejwt, rest_framework_simplejwt.token_blacklist, corsheaders, and drf_spectacular to INSTALLED_APPS.
    • Configures REST_FRAMEWORK defaults for authentication (JWT), permissions (IsAuthenticated), renderers (JSON), parsers (JSON), and schema class (drf_spectacular).
    • Sets up SIMPLE_JWT with token lifetimes, rotation, and blacklisting.
    • Configures SPECTACULAR_SETTINGS for API documentation title, description, and version.
    • Adds necessary middleware, including SecurityMiddleware, WhiteNoiseMiddleware, CorsMiddleware, and others.
    • Configures database settings for PostgreSQL using environment variables.
    • Sets up email backend settings from environment variables.
  • Updates urls.py:
    • Includes drf-spectacular URLs for API schema (/schema/) and Swagger UI documentation (/docs/).
    • Provides a placeholder for your API's root URL path.

🔧 Requirements

  • Python 3.7+
  • Django 3.2+
  • Django REST Framework
  • djangorestframework-simplejwt
  • django-cors-headers
  • drf-spectacular
  • whitenoise (for static files in production)
  • psycopg2-binary (for PostgreSQL database)

🤝 Contributing

New command ideas, bug fixes, or improvements are always welcome.

  1. Fork the repository.
  2. Create a feature branch.
  3. Submit a pull request.

Please follow Django and Python community conventions.

🪪 License

MIT License. See LICENSE.txt for more details.

💡 Inspiration

Born from the need to automate boilerplate in production projects, drfbp aims to give Django developers more time for logic, less time spent on setup.

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

drfbp-25.6.21.432.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

drfbp-25.6.21.432-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file drfbp-25.6.21.432.tar.gz.

File metadata

  • Download URL: drfbp-25.6.21.432.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for drfbp-25.6.21.432.tar.gz
Algorithm Hash digest
SHA256 8f01c0acd2fbd1394cbc2aefdb7a514389bbe3254f183d2cf2465cae032b7454
MD5 01dca68460a7526f6cf755e55a15682c
BLAKE2b-256 08ad604d31186fa576e87f231b8dac136f8f743e12cd46f7a321b3b3f2780c9a

See more details on using hashes here.

File details

Details for the file drfbp-25.6.21.432-py3-none-any.whl.

File metadata

  • Download URL: drfbp-25.6.21.432-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for drfbp-25.6.21.432-py3-none-any.whl
Algorithm Hash digest
SHA256 6526a847d8e403cf148d1fc357e3f7c49a47628d9f8bfc02ff987b6c206261ee
MD5 032e617fe01fb726831e6fac2f406c7d
BLAKE2b-256 74195fd7939b0a0573b4963089e826ee321a5d5d89d55e2d6a6b776963f3f708

See more details on using hashes here.

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