A starting template for a Python API Server or Microservice using:
- FastAPI to create & document the API endpoints
- Uvicorn to serve the APIs
- Custom Python modules for business logic
- Dedicated folders for integrations (DBs, LLMs, etc.), models, services, and utils
- Docker, .env, and requirements.txt for easy local and Azure deployment
Please clone this template and modify it — then push to a different remote that is project-specific.
├── app
│ ├── main.py # Instantiate FastAPI, include routers, (optionally) CORS & startup tasks
│ ├── routes.py # API endpoints (routers) — with OPS Plans example stubs
│ └── __init__.py
├── config
│ ├── config.py # Optional runtime config loader (env + convenience accessors)
│ └── __init__.py
├── extensions # Example for framework extensions (placeholders)
│ ├── extension_example1.py
│ ├── extension_example2.py
│ ├── extension_example3.py
│ └── __init__.py
├── integrations # Outbound calls (DBs, LLMs, services). Stubs only.
│ ├── integration_example1.py
│ └── __init__.py
├── models # Pydantic models (request/response/domain). Stubs + examples.
│ ├── model_example1.py
│ ├── model_example2.py
│ ├── model_example3.py
│ ├── model_example4.py
│ └── __init__.py
├── services # Business logic grouped by feature area
│ ├── service_grouping_example1.py
│ ├── service_grouping_example2.py
│ └── __init__.py
├── tests # Unit tests (pytest). Placeholder.
│ ├── test_sample.py
│ └── __init__.py
├── utils # Shared helpers (e.g., logging, schedulers). Includes fake re-indexer.
│ ├── utility.py
│ ├── fake_reindexer.py
│ └── __init__.py
├── .env
├── .gitignore
├── Dockerfile
├── LICENSE
├── README.md
└── requirements.txt
-
Python 3.11 recommended. Create & activate a virtual env:
python -m venv .venv . .venv/bin/activate # Windows: .venv\Scripts\activate
-
Install deps:
pip install -r requirements.txt
-
Run dev server:
uvicorn app.main:app --reload
-
Open Swagger UI: http://127.0.0.1:8000/docs
Build and run with Docker:
docker build -t fastapi-template .
docker run --rm -p 8000:8000 --env-file .env fastapi-templateapp/routes.pyincludes example endpoints for the "OPS Plans Search and Create" concept, returning fake JSON.utils/fake_reindexer.pyincludes a fake timer-driven re-indexing job you can wire up on startup if desired.- It is disabled by default; see the commented lines in
app/main.pyto enable.
- It is disabled by default; see the commented lines in
- Replace example modules with your actual business logic, integrations, and data models.