A powerful and configurable API stress testing tool built with Python, using HTTPX for efficient concurrent requests. This tool helps you evaluate API performance, reliability, and behavior under load by simulating multiple concurrent requests.
- Concurrent request execution using async/await
- Detailed request/response logging in JSONLINEs format
- Configurable request parameters (headers, query params, etc.)
- Connection pooling and timeout management
- Support for different HTTP methods
- Comprehensive metrics collection (response time, status codes, etc.)
- Python 3.13 or higher
- Poetry (Python package manager)
curl -sSL https://install.python-poetry.org | python3 -
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -
After installation, make sure to add Poetry to your system's PATH:
- Windows:
%APPDATA%\Python\Scripts
- macOS/Linux:
$HOME/.local/bin
- Clone the repository:
git clone https://github.com/cs4alhaider/api-stress-testing-tool
cd api-stress-testing-tool
- Install dependencies using Poetry:
poetry install
- Activate the virtual environment:
poetry shell
from main import run_stress_test
run_stress_test(
url="https://api.example.com/endpoint",
total_requests=100,
concurrent_requests=10
)
config = {
"total_requests": 100,
"concurrent_requests": 10,
"headers": {
"Authorization": "Bearer your-token",
"Accept": "application/json"
},
"params": {
"page": 1,
"limit": 10
},
"method": "POST",
"log_file": "logs/custom_test.jsonl",
"timeout": 30.0
}
run_stress_test(
url="https://api.example.com/endpoint",
**config
)
Parameter | Description | Default |
---|---|---|
url |
Target API endpoint URL | Required |
total_requests |
Total number of requests to make | 100 |
concurrent_requests |
Number of concurrent requests | 10 |
headers |
HTTP headers for requests | None |
params |
Query parameters for requests | None |
method |
HTTP method (GET, POST, etc.) | "GET" |
log_file |
Path to log file | "api_stress_test.jsonl" |
timeout |
Request timeout in seconds | 60.0 |
The tool generates a JSONL (JSON Lines) file containing detailed information about each request:
{
"request_id": 1,
"timestamp": "2024-01-01T12:00:00.000000",
"url": "https://api.example.com/endpoint",
"method": "GET",
"headers": {},
"params": {},
"status_code": 200,
"response_time_ms": 150.45,
"success": true,
"response_headers": {},
"content_length": 1234,
"response_body": {}
}
.
├── main.py # Main implementation
├── pyproject.toml # Poetry configuration and dependencies
├── README.md # Documentation
└── logs/ # Directory for log files
└── api_stress_test.jsonl
poetry run pytest
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.