Skip to main content

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: Config class 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.33

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fk_util_tools 0.1.33
File Size Uploaded
fk_util_tools-0.1.33.tar.gz 14.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fk_util_tools 0.1.33
File Interpreter ABI Platform
fk_util_tools-0.1.33-py3-none-any.whl Python 3 none any Details

Total release size: 43.8 kB

Release files / fk_util_tools-0.1.33.tar.gz

Download URL fk_util_tools-0.1.33.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4624b9a820ea479dfa17d844fde17215d4d3aa97401d0b090ff93c86453cee42
BLAKE2b-256 checksum
How to use checksums
f7944df1b6400ad2b23c585b7835e1585d2a029c3655fb2cee1ace9fd9343f7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.13.15 Linux/6.17.0-1022-azure

Release files / fk_util_tools-0.1.33-py3-none-any.whl

Download URL fk_util_tools-0.1.33-py3-none-any.whl
Size 29.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
39c1eddb3b9383d3f9fcb5da356ae3b0401521e3c45722c5426139ef6e2bcc2e
BLAKE2b-256 checksum
How to use checksums
0d5c05965e9174af563f62e5b91f385d8da43ff7a8a9114bf782f6e30a3ac67c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.13.15 Linux/6.17.0-1022-azure

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.33 This release

2 release files

0.1.30

2 release files

0.1.22

2 release files

0.1.21

2 release files

0.1.20

2 release files

0.1.19

2 release files

0.1.18

2 release files

0.1.17

2 release files

0.1.11

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page