Command line interface for testing internet bandwidth using speedtest.net
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Command line interface for testing internet bandwidth using speedtest.net. Provides both CLI functionality and a Python API for programmatic access to speed testing capabilities including download/upload speed measurements, latency testing, and server selection.
pip install speedtest-cliimport speedtestimport speedtest
# Create speedtest instance
s = speedtest.Speedtest()
# Get best server and run tests
s.get_best_server()
s.download()
s.upload()
# Access results
results = s.results
print(f"Download: {results.download / 1000000:.2f} Mbps")
print(f"Upload: {results.upload / 1000000:.2f} Mbps")
print(f"Ping: {results.ping:.2f} ms")
# Export results
print(results.json(pretty=True))speedtest-cli uses a class-based architecture centered around two main classes:
The package provides extensive exception handling through a hierarchy of specialized exception classes, and includes threading classes for concurrent download/upload testing to maximize bandwidth utilization.
Primary speed testing functionality including server selection, download/upload tests, and configuration management. The main Speedtest class provides the complete API for performing bandwidth measurements.
class Speedtest:
def __init__(self, config=None, source_address=None, timeout=10, secure=False, shutdown_event=None): ...
def get_config(self): ...
def get_servers(self, servers=None, exclude=None): ...
def set_mini_server(self, server): ...
def get_closest_servers(self, limit=5): ...
def get_best_server(self, servers=None): ...
def download(self, callback=None, threads=None): ...
def upload(self, callback=None, pre_allocate=True, threads=None): ...Comprehensive results handling with multiple export formats and sharing capabilities. The SpeedtestResults class provides structured access to test data and various output options.
class SpeedtestResults:
def __init__(self, download=0, upload=0, ping=0, server=None, client=None, opener=None, secure=False): ...
def share(self): ...
def dict(self): ...
def json(self, pretty=False): ...
def csv(self, delimiter=','): ...Comprehensive exception hierarchy for handling various error conditions during speed testing operations. All exceptions inherit from SpeedtestException base class.
class SpeedtestException(Exception): ...
class SpeedtestCLIError(SpeedtestException): ...
class SpeedtestHTTPError(SpeedtestException): ...
class SpeedtestConfigError(SpeedtestException): ...
class ConfigRetrievalError(SpeedtestHTTPError): ...
class SpeedtestServersError(SpeedtestException): ...
class ServersRetrievalError(SpeedtestHTTPError): ...
class InvalidServerIDType(SpeedtestException): ...
class NoMatchedServers(SpeedtestException): ...
class SpeedtestMiniConnectFailure(SpeedtestException): ...
class InvalidSpeedtestMiniServer(SpeedtestException): ...
class ShareResultsConnectFailure(SpeedtestException): ...
class ShareResultsSubmitFailure(SpeedtestException): ...
class SpeedtestUploadTimeout(SpeedtestException): ...
class SpeedtestBestServerFailure(SpeedtestException): ...
class SpeedtestMissingBestServer(SpeedtestException): ...Command-line interface providing direct access to speed testing functionality with extensive options for output formatting, server selection, and test configuration.
def main(): ...
def shell(): ...
def parse_args(): ...Module-level utility functions for distance calculation, HTTP operations, and user agent building.
def distance(origin, destination): ...
def build_user_agent(): ...
def build_request(url, data=None, headers=None, bump='0', secure=False): ...
def catch_request(request, opener=None): ...__version__: str # Current version string
DEBUG: bool # Debug flag (default: False)class FakeShutdownEvent:
@staticmethod
def isSet() -> bool: ...# Configuration dictionary structure
ConfigDict = dict[str, Any] # Contains client info, server list URLs, timing settings
# Server dictionary structure
ServerDict = dict[str, Any] # Contains id, host, port, name, country, sponsor, lat, lon, distance
# Client dictionary structure
ClientDict = dict[str, Any] # Contains ip, lat, lon, isp, isprating, rating, ispdlavg, ispulavg
# Callback function signature for progress monitoring
CallbackFunction = Callable[[int, int], None] # (bytes_received, total_bytes) -> None