Skip to content

gouomar/check_connectivity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Python URL Connectivity Checker

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:

  1. Synchronous (Default): A sequential, blocking method using the standard http.client library.
  2. Asynchronous: A high-performance, concurrent method using aiohttp and asyncio for efficiently checking large URL lists.

Features

  • 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) using urllib.parse.
  • Clear Status Output: Reports a simple status (OK, ERROR, or DOWN) for each URL.
  • Configurable Timeout: Uses a global timeout for all requests.

Technical Overview: Synchronous vs. Asynchronous

This project intentionally includes two different implementations to demonstrate and compare I/O handling.

Synchronous (http.client)

  • Implementation: Uses the standard http.client library. 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.

Asynchronous (aiohttp + asyncio)

  • Implementation: Uses aiohttp and the asyncio event 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/await code structure.

Setup and Installation

  1. Clone the repository:

    git clone https://github.com/gouomar/check_connectivity
    cd <your-project-name>
  2. install requirements: This project requires aiohttp.

    install the dependencies (preferably in a virtual environment):

    pip install aiohttp

Usage

All options can be viewed with the -h flag.

python check_connectivity.py -h
usage: 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

Core Concepts Demonstrated

This project serves as a practical application of several key Python concepts:

  • CLI Implementation: Building a complete command-line interface using the argparse standard library.
  • HTTP/HTTPS Handling: Using the http.client library for low-level, blocking HTTP requests.
  • Robust Input Handling: Using urllib.parse to normalize and validate URL inputs.
  • Asynchronous Programming:
    • Implementing high-concurrency network I/O with asyncio and aiohttp.
    • Using async/await syntax for non-blocking code.
    • Managing connection pools and client configuration with aiohttp.ClientSession.
    • Orchestrating and executing concurrent tasks with asyncio.gather().

Application & Relevance

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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages