fk-util-tools
Utility tools and shared functions for FK projects: centralized configuration, logging, middlewares, AWS integration, and OpenTelemetry tracing for Python web frameworks.
Installation
pip install fk-util-tools
Main Features
- Centralized Configuration:
Configclass for global settings management. - Cache: Redis integration.
- Environment Variables & AWS: Access to AWS Parameter Store and Secrets Manager.
- Custom Exceptions: HTTP error handling with custom codes.
- Structured Logging: Logging for FastAPI and other frameworks.
- Middlewares: SQL Printer, error handling, internationalization, and language support for Flask, Django, and FastAPI.
- OpenTelemetry Tracing: Instrumentation for Flask, Django, FastAPI, and AWS Lambda.
- Type Hints: PEP 561 support.
Usage Examples
Configuration
from fk_utils import SETTINGS
print(SETTINGS.ENV)
Structured Logging in FastAPI
from fastapi import FastAPI
from fk_utils.logging.fastapi.logging import setup_logging
app = FastAPI()
setup_logging(app)
SQL Printer Middleware
Flask
from flask import Flask
from fk_utils.middlewares.flask.sql_middleware import SqlPrintingMiddleware
app = Flask(__name__)
app.config['DEBUG'] = True
SqlPrintingMiddleware(app)
Django
from fk_utils.middlewares.django.sql_middleware import SqlPrintingMiddleware
SqlPrintingMiddleware()
FastAPI
from fk_utils.middlewares.fastapi.sql_middleware import SqlPrintingMiddleware
app = FastAPI()
SqlPrintingMiddleware(app)
OpenTelemetry Instrumentation
from fk_utils.traces.opentelemetry.fastapi.trace import instrument_app
app = FastAPI()
instrument_app(app)
AWS Lambda Instrumentation
from fk_utils.traces.opentelemetry.fastapi.aws_lambda.trace import instrument_app
app = FastAPI()
is_lambda = instrument_app(app, instrument_lambda=True)
print("Lambda instrumented:", is_lambda)
Health check endpoint
fk_utils.health expone un /health estandarizado para Django, FastAPI y Flask:
from fk_utils.health.django import DjangoHealthCheck
from fk_utils.health import DjangoPostgreSQLCheck, MongoDBCheck
health = DjangoHealthCheck(
environment=settings.ENV,
country="CO",
version=settings.VERSION,
checks=[DjangoPostgreSQLCheck(), MongoDBCheck(mongo_client)],
)
urlpatterns = [path("health", health.view)]
Respuesta: {"status": "healthy|unhealthy", "environment", "country", "version", "databases": {"postgresql": "healthy", "mongodb": "unhealthy: ..."}}.
Los checks corren en paralelo y la respuesta está acotada en tiempo (2 s por defecto). Si una
dependencia se cuelga (p. ej. pymongo reintentando autenticación durante 20 s), el check se reporta
como unhealthy: timeout after 2s y el endpoint igual responde: los probes de Kubernetes y el
blackbox de monitoreo nunca ven un timeout HTTP por culpa de una dependencia. El presupuesto se
ajusta con el parámetro timeout= o la variable FK_HEALTH_CHECK_TIMEOUT; timeout=0 vuelve al
comportamiento secuencial sin límite.
Checks propios: subclasear fk_utils.health.base.HealthCheck (ver docstring).
License
MIT
Metadata
Release files for fk_util_tools 0.1.34
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fk_util_tools-0.1.34.tar.gz | 14.7 kB | Without provenance | Details for fk_util_tools-0.1.34.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fk_util_tools-0.1.34-py3-none-any.whl | Python 3 | none | any | Details for fk_util_tools-0.1.34-py3-none-any.whl |
Total release size: 43.8 kB
Release files / fk_util_tools-0.1.34.tar.gz
| Download URL | fk_util_tools-0.1.34.tar.gz |
|---|---|
| Size | 14.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ccfcf99be7257ded7ddd92a9492d64307a920a750fac8191fc469e3a48cf4722
|
|
BLAKE2b-256 checksum How to use checksums |
e5be633a7849b43a68ebd8955dc06d514d65608fcbfeb9db79ed77f344da5494
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.5.1 CPython/3.13.17 Linux/7.0.0-1017-azure
|
Release files / fk_util_tools-0.1.34-py3-none-any.whl
| Download URL | fk_util_tools-0.1.34-py3-none-any.whl |
|---|---|
| Size | 29.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5fb716247e449be1889b9325ae647babd6a4d4f7a5355c2bc731817000557434
|
|
BLAKE2b-256 checksum How to use checksums |
a1bc264f17b8c12f564cd8c6b45864f4cabe2af7cf597dc67176f027ef4ffea7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.5.1 CPython/3.13.17 Linux/7.0.0-1017-azure
|
Security for fk_util_tools 0.1.34
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.