speedtest-ng
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-ngis an independent continuation of Matt Martz's archivedsivel/speedtest-cliproject (Copyright 2012 Matt Martz), preserving the Apache License 2.0 and full Git history.
Highlights (3.x)
- Native
AsyncSpeedtest+ Injectableaiohttp.ClientSession: Run directly on an existingasyncioevent loop without thread-pool blocking, while keeping the synchronousSpeedtestfacade 100% drop-in compatible across Python3.11–3.15. - Clean-Room
OoklaServerRaw TCP (:8080) Transport + Automatic HTTP Fallback: SpeaksHI/HELLO,PING/PONG,DOWNLOAD,UPLOAD,QUITwith zero-copy 256 KiB buffers and transparent fallback to keep-aliveaiohttpwhen port8080is 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, andprotocolfields. - Modern JSON Server Discovery: Queries Speedtest.net's
/api/js/serversendpoint 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 mslatency 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 (autoprefers raw TCP:8080with 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
Async API (Recommended)
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)
| 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)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| 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 logRelease 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 logSecurity 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.
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 logA 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.