|
1 | 1 | # python-response-time |
2 | | -Python-based response time module |
| 2 | + |
| 3 | +A Pythonic, DevOps-friendly HTTP benchmarking tool leveraging Pydantic v2 for robust configuration, Loguru for structured logging, and a modern, testable workflow. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Configurable HTTP benchmarking** via environment variables or `.env` file (Pydantic v2 + pydantic-settings) |
| 8 | +- **Structured logging** with Loguru (console and file, colorized, with rotation) |
| 9 | +- **Pre-flight DevOps checks**: auto-formatting, linting, and test coverage in one command |
| 10 | +- **Modern Python packaging**: `pyproject.toml`-based, ready for CI/CD |
| 11 | +- **Type-safe, validated settings**: all config is validated at startup |
| 12 | +- **Tested and type-checked**: includes pytest-based tests for all config |
| 13 | +- **CLI entrypoints** for both benchmarking and checks |
| 14 | + |
| 15 | +## Quickstart |
| 16 | + |
| 17 | +```bash |
| 18 | +# Install with all dev dependencies |
| 19 | +uv pip install -e '.[build]' |
| 20 | + |
| 21 | +# Run the HTTP benchmark |
| 22 | +uv run python-response-time |
| 23 | + |
| 24 | +# Run all pre-flight DevOps checks (format, lint, test) |
| 25 | +uv run checks |
| 26 | +``` |
| 27 | + |
| 28 | +## Configuration |
| 29 | + |
| 30 | +All settings are managed with Pydantic v2 and can be set via environment variables or a `.env` file: |
| 31 | + |
| 32 | +| Variable | Type | Default | Description | |
| 33 | +|---------------|--------|--------------------------|------------------------------------| |
| 34 | +| TARGET_URL | str | https://httpbin.org/get | Target endpoint for benchmarking | |
| 35 | +| NUM_REQUESTS | int | 10 | Total number of requests | |
| 36 | +| CONCURRENCY | int | 2 | Number of concurrent requests | |
| 37 | +| TIMEOUT | float | 10.0 | Request timeout (seconds) | |
| 38 | +| LOG_LEVEL | str | INFO | Log level (DEBUG, INFO, etc.) | |
| 39 | + |
| 40 | +Example `.env`: |
| 41 | + |
| 42 | +``` |
| 43 | +TARGET_URL=https://example.com/api |
| 44 | +NUM_REQUESTS=100 |
| 45 | +CONCURRENCY=5 |
| 46 | +TIMEOUT=5.0 |
| 47 | +LOG_LEVEL=DEBUG |
| 48 | +``` |
| 49 | + |
| 50 | +## DevOps & Pythonic Practices |
| 51 | + |
| 52 | +- **Pre-flight checks**: One command (`uv run checks`) runs ruff, isort, black, and pytest with coverage. |
| 53 | +- **Strict config validation**: Pydantic v2 ensures all settings are valid before running. |
| 54 | +- **Logging**: Loguru provides both human-friendly console logs and persistent file logs with rotation and compression. |
| 55 | +- **Modern packaging**: Uses `pyproject.toml` for dependencies, scripts, and tool config. |
| 56 | +- **CI/CD ready**: Semantic release and coverage tools are pre-configured. |
| 57 | +- **Type annotations**: All code is type-annotated for clarity and safety. |
| 58 | + |
| 59 | +## Project Structure |
| 60 | + |
| 61 | +``` |
| 62 | +src/python_response_time/ |
| 63 | + main.py # Benchmark runner |
| 64 | + pre_flight.py # DevOps checks |
| 65 | + core/ |
| 66 | + config.py # Pydantic v2 settings |
| 67 | + logging.py # Loguru setup |
| 68 | +tests/ |
| 69 | + test_basic.py # Pytest-based config tests |
| 70 | +``` |
| 71 | + |
| 72 | +## License |
| 73 | + |
| 74 | +MIT |
0 commit comments