A command-line tool for checking URL connectivity, with support for both synchronous and asynchronous request methods.
This tool was built to contrast two fundamental approaches to network I/O in Python:
- Synchronous (Default): A sequential, blocking method using the standard
http.clientlibrary. - Asynchronous: A high-performance, concurrent method using
aiohttpandasynciofor efficiently checking large URL lists.
- Dual-Mode Operation: Supports both synchronous (blocking) and asynchronous (non-blocking) request modes.
- Flexible Input: Accepts URLs from command-line arguments (
-u) or a newline-delimited file (-f). - Robust URL Parsing: Automatically prepends
http://to non-qualified domains (e.g.,google.com) usingurllib.parse. - Clear Status Output: Reports a simple status (OK, ERROR, or DOWN) for each URL.
- Configurable Timeout: Uses a global timeout for all requests.
This project intentionally includes two different implementations to demonstrate and compare I/O handling.
- Implementation: Uses the standard
http.clientlibrary. Requests are executed sequentially. The script blocks and waits for each request to complete (or time out) before starting the next. - Use Case: Simple, reliable, and requires no external dependencies. Suitable for small batches of URLs or when simplicity is paramount.
- Limitation: Highly inefficient for large lists. The total execution time is the sum of all individual response times.
- Implementation: Uses
aiohttpand theasyncioevent loop. All requests are initiated concurrently. The event loop manages the I/O, allowing the script to handle many "waiting" states simultaneously without blocking the main thread. - Use Case: High-performance. Ideal for checking hundreds or thousands of URLs. The total execution time is approximately the time of the single slowest responding URL.
- Limitation: Requires an external library (
aiohttp) and a more complex (but powerful)async/awaitcode structure.
-
Clone the repository:
git clone https://github.com/gouomar/check_connectivity cd <your-project-name>
-
install requirements: This project requires
aiohttp.install the dependencies (preferably in a virtual environment):
pip install aiohttp
All options can be viewed with the -h flag.
python check_connectivity.py -husage: check_connectivity.py [-h] [-u URLS [URLS ...]] [-f FILE_NAME] [-a]
Check connectivity for URLs (sync by default, async with -a/--async).
options:
-h, --help show this help message and exit
-u, --urls URLS [URLS ...]
One or more URLs to check
-f, --file FILE_NAME File containing one URL per line
-a, --async Use asynchronous requests with aiohttp
This project serves as a practical application of several key Python concepts:
- CLI Implementation: Building a complete command-line interface using the
argparsestandard library. - HTTP/HTTPS Handling: Using the
http.clientlibrary for low-level, blocking HTTP requests. - Robust Input Handling: Using
urllib.parseto normalize and validate URL inputs. - Asynchronous Programming:
- Implementing high-concurrency network I/O with
asyncioandaiohttp. - Using
async/awaitsyntax for non-blocking code. - Managing connection pools and client configuration with
aiohttp.ClientSession. - Orchestrating and executing concurrent tasks with
asyncio.gather().
- Implementing high-concurrency network I/O with
The principles in this project are directly applicable to common automation, data engineering, and backend tasks.
- Performance: Demonstrates a clear understanding of I/O-bound bottlenecks and how to solve them with concurrency. This is a critical skill for building fast APIs, web scrapers, or data-processing pipelines.
- Robustness: Includes error handling for network failures and invalid input, essential for building reliable automation scripts.
- Maintainability: Provides a clean, documented, and easy-to-use tool, demonstrating the ability to deliver professional-grade, usable code.