Skip to content

MorphAPI is a config-first backend framework built on FastAPI that lets you generate fully functional APIs just by defining them in YAML.

Notifications You must be signed in to change notification settings

anand-mm/MorphAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 MorphAPI

No Boilerplate. Just Config. High Performance.

MorphAPI is a Config-Driven Python API Framework built on top of FastAPI and AsyncPG. It allows you to build secure, scalable, and high-performance APIs by simply defining your logic in YAML files.

Stop writing repetitive route handlers, Pydantic models, and database connectors. Just describe your API, and MorphAPI builds it for you.


✨ Features

  • 📄 Yaml-First Architecture: Define routes, SQL queries, and validation logic in clean YAML files.
  • ⚡ High Performance: Powered by FastAPI (ASGI) and AsyncPG (PostgreSQL) for blazing fast async execution.
  • 🔒 Secure by Default: Built-in SQL injection protection, automatic Pydantic validation, and JWT support.
  • 🧱 Auto-Validation: Request parameters (Path, Query, Body) are strictly validated against generated schemas.
  • 🧠 Smart Caching: Built-in support for Redis caching with ttl defined right in your config.
  • 🔌 Jinja2 SQL Templates: Write dynamic SQL queries using Jinja2 logic directly in your config.

📦 Installation

1. Install via pip

pip install morph-api

(Coming soon to PyPI. for now, clone and install locally)

2. Install from Source

git clone https://github.com/your-username/morph-api.git
cd morph-api
pip install -e .

🚀 Quick Start

1. Create your Configuration

Create a folder structure like this:

my_app/
├── config/
│   ├── settings.yaml
│   └── routes/
│       └── users.yaml
└── main.py

config/settings.yaml

app_name: "My Morph App"
database_url: "${DB_URL}"  # Reads from environment variable

config/routes/users.yaml

endpoints:
  - name: "get_user"
    path: "/users/{user_id}"
    method: "GET"
    action: "database_query"
    payload: "SELECT * FROM users WHERE id=:user_id"
    params:
      user_id:
        in: "path"
        type: "int"
        gt: 0
    response_schema:
      id: "int"
      username: "str"
      email: "str"

2. Run the Server

Create a main.py entry point:

import os
import uvicorn
from morph_api import MorphApp

# Initialize with the path to your config directory
app_instance = MorphApp(config_dir="config")

if __name__ == "__main__":
    uvicorn.run(app_instance.app, host="0.0.0.0", port=8000)

Run it:

export DB_URL="postgresql+asyncpg://user:pass@localhost/mydb"
python3 main.py

Visit http://localhost:8000/docs to see your auto-generated Swagger UI!


📖 Configuration Guide

Security & Validations

Define strict validation rules for your parameters:

params:
  age:
    in: "query"
    type: "int"
    gt: 18
    lt: 100
    description: "User age must be between 18 and 100"

Dynamic SQL with Jinja2

Make your SQL queries smarter:

payload: >
  SELECT * FROM products
  WHERE active = TRUE
  {% if category_id %}
    AND category_id = :category_id
  {% endif %}
params:
  category_id:
    in: "query"
    required: false

Caching (Redis)

Cache expensive queries easily:

cache:
  enabled: true
  ttl: 300  # Cache for 5 minutes

🤝 Contributing

We love contributions! Whether it's reporting bugs, suggesting features, or submitting PRs.

Development Setup

  1. Clone the repo
    git clone https://github.com/your-username/morph-api.git
  2. Install Dev Dependencies
    pip install -e ".[dev]"
  3. Run Tests
    pytest tests/
  4. Format Code
    black morph_api/ tests/

Roadmap

  • Support for MongoDB and NoSQL.
  • GraphQL Support.
  • Rate Limiting configuration.
  • Custom authentication providers.

📄 License

This project is licensed under the MIT License.

About

MorphAPI is a config-first backend framework built on FastAPI that lets you generate fully functional APIs just by defining them in YAML.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages