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.31

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.31
File Size Uploaded
fk_util_tools-0.1.31.tar.gz 14.7 kB Details

Built distribution (wheel)

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

Total release size: 43.8 kB

Release files / fk_util_tools-0.1.31.tar.gz

Download URL fk_util_tools-0.1.31.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8ec01e9d8ed9639fca77eb30369685f549c45efb62afb5e0f17bbfd86ff8f716
BLAKE2b-256 checksum
How to use checksums
e3e521d52ce2086a5322fefcfb27869619cce7b85339bd96ceca83d7604503b9
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.31-py3-none-any.whl

Download URL fk_util_tools-0.1.31-py3-none-any.whl
Size 29.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6d891217a10245b54e161bab75b64756bd287274f8dbe4c9a71c0d66cb27844f
BLAKE2b-256 checksum
How to use checksums
d90ddcf038b98e9f7df9e868ba517da04b4de12c673d75679779cff0fb275aec
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.31 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