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.
- 📄 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
ttldefined right in your config. - 🔌 Jinja2 SQL Templates: Write dynamic SQL queries using Jinja2 logic directly in your config.
pip install morph-api(Coming soon to PyPI. for now, clone and install locally)
git clone https://github.com/your-username/morph-api.git
cd morph-api
pip install -e .Create a folder structure like this:
my_app/
├── config/
│ ├── settings.yaml
│ └── routes/
│ └── users.yaml
└── main.py
app_name: "My Morph App"
database_url: "${DB_URL}" # Reads from environment variableendpoints:
- 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"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.pyVisit http://localhost:8000/docs to see your auto-generated Swagger UI!
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"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: falseCache expensive queries easily:
cache:
enabled: true
ttl: 300 # Cache for 5 minutesWe love contributions! Whether it's reporting bugs, suggesting features, or submitting PRs.
- Clone the repo
git clone https://github.com/your-username/morph-api.git
- Install Dev Dependencies
pip install -e ".[dev]" - Run Tests
pytest tests/
- Format Code
black morph_api/ tests/
- Support for MongoDB and NoSQL.
- GraphQL Support.
- Rate Limiting configuration.
- Custom authentication providers.
This project is licensed under the MIT License.