✨ python-magicmodels ✨
A blazingly fast CLI tool to instantly generate production-ready Django and FastAPI APIs from a simple schema.
🚀 What is python-magicmodels?
python-magicmodels translates a single, human-readable .txt file into a full, scalable, Domain-Driven backend architecture.
It completely removes the boilerplate of setting up APIs by automatically generating:
- Models, Serializers/Schemas, & Routers isolated per domain.
- Pagination, Searching, & Sorting out-of-the-box.
- Security & Permissions templates built-in.
- Dockerization (
Dockerfile&docker-compose.yml) ready for deployment.
Whether you're spinning up an MVP or setting up microservices, python-magicmodels gives you a 100% working backend in seconds.
📦 Installation
Install globally via pip:
pip install python-magicmodels
⚡ How to Use
1. Define your Database Schema
Create a file named schema.txt. Use our intuitive schema syntax to define your data models and relationships.
Model: Author
- name (String)
- email (String) [indexed]
- bio (Text)
Model: Book
- title (String)
- published_date (DateTime)
- author (Author)
2. Generate the Magic!
Run the magicmodels command on your terminal. You can choose either --framework django or --framework fastapi.
Generate a Django REST Framework API:
magicmodels schema.txt --framework django --output ./my_django_api
Generate a FastAPI Project:
magicmodels schema.txt --framework fastapi --output ./my_fastapi_api
3. Spin it up!
The generated project is fully Dockerized. Navigate to your output directory and run Docker Compose:
cd my_django_api
docker-compose up --build
Your production-ready API is now live!
(For FastAPI, visit http://localhost:8000/docs to see your auto-generated Swagger UI!)
📖 Schema Syntax Guide
The parser is strict but extremely simple.
- Models: Declare a model with
Model: YourModelName. - Fields: Declare a field with
- field_name (Type) [Modifiers].
Supported Data Types
String(255 max length)Text(Unlimited length)IntBooleanDateTimeuuid7(Automatically generates UUID v7)
Supported Modifiers
Modifiers are optional tags you can add to the end of a field definition:
[pk]: Marks the field as a Custom Primary Key.[indexed]: Adds a database index for faster lookups.
Relationships
Relationships are detected automatically based on the type you provide!
- One-to-Many (ForeignKey): Simply put the target Model name in parentheses. E.g.,
- author (Author) - Many-to-Many: Wrap the target Model name in
list[]. E.g.,- tags (list[Tag])
Full Schema Example
Model: User
- id (Int) [pk]
- username (String) [indexed]
- is_active (Boolean)
Model: Post
- title (String)
- content (Text)
- author (User)
Model: Tag
- name (String) [indexed]
- posts (list[Post])
🛠️ Advanced Features Automatically Included
Regardless of which framework you choose, python-magicmodels embeds advanced API functionality:
- Pagination: Endpoints are natively paginated.
- Dynamic Searching: Any field marked as a
StringorTextis automatically searchable via?search=keyword. - Sorting: All models support ascending/descending sorts out of the box via
?sort_by=field&order=desc. - Permissions: Mutation endpoints (
POST,PATCH,DELETE) are scaffolded with authentication dependencies/permissions ready to be customized for your exact business logic.
🤝 Contributing
Contributions are always welcome! Feel free to open an issue or submit a Pull Request if you want to add support for a new framework or feature.
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 python_magicmodels-0.3.0.tar.gz.
File metadata
- Download URL: python_magicmodels-0.3.0.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e1093f5a488108437adbd74774eba2698313e8469c0b7501184152fbeb385d9
|
|
| MD5 |
7d4f04be376eb5bac2ab02851f0b3717
|
|
| BLAKE2b-256 |
92edf1dfcebdee10e79d0d3fb49c862d5487596de5e9ec47636719b237e70535
|
File details
Details for the file python_magicmodels-0.3.0-py3-none-any.whl.
File metadata
- Download URL: python_magicmodels-0.3.0-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5af447b9076ed0acdae5ec6a9578e7f15aab05a190f24e59a6e20da72ade97df
|
|
| MD5 |
5637eb992df3cf1d9de9a2349c9473a5
|
|
| BLAKE2b-256 |
f495f436f5905d481db4d48a2af7386a9b070680b3cb91ce0e897f000ebd3fae
|