Utilities for AKMI integration and instrumentation (FastAPI helpers with OpenTelemetry and Prometheus support).
Project description
akmi-utils
A utility package for various functionalities including converting TOML files to YAML format, logging, and OpenTelemetry integration.
Prerequisites
- Python 3.12 or higher
- Poetry
Installation
-
Clone the repository:
git clone https://github.com/yourusername/akmi-utils.git cd akmi-utils
-
Install dependencies using Poetry:
poetry install
Usage
Converting TOML to YAML
To use the convert_toml_to_yaml function, follow these steps:
-
Import the function in your script:
from akmi_utils.convert_toml_yaml import convert_toml_to_yaml
-
Call the function with the input TOML file path and output YAML file path:
convert_toml_to_yaml('path/to/input.toml', 'path/to/output.yaml')
Logging Requests
To log requests in a FastAPI application, use the log_requests middleware:
- Import and add the middleware to your FastAPI app:
from akmi_utils.logging import log_requests app = FastAPI() app.middleware('http')(log_requests)
OpenTelemetry Integration
To set up OpenTelemetry with FastAPI, use the setting_otlp function and PrometheusMiddleware:
- Import and configure OpenTelemetry in your FastAPI app:
from akmi_utils.otel import setting_otlp, PrometheusMiddleware, metrics app = FastAPI() setting_otlp(app, app_name='your_app_name', endpoint='your_otlp_endpoint') app.add_middleware(PrometheusMiddleware, app_name='your_app_name') app.add_route('/metrics', metrics)
Running Tests
To run the tests, use the following command:
poetry run pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file akmi_utils-0.1.8.tar.gz.
File metadata
- Download URL: akmi_utils-0.1.8.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.31
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17f3a811e3c125d8401586ab674ca99fb8d8a4ad373df6dbde7fa9e69841a8f0
|
|
| MD5 |
29188fbc2c219153b3ce5bf188a57e75
|
|
| BLAKE2b-256 |
504c7b8f83df357acb3b6bb362f315fa4d10bdc2ccbc46e7096b1d4f9cec0046
|
File details
Details for the file akmi_utils-0.1.8-py3-none-any.whl.
File metadata
- Download URL: akmi_utils-0.1.8-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.31
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa13e3b488351a9fdd926a2b3b5088c636b9221e947ae289189b4c84a42e4693
|
|
| MD5 |
e4169e8d2ea4fa4ee703942dfc945156
|
|
| BLAKE2b-256 |
1df7b6588f060c54298669c3d63d5e4840017f0d6ebdb61f6b3f3fe2c085d2ed
|