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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_magicmodels-0.3.0.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

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

python_magicmodels-0.3.0-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

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

Hashes for python_magicmodels-0.3.0.tar.gz
Algorithm Hash digest
SHA256 4e1093f5a488108437adbd74774eba2698313e8469c0b7501184152fbeb385d9
MD5 7d4f04be376eb5bac2ab02851f0b3717
BLAKE2b-256 92edf1dfcebdee10e79d0d3fb49c862d5487596de5e9ec47636719b237e70535

See more details on using hashes here.

File details

Details for the file python_magicmodels-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_magicmodels-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5af447b9076ed0acdae5ec6a9578e7f15aab05a190f24e59a6e20da72ade97df
MD5 5637eb992df3cf1d9de9a2349c9473a5
BLAKE2b-256 f495f436f5905d481db4d48a2af7386a9b070680b3cb91ce0e897f000ebd3fae

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page