Skip to main content

✨ python-magicmodels ✨

A blazingly fast CLI tool to instantly generate production-ready Django and FastAPI APIs from a simple schema.

License: MIT Python Versions Frameworks


🚀 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)
  • Int
  • Boolean
  • DateTime
  • uuid7 (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:

  1. Pagination: Endpoints are natively paginated.
  2. Dynamic Searching: Any field marked as a String or Text is automatically searchable via ?search=keyword.
  3. Sorting: All models support ascending/descending sorts out of the box via ?sort_by=field&order=desc.
  4. 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.

Metadata

Release files for python-magicmodels 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-magicmodels 0.3.0
File Size Uploaded Provenance Actions
python_magicmodels-0.3.0.tar.gz 19.6 kB Without provenance Details for python_magicmodels-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-magicmodels 0.3.0
File Interpreter ABI Platform Actions
python_magicmodels-0.3.0-py3-none-any.whl Python 3 none any Details for python_magicmodels-0.3.0-py3-none-any.whl

Total release size: 39.2 kB

Release files / python_magicmodels-0.3.0.tar.gz

Download URL python_magicmodels-0.3.0.tar.gz
Size 19.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4e1093f5a488108437adbd74774eba2698313e8469c0b7501184152fbeb385d9
BLAKE2b-256 checksum
How to use checksums
92edf1dfcebdee10e79d0d3fb49c862d5487596de5e9ec47636719b237e70535
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release files / python_magicmodels-0.3.0-py3-none-any.whl

Download URL python_magicmodels-0.3.0-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5af447b9076ed0acdae5ec6a9578e7f15aab05a190f24e59a6e20da72ade97df
BLAKE2b-256 checksum
How to use checksums
f495f436f5905d481db4d48a2af7386a9b070680b3cb91ce0e897f000ebd3fae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Security for python-magicmodels 0.3.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page