Metadata-Version: 2.3
Name: httpx-metrics
Version: 0.0.1
Project-URL: Issues, https://github.com/Karen Petrosyan/httpx-metrics/issues
Project-URL: Source, https://github.com/Karen Petrosyan/httpx-metrics
Author-email: Karen Petrosyan <kar.petrosyanpy@gmail.com>
License-Expression: MIT
License-File: LICENSE.txt
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.8
Requires-Dist: prometheus-client
Provides-Extra: hishel
Requires-Dist: hishel<0.1,>=0.0.29; extra == 'hishel'
Description-Content-Type: text/markdown

# httpx-metrics

httpx-metrics is a utility library that offers classes for integrating metrics into your httpx client (currently, it supports only Prometheus metrics).

[![PyPI - Version](https://img.shields.io/pypi/v/httpx-observer.svg)](https://pypi.org/project/httpx-observer)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/httpx-observer.svg)](https://pypi.org/project/httpx-observer)

-----

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [Supported metrics](#supported-metrics)

## Installation

```console
pip install httpx-metrics
```

## Usage

```python
import httpx
import anyio
from httpx_metrics.async_metrics import (
    AsyncDownloadDurationMetric,
    AsyncProcessingRequestsMetric,
    AsyncRequestsDurationMetric,
    AsyncTotalRequestsMetric,
)
from httpx_metrics import AsyncPrometheusTransport

metrics_transport = AsyncPrometheusTransport(
    next_transport=httpx.AsyncHTTPTransport(),
    metrics=[
        AsyncRequestsDurationMetric(),
        AsyncTotalRequestsMetric(),
        AsyncProcessingRequestsMetric(),
        AsyncDownloadDurationMetric(),
    ],
    exporter_port=8000,
)


async def main():
    async with httpx.AsyncClient(transport=metrics_transport) as client:
        while True:
            response = await client.get("https://www.encode.io")
            await anyio.sleep(5)


anyio.run(main)
```

## Supported metrics

- **AsyncTotalRequestsMetric** / **TotalRequestsMetric**
    
    **Type**: Counter

    **Description**: Total number of requests

    **Labels**
    
    - method
    - status_code
    - path
    - version

- **AsyncRequestsDurationMetric** / **RequestsDurationMetric**

    **Type**: Histogram

    **Description**: Request duration in seconds

    **Labels**

    - method
    - status_code
    - path
    - version

- **AsyncProcessingRequestsMetric** / **ProcessingRequestsMetric**

    **Type**: Gauge

    **Description**: Number of requests in fly

    **Labels**

    - method
    - path

- **AsyncDownloadDurationMetric** / **DownloadDurationMetric**

    **Type**: Histogram

    **Description**: Response body downloading duration in seconds

    **Labels**

    - method
    - status_code
    - path
    - version

- **AsyncCachedRequestsMetric** / **CachedRequestsMetric**

    **Note**: This metric should be used on top of [hishel](hishel.com) transports

    **Type**: Counter

    **Description**: Total number of cached requests

    **Labels**

    - method
    - status_code
    - path
    - version
    - revalidated