Metadata-Version: 2.1
Name: akmi-utils
Version: 0.1.5.1
Summary: 
Author: ekoi
Author-email: eko.indarto@dans.knaw.nl
Requires-Python: >=3.12,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: fastapi (>=0.115.7,<0.116.0)
Requires-Dist: httpx (>=0.28.1,<0.29.0)
Requires-Dist: opentelemetry-distro (>=0.50b0,<0.51)
Requires-Dist: opentelemetry-exporter-otlp (>=1.29.0,<2.0.0)
Requires-Dist: opentelemetry-instrumentation-fastapi (>=0.50b0,<0.51)
Requires-Dist: opentelemetry-instrumentation-logging (>=0.50b0,<0.51)
Requires-Dist: prometheus-client (>=0.21.1,<0.22.0)
Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
Requires-Dist: toml (>=0.10.2,<0.11.0)
Requires-Dist: uvicorn (>=0.34.0,<0.35.0)
Description-Content-Type: text/markdown

# 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

1. Clone the repository:
    ```sh
    git clone https://github.com/yourusername/akmi-utils.git
    cd akmi-utils
    ```

2. Install dependencies using Poetry:
    ```sh
    poetry install
    ```

## Usage

### Converting TOML to YAML

To use the `convert_toml_to_yaml` function, follow these steps:

1. Import the function in your script:
    ```python
    from akmi_utils.convert_toml_yaml import convert_toml_to_yaml
    ```

2. Call the function with the input TOML file path and output YAML file path:
    ```python
    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:

1. Import and add the middleware to your FastAPI app:
    ```python
    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`:

1. Import and configure OpenTelemetry in your FastAPI app:
    ```python
    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:
```sh
poetry run pytest
