https://github.com/r-m-n/httpx-structlog
Сustom httpx client that logs all requests and responses with structlog
https://github.com/r-m-n/httpx-structlog
httpx logging structlog
Last synced: 4 months ago
JSON representation
Сustom httpx client that logs all requests and responses with structlog
- Host: GitHub
- URL: https://github.com/r-m-n/httpx-structlog
- Owner: r-m-n
- Created: 2024-07-13T12:31:33.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-12-13T16:47:19.000Z (5 months ago)
- Last Synced: 2025-01-20T20:53:15.317Z (4 months ago)
- Topics: httpx, logging, structlog
- Language: Python
- Homepage:
- Size: 32.2 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

# 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
}
```