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

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.2.0.tar.gz (18.8 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.2.0-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file python_magicmodels-0.2.0.tar.gz.

File metadata

  • Download URL: python_magicmodels-0.2.0.tar.gz
  • Upload date:
  • Size: 18.8 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.2.0.tar.gz
Algorithm Hash digest
SHA256 02b411365a9710fdfb36b8c8cdf9e72d83958cb3f75e67df3e10e8e552dbdbaa
MD5 65da3bf919bfc3f2e664adca2cc7fbfc
BLAKE2b-256 6837238ab94e2ccdca95753c220d7e4a53c891ce79c6ab624c5441a33bb7014b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_magicmodels-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab9e59e0c18d1d8a901f70b4262a76a682c218a15513a808ab1783688fe1857f
MD5 e9b136724435082e85be7fb29dddd1e0
BLAKE2b-256 bdfc8f68621186146adae61799bfb6da35059e396a4aeac7f8528c7330b097f8

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.0

2 files

This release

0.2.0 This release

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