Metadata-Version: 2.1
Name: httpx-structlog
Version: 0.1.1
Summary: Сustom httpx client that logs all requests and responses with structlog.
Home-page: https://github.com/r-m-n/httpx-structlog
Keywords: httpx,structlog,logging
Author: Your Name
Author-email: you@example.com
Requires-Python: >=3.8,<4.0
Classifier: Programming Language :: Python :: 3
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 :: 3.13
Requires-Dist: httpx (>=0.27.0,<0.28.0)
Requires-Dist: structlog (>=24.2.0,<25.0.0)
Project-URL: Repository, https://github.com/r-m-n/httpx-structlog
Description-Content-Type: text/markdown

![PyPI - Version](https://img.shields.io/pypi/v/httpx-structlog)
![PyPI - Downloads](https://img.shields.io/pypi/dm/httpx-structlog)


# httpx-structlog

Сustom httpx client that logs all requests and responses with structlog.

## Installation

Install using `pip`:

```shell
$ pip install httpx-structlog
```

## Usage

```python
from httpx_structlog import AsyncLoggingClient, LoggingClient

# configure structlog
# structlog.configure(
#     processors=[structlog.processors.JSONRenderer(sort_keys=True, indent=4)]
# )

# Sync client
with LoggingClient() as client:
    client.get("https://httpbin.org/uuid")


# Async client
async with AsyncLoggingClient() as client:
    await client.get("https://httpbin.org/uuid")
```

## Log example

```json
{
    "duration": 0.49533109995536506,
    "event": "httpx request",
    "host": "httpbin.org",
    "method": "GET",
    "path": "/uuid",
    "request_body": "",
    "request_headers": {
        "accept": "*/*",
        "accept-encoding": "gzip, deflate",
        "connection": "keep-alive",
        "host": "httpbin.org",
        "user-agent": "python-httpx/0.27.0"
    },
    "request_query": "",
    "response_body": "{\n  \"uuid\": \"36a2c551-8632-4712-8b56-d3e21819c04e\"\n}\n",
    "response_headers": {
        "access-control-allow-credentials": "true",
        "access-control-allow-origin": "*",
        "connection": "keep-alive",
        "content-length": "53",
        "content-type": "application/json",
        "date": "Sat, 13 Jul 2024 12:22:17 GMT",
        "server": "gunicorn/19.9.0"
    },
    "response_status": 200
}
```

