🚀 django-magicapi
Automatically generate production-ready Django REST Framework APIs with zero boilerplate.
django-magicapi helps you instantly generate CRUD APIs for your Django models without manually writing serializers, viewsets, routers, pagination logic, or permissions.
✨ Why django-magicapi?
Building APIs in Django REST Framework usually requires repetitive setup:
- Writing serializers
- Creating viewsets
- Registering routers
- Configuring pagination
- Setting permissions
- Adding Swagger docs
- Registering models in admin
This package automates all of that with one command.
python manage.py magicapi --app blog
And you're done.
📌 Features
✅ Auto-generates full CRUD APIs
✅ Creates serializers automatically
✅ Creates viewsets automatically
✅ Generates routers automatically
✅ Supports API versioning (/api/v1/)
✅ Swagger UI support
✅ ReDoc support
✅ Automatic Django admin registration
✅ Hybrid pagination support
✅ Safe regeneration (won’t overwrite custom code unless forced)
✅ Cleanup command for generated files
📦 Installation
Install the package:
pip install django-magicapi
Add it to INSTALLED_APPS:
INSTALLED_APPS = [
...
"django_magicapi",
]
Optional Swagger Support
For API documentation UI:
pip install drf-yasg
Then add:
INSTALLED_APPS = [
...
"drf_yasg",
]
⚡ Quick Start
Step 1: Create models
Example:
from django.db import models
class Category(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class Post(models.Model):
title = models.CharField(max_length=200)
content = models.TextField()
category = models.ForeignKey(Category, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
Step 2: Run migrations
python manage.py makemigrations
python manage.py migrate
Step 3: Generate APIs
python manage.py magicapi --app blog
Step 4: Run server
python manage.py runserver
🌐 Generated Endpoints
After running the command:
API Root
http://127.0.0.1:8000/api/v1/
Swagger UI
http://127.0.0.1:8000/swagger/
ReDoc
http://127.0.0.1:8000/redoc/
🧠 Available Commands
| Command | Description |
|---|---|
magicapi --app yourapp |
Generate API for an app |
magicapi --app yourapp --clean |
Remove generated files |
magicapi --app yourapp --clean --force |
Force remove generated files |
magicapi --app app1 app2 |
Generate APIs for multiple apps |
📁 Generated Project Structure
yourapp/
│
├── models.py
├── admin.py
│
├── utilities/
│ ├── permissions.py
│ ├── pagination.py
│ └── importbase.py
│
├── serializers/
│ ├── __init__.py
│ └── post_serializers.py
│
├── viewsets/
│ ├── __init__.py
│ └── post_viewsets.py
│
└── routers/
└── routers.py
🔐 Permissions
Modify:
utilities/permissions.py
Use this file to:
- Add owner-based permissions
- Add role-based permissions
- Integrate Django default permissions
- Create custom access logic
📄 Pagination
Modify:
utilities/pagination.py
Supports:
- Page number pagination
- Limit/offset pagination
- Custom page sizes
🔧 Customizing Generated Code
Each generated file is independent.
You can safely customize:
- Serializers
- Viewsets
- Routers
- Permissions
- Pagination
Your custom code won’t be overwritten unless you explicitly force it.
🧹 Cleanup Generated Files
Remove generated files:
python manage.py magicapi --app blog --clean
Force cleanup:
python manage.py magicapi --app blog --clean --force
🛠 Tech Stack
Built with:
- Django
- Django REST Framework
- drf-yasg
- django-filter
🤝 Contributing
Contributions are welcome.
You can help by:
- Reporting bugs
- Suggesting features
- Improving documentation
- Submitting pull requests
📜 License
This project is licensed under the MIT License
👨💻 Maintainer
Prashant Karna
📧 prashantkarna21@gmail.com
⭐ Support
If this project helped you, consider giving it a GitHub star ⭐
Metadata
Release files for django-magicapi 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_magicapi-0.2.1.tar.gz | 15.7 kB | Without provenance | Details for django_magicapi-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_magicapi-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for django_magicapi-0.2.1-py3-none-any.whl |
Total release size: 33.3 kB
Release files / django_magicapi-0.2.1.tar.gz
| Download URL | django_magicapi-0.2.1.tar.gz |
|---|---|
| Size | 15.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ecb01828e01361e34e20d101c631a7285d1a989307bb1944cba17b8ddc8fbaf1
|
|
BLAKE2b-256 checksum How to use checksums |
a24b3d563fad5f9374716f950b572e8aca27a637509ace8488c572f8c66f9a10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Release files / django_magicapi-0.2.1-py3-none-any.whl
| Download URL | django_magicapi-0.2.1-py3-none-any.whl |
|---|---|
| Size | 17.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b2bd9dffea02f65b06c9d590972a5cc9eb26cdb99b023ac6740186fa12cf640c
|
|
BLAKE2b-256 checksum How to use checksums |
ac111ae232aef540fe756e4f12dfb86f751e44eb8c5cdf50658af89add56452a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Security for django-magicapi 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.