No description
Infrastructure improvements synced from LayersFactory service APIs: Settings: - Add LokiSettings (LOKI_* env prefix) for Grafana Loki integration - Add SystemSettings (SYSTEM_* env prefix) with system user ID/name - Add SYSTEM_USER_ID and SYSTEM_USER_NAME to core consts - Add system and loki fields to AppSettings Logging: - Add LokiHandler with custom LokiEmitterV1 payload builder - Add EndpointFilter to suppress healthcheck/metrics noise - Add init_loki_handler helper - Add colorlog logger and httpx WARNING-level suppression to app_logger Docker: - Multi-stage Dockerfile with --mount=type=secret for private index auth - Add 4 build targets: webapi, worker, scheduler, migration - Add start_*.sh entry point scripts CI/CD: - development.yaml: add lint-imports step, Docker dev build with layer cache - build-and-publish.yaml: 4-target release with --secrets and registry cache Pre-commit: - Add import-linter hook Dependencies: - Add python-logging-loki>=0.3.1 Co-Authored-By: Paperclip <noreply@paperclip.ing> |
||
|---|---|---|
| .forgejo/workflows | ||
| docs | ||
| src | ||
| .env.example | ||
| .gitignore | ||
| .importlinter | ||
| .pre-commit-config.yaml | ||
| docker-compose.yaml | ||
| Dockerfile | ||
| LICENSE | ||
| logging-granian.json | ||
| mypy.ini | ||
| prometheus.yml | ||
| pyproject.toml | ||
| README.md | ||
| requirements-dev.txt | ||
| requirements.txt | ||
| start_migration.sh | ||
| start_scheduler.sh | ||
| start_webapi.sh | ||
| start_worker.sh | ||
| uv.lock | ||
Service Template
A design template for services with emphasis on asynchronous operations and database integration.
Features
- Asynchronous handling of HTTP requests (FastAPI).
- PostgreSQL database support (asyncpg, SQLModel)
- Job queues (Celery, RabbitMQ)
- Caching and rate limiting (Redis, slowapi)
- Configurable settings via
.envfile - Ready integration with database migration tools (Alembic)
- Extensive logging system (Rich, Granian)
- Application healthiness (healthchecks)
- Support for CORS, GZIP, HTTPS redirect, Trusted Hosts
Requirements
- Python 3.12+
- Docker (optional, to run in a container)
Installation
- Clone the repository:
sh git clone <address_repository> cd service-template - Install dependencies:
uv sync
3. Configure the `.env` file according to your needs.
## Run the application
Locally:
```sh
uv run manage-cli api serve
In Docker: ``sh docker build -t service-template . docker run -p 8000:8000 service-template
## Project structure
- `src/service_template/` - main application code
- `src/alembic/` - database migrations
- `tests/` - unit and integration tests
## management commands
All commands are available via CLI:
``sh
uv run manage-cli --help
```.
## Endpoints
- OpenAPI documentation: `/docs`.
- Redoc: `/redoc`
- Healthcheck: `/api/v1/health`.
## Author
Illia Bahlai - i.bahlai@3dcra.eu