or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli-interface.mdexception-handling.mdindex.mdresults-management.mdspeed-testing.md
tile.json

tessl/pypi-speedtest-cli

Command line interface for testing internet bandwidth using speedtest.net

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/speedtest-cli@2.1.x

To install, run

npx @tessl/cli install tessl/pypi-speedtest-cli@2.1.0

index.mddocs/

speedtest-cli

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.

Package Information

  • Package Name: speedtest-cli
  • Package Type: pypi
  • Language: Python
  • Installation: pip install speedtest-cli

Core Imports

import speedtest

Basic Usage

import 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))

Architecture

speedtest-cli uses a class-based architecture centered around two main classes:

  • Speedtest: Primary interface for performing speed tests, managing configuration, server selection, and test execution
  • SpeedtestResults: Container for test results with export capabilities (JSON, CSV, sharing)

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.

Capabilities

Core Speed Testing

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): ...

Speed Testing

Results Management

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=','): ...

Results Management

Exception Handling

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): ...

Exception Handling

CLI Interface

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(): ...

CLI Interface

Utility Functions

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): ...

Constants

__version__: str  # Current version string
DEBUG: bool      # Debug flag (default: False)

Classes

class FakeShutdownEvent:
    @staticmethod
    def isSet() -> bool: ...

Types

# 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