Skip to main content

speedtest-ng

CI PyPI version Python versions Downloads License: Apache-2.0

Modern, actively maintained Python 3.11+ asyncio and raw-TCP (OoklaServer) successor to sivel/speedtest-cli, providing both a CLI (speedtest / speedtest-cli) and a drop-in library API (import speedtest) engineered for Gigabit+ fiber accuracy and Home Assistant's speedtestdotnet integration.

Attribution: speedtest-ng is an independent continuation of Matt Martz's archived sivel/speedtest-cli project (Copyright 2012 Matt Martz), preserving the Apache License 2.0 and full Git history.

Highlights (3.x)

  • Native AsyncSpeedtest + Injectable aiohttp.ClientSession: Run directly on an existing asyncio event loop without thread-pool blocking, while keeping the synchronous Speedtest facade 100% drop-in compatible across Python 3.11–3.15.
  • Clean-Room OoklaServer Raw TCP (:8080) Transport + Automatic HTTP Fallback: Speaks HI/HELLO, PING/PONG, DOWNLOAD, UPLOAD, QUIT with zero-copy 256 KiB buffers and transparent fallback to keep-alive aiohttp when port 8080 is blocked or returns premature EOF.
  • Dynamic Multi-Stream Scaling & Statistical Windowing: Scales streams dynamically on Gigabit+ links, sustains full-duration worker pools over both TCP and HTTP, discards TCP slow-start warm-up and outliers via trimmed mean, and reports additive jitter, packet_loss, loaded_ping_download, loaded_ping_upload, and protocol fields.
  • Modern JSON Server Discovery: Queries Speedtest.net's /api/js/servers endpoint first (fixing stale/distant 10-server XML fallbacks) with automatic XML fallback, bounded metadata payload reads, and HTTPS (secure=True) by default.
  • Reliability & Leak Fixes: Eliminates phantom 1,800,000 ms latency values on unreachable servers, prevents TCP ping stream desync and fake-positive rejected HTTP uploads, removes multi-MB per-request upload buffer allocations and stdout/stderr fd wrapping leaks, and refreshes timestamps between reused runs.

Installation

uv add speedtest-ng

or with pip:

pip install speedtest-ng

CLI Usage

speedtest --simple
speedtest --json
speedtest --protocol tcp
speedtest --protocol http --no-secure
speedtest --list
speedtest --server 19911 --bytes

Key CLI options:

  • --protocol {auto,tcp,http} — Transfer transport (auto prefers raw TCP :8080 with automatic HTTP fallback).
  • --simple, --json, --csv, --csv-delimiter, --csv-header — Output formats.
  • --bytes — Report human-readable output in MB/s instead of Mbit/s.
  • --no-download, --no-upload, --single — Run partial or single-stream tests.
  • --server ID, --exclude ID, --list, --mini URL — Server discovery and selection.
  • --secure (default) / --no-secure, --source IP, --timeout SEC, --share, --version.

Python API

import asyncio
import aiohttp
from speedtest import AsyncSpeedtest


async def main() -> None:
    async with aiohttp.ClientSession() as session:
        client = AsyncSpeedtest(session=session)
        await client.get_servers()
        best = await client.get_best_server()
        download_bps = await client.download()
        upload_bps = await client.upload()
        print(
            best["sponsor"], client.results.ping, download_bps / 1e6, upload_bps / 1e6
        )


asyncio.run(main())

Synchronous Drop-In API (speedtest-cli Compatible)

import speedtest

api = speedtest.Speedtest(secure=True)
api.get_servers()
best = api.get_best_server()
api.download()
api.upload()
results = api.results.dict()
print(results["ping"], results["download"] / 1e6, results["upload"] / 1e6)

Development

uv sync --all-groups
uv run ruff check --no-fix .
uv run ruff format --check .
uv run mypy speedtest tests
uv run pytest

Opt-in live Speedtest.net tests:

uv run pytest -m real_api_call --no-cov

Metadata

Release files for speedtest-ng 3.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for speedtest-ng 3.1.0
File Size Uploaded Provenance Actions
speedtest_ng-3.1.0.tar.gz 51.2 kB With provenance Details for speedtest_ng-3.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for speedtest-ng 3.1.0
File Interpreter ABI Platform Actions
speedtest_ng-3.1.0-py3-none-any.whl Python 3 none any Details for speedtest_ng-3.1.0-py3-none-any.whl

Total release size: 86.9 kB

Release files / speedtest_ng-3.1.0.tar.gz

Download URL speedtest_ng-3.1.0.tar.gz
Size 51.2 kB
Tags Source
SHA-256 checksum
How to use checksums
54c490ee1e6b009c0da2021a9c4eeacb3a41bad7dc5b42e35d01d0790e168b92
BLAKE2b-256 checksum
How to use checksums
c723420a1ca0a88f380340d7212ea6f92ac76822061bed0c760d820baf5b244a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / speedtest_ng-3.1.0-py3-none-any.whl

Download URL speedtest_ng-3.1.0-py3-none-any.whl
Size 35.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
caca12e2bcecba5e89432d0a524b887570499823130ef6ffa6647609e8151618
BLAKE2b-256 checksum
How to use checksums
4c5d511d4b2477d0c2df41584d3584febed4d24750c7e92e306351fc25168db9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for speedtest-ng 3.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for speedtest_ng-3.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page