Python FastAPI Microservice
Production-ready Python REST API starter with structured routing, data validation models, health checks, and clean service architecture.
"""FastAPI Microservice Entrypoint."""
from routes import register_routes
class AppServer:
def __init__(self, title: str, version: str = "1.0.0"):
self.title = title
self.version = version
self.routes = {}
def route(self, path: str, method: str = "GET"):
def decorator(fn):
self.routes[(method.upper(), path)] = fn
return fn
return decorator
app = AppServer(title="WorkMA Service API", version="1.0.0")
register_routes(app)
if __name__ == "__main__":
print(f"Starting {app.title} v{app.version} with {len(app.routes)} routes...")
"""Domain data models and payload validators."""
from dataclasses import dataclass, field
from typing import List, Optional
@dataclass
class TaskItem:
id: int
title: str
status: str = "todo"
priority: str = "medium"
tags: List[str] = field(default_factory=list)
def to_dict(self) -> dict:
return {
"id": self.id,
"title": self.title,
"status": self.status,
"priority": self.priority,
"tags": self.tags,
}
"""API route handlers."""
from models import TaskItem
SAMPLE_TASKS = [
TaskItem(id=1, title="Configure API Gateway", status="completed", priority="high", tags=["infra"]),
TaskItem(id=2, title="Implement OAuth2 Token Guard", status="in_progress", priority="high", tags=["security"]),
]
def register_routes(app):
@app.route("/health", method="GET")
def health_check():
return {"status": "healthy", "service": app.title}
@app.route("/api/v1/tasks", method="GET")
def list_tasks():
return {"count": len(SAMPLE_TASKS), "items": [t.to_dict() for t in SAMPLE_TASKS]}
# Python FastAPI Microservice Starter A clean, modular Python API project template for **WorkMA Code Nexus**. ## Project Structure - `main.py` — Application server initialization - `models.py` — Typed domain dataclasses & serializers - `routes.py` — Endpoint handlers and health check
How to Customize Inside WorkMA
Runtime: Python 3.12 + WorkMA Code Runner / Virtualenv
- Open the template directly inside WorkMA Code Nexus or fork it inside your workspace gallery.
- Configure any API tokens in the project's Encrypted Secrets Vault.
- Edit code in the browser Monaco editor with real-time file locking and 3-way merge safety.
- Sync upstream to GitHub with Sentinel regex + AI PR checks enabled.
DLP & Secrets Vault Readiness
All database URIs, JWT secrets, and third-party API keys should live inside WorkMA Encrypted Secrets Vault and inject strictly at runtime rather than committing plaintext .env configs.
More Code Nexus Starter Templates
Full-Stack SaaS Module Blueprint
Multi-layer blueprint with backend service controller, frontend view template, and JSON schema contract.
htmlInteractive Web Dashboard (HTML5 + CSS + JS)
Responsive modern frontend application with interactive KPI cards, live search filter, dark-mode styling, and clean vanilla JavaScript controller.
javascriptNode.js REST API & Webhook Worker
Lightweight JavaScript backend service template with router middleware, webhook signature verifier, and JSON configuration.