π Python microservice template built with:
uv:
brew install uvClone the repository:
git clone https://github.com/remarkablemark/python-microservice-template.git
cd python-microservice-templateInstall the dependencies:
uv syncThe microservice supports optional bearer token authentication.
Copy the example environment file:
cp .env.example .envEdit .env and set your bearer tokens:
# Single token
API_KEYS=your-secret-key-here
# Multiple tokens (comma-separated)
API_KEYS=key-1,key-2,key-3Protected endpoints require an Authorization header with a bearer token:
curl -H "Authorization: Bearer your-secret-key-here" \
http://127.0.0.1:8000/protected/When authentication is enabled, the /protected endpoints will be available at:
GET /protected/- Basic protected endpointGET /protected/data- Protected endpoint with data
The microservice supports optional database integration using SQLModel and Alembic.
Copy the example environment file and configure your database:
cp .env.example .envEdit .env and set your database URL:
# For SQLite (Development)
DATABASE_URL=sqlite:///./app.db
# For PostgreSQL (Production)
# DATABASE_URL=postgresql://user:password@localhost:5432/dbnameCreate a new migration after modifying models:
uv run alembic revision --autogenerate -m "description"Apply migrations:
uv run alembic upgrade headRollback migration:
uv run alembic downgrade -1In the project directory, you can run:
Installs the pre-commit script.
Runs the app in development mode:
- Server: http://127.0.0.1:8000
- Documentation: http://127.0.0.1:8000/docs
- OpenAPI: http://127.0.0.1:8000/openapi.json
The server will reload if you make edits.
Alternatively, run with uvicorn directly:
uv run uvicorn app.main:app --reloadRuns the app in production mode.
Alternatively, run with uvicorn directly:
uv run uvicorn app.main:app --host 0.0.0.0 --port 8000Formats the code (replaces Black).
Lints the code and checks import sorting (replaces isort).
Auto-fixes linting issues and sorts imports.
Runs tests with coverage reporting (fails if coverage is below 100%).
Creates a new database migration.
Applies all pending database migrations.