Python driver library for low-cost vector network analyzers of the NanoVNA family. Supported protocol families:
- NanoVNA V1 — line-based text protocol
- NanoVNA V2 / LiteVNA — binary register protocol
- NanoVNA-X — ChibiOS shell protocol (USB CDC serial)
- Python 3.12+
- Optional: a VNA connected via USB-serial for hardware use
- VNA devices might use the NanoVNA-X firmware for supported devices; it is preferable
pip install pyvna # core library (drivers + calibration)
pip install "pyvna[server]" # adds the example HTTP server
pip install "pyvna[test,dev]" # adds the test and lint toolchainEditable development checkout:
pip install -e ".[server,test,dev]"from pyvna import SweepConfig, VNAPool
pool = VNAPool()
vna = pool.get("COM5") # or "/dev/ttyACM0"
print(vna.model) # identification string from the probe
vna.set_sweep(SweepConfig(start=1e6, stop=900e6, points=101))
data = vna.get_data()
print(data.to_touchstone("s11")) # standard Touchstone RI export
pool.close_all()from pyvna import (
CalibrationPlan,
CalibrationStandard,
CalibrationStep,
SweepConfig,
)
plan = CalibrationPlan(
name="s11-sol",
sweep=SweepConfig(start=1e6, stop=900e6, points=101),
steps=[
CalibrationStep(CalibrationStandard.OPEN),
CalibrationStep(CalibrationStandard.SHORT),
CalibrationStep(CalibrationStandard.LOAD),
],
)
profile = vna.acquire_calibration(plan, prompt=lambda std: print("connect:", std))
data = vna.get_data() # S11 de-embedded with the three-term modelThe profile is installed only after all standards are measured and the error
terms compute and validate; a cancelled run raises CalibrationCancelledError
and installs nothing. S21 passes through as measured — see the API docstrings.
python -m pyvna.server.main [--host 127.0.0.1] [--port 8080]GET /api/v1/scan?port=COM5&start=1e6&stop=900e6&points=101&trace=s11-> TouchstoneGET /metrics-> Prometheus text format
The server binds to loopback by default; put it behind an authenticated reverse proxy for network use.
pyvna/__init__.py— public API exports and package versionpyvna/errors.py— exception hierarchy rooted atPyVNAErrorpyvna/models.py—SweepConfig,VNAData; Touchstone RI export, VSWRpyvna/driver_base.py— shared driver behaviour: bounded I/O disciplinepyvna/driver.py—Driverprotocol, probe factory,VNAPoolpyvna/driver_v1.py— NanoVNA V1 line-based text protocolpyvna/driver_v2.py— NanoVNA V2 / LiteVNA binary register protocolpyvna/driver_x.py— NanoVNA-X ChibiOS shell protocol (USB CDC serial)pyvna/calibration.py— SOL calibration: standards, plans, profiles, error termspyvna/vna.py— high-level VNA facade: sweep, scan, calibrationpyvna/util/serial_port.py— serial port abstraction and path validationpyvna/server/main.py— example FastAPI server: Touchstone scans + Prometheus metricstests/— unit test suite with mock ports and fake devices
MIT (see LICENSE)