Automatically generate DRF API components for Django apps
Project description
๐ 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 โญ
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_magicapi-0.1.1.tar.gz.
File metadata
- Download URL: django_magicapi-0.1.1.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48ea82301dfed9a031251addf52c173866b7f7fa081afe374996d7abfe621167
|
|
| MD5 |
840aa72d75d1fa372e62fbd28564952e
|
|
| BLAKE2b-256 |
3a29f8a19a0cfbe94da2091ce0fa8877420906acf822720e81a25c611ee229c4
|
File details
Details for the file django_magicapi-0.1.1-py3-none-any.whl.
File metadata
- Download URL: django_magicapi-0.1.1-py3-none-any.whl
- Upload date:
- Size: 20.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1893f28fb69cdb86f03b275c111a928d2fc49ae464139be43699743468bb7043
|
|
| MD5 |
8dbf1e2adeacb5f7ddf94023413d7327
|
|
| BLAKE2b-256 |
3e544c680aada52355cef68fb7786fbaea6be515ed081587eb8e526e9d8a5462
|