Skip to content

Network benchmarks, from Python

iperf3-lib is a programmable network benchmarking and analysis library powered by native libiperf through CFFI. Configure traffic, preserve the measurements, compare results, and run finite sequential experiments from Python.

Get started Read the API

Python 3.12–3.15 · Linux tested · libiperf 3.19.1 / 3.22 · MIT license

Put the benchmark logic in your application

Calling iperf3 from a script is straightforward. As your workflow grows, iperf3-lib supplies the surrounding Python API: validated configuration, normalized measurements, repeated trials, baseline assessments, saved artifacts, and monitoring output. Reuse those contracts across applications instead of maintaining separate command builders, result interpreters, and reporting code.

The library uses the same native measurement engine as the CLI. Its advantage is the integration and analysis around each test. Existing subprocess or Ansible workflows can also import completed native JSON for analysis without replacing their runner.

Compare Python, CLI, and Ansible workflows

Choose your next step

  • Run a benchmark

    Install the shared library, configure a TCP or UDP client, and learn the synchronous, asynchronous, and live-event APIs.

    Installation and first run · Native controls · Live events

  • Understand the measurements

    Read flow directions, sender and receiver observations, intervals, and the original native JSON.

    Results guide

  • Save results

    Save native and normalized measurements with requested settings, verified observations, producer identity, and timing provenance.

    Result artifacts

  • Analyze measurements

    Calculate throughput stability, stream balance and scaling, and directional comparisons with explicit missing-data and diagnostic limits.

    Analysis guide

  • Run repeatable experiments

    Retain warm-ups, repetitions and failures; assess compatible baselines, run bounded concurrent plans, or explore finite sweeps and adaptive UDP rates.

    Trials and assessments · Concurrent plans · Parameter sweeps · Adaptive UDP

  • Export completed runs

    Use Prometheus gauges, atomic textfiles, and a reproducible local Grafana integration. Benchmark scheduling remains under your application's control.

    Prometheus guide

A small starting point

Start a compatible iperf3 server on a host you control, then run:

from iperf3_lib import Client, ClientConfig

result = Client(ClientConfig(server="127.0.0.1", duration=2)).run()
if result.ok:
    print(f"{result.summary_mbps:.2f} Mbps")
else:
    print(result.error)

The native library generates traffic and measures it. Python provides configuration, typed access to the output, and integration with your application. The package does not bundle libiperf or operate a benchmark scheduler or metrics service.

Know the execution boundary

Linux is the tested platform. Basic direct native calls share process-global state and must be serialized. Async methods, expanded controls, event delivery and explicit execution timeouts use isolated Python/CFFI workers. Cancelling arun() or aserve_once() waits for worker cleanup and any active callback; unconfirmed cleanup raises IperfCleanupError (introduced in 0.4.0). See compatibility and limitations.

Use the native option inventory to find binding, protocol, transport, server-policy and output controls. Option availability also depends on the native build, kernel and peer; a configuration request is not proof of effective network behavior.