Use try/finally to close the connection:
import json
from pyvantagepro import VantagePro2
device = VantagePro2.from_url('tcp:127.0.0.1:22222', timeout=10)
try:
raw = device.get_current_data()
print(raw.filter(('Datetime', 'TempOut', 'HumOut')).to_csv())
payload = device.get_current_data_as_json()
print(json.dumps(payload))
finally:
device.close()
Raw parser dictionaries retain native engineering units and sensor codes. Normalized payloads apply conversions and validation described in :doc:`data-format`. The JSON method returns a dictionary, not encoded JSON text. Each live API call fetches a new observation.
meta() reads a live packet and returns an ordered mapping from field name
to internal_unit and si_unit descriptors. Live lists use that field
order; invalid entries become None:
metadata = device.meta()
values = device.get_current_data_as_list()
for name, value in zip(metadata, values):
print(name, value, metadata[name]['si_unit'])
get_current_data_as_csv() is a compatibility alias for the list method;
it does not produce CSV text. For CSV text use Dict.to_csv() or
ListDict.to_csv().
Specify station-local naive datetimes to bound a download:
from datetime import datetime
rows = device.get_archives(
start_date=datetime(2026, 2, 19, 0, 0),
stop_date=datetime(2026, 2, 19, 23, 59),
)
if rows:
print(rows[0])
with open('archive.csv', 'w', newline='') as output:
output.write(rows.to_csv())
get_archives() returns a ListDict sorted by timestamp with duplicate
returned timestamps removed. Without dates it requests available history.
The download start is rounded using the archive period. Archive downloads
may be slow; request bounded windows and check the returned timestamps.
get_archives_as_json() returns a list of normalized dictionaries.
get_archives_as_list() returns each archive row's own field order,
not the live meta() schema. See :doc:`data-format` for archive unit
limitations. Neither wrapper changes which records are downloaded.
Read gettime(), getperiod(), timezone, firmware_date,
firmware_version, getdiagnostics() and getbar() to inspect the
station. settime(datetime.now()) changes its clock.
setperiod(10) changes its archive interval; the allowed intervals are
1, 5, 10, 15, 30, 60 and 120 minutes. Reconnect before verifying cached
station properties after configuration changes.
The repository's examples/README.md catalogs connection, archive,
CSV, JSON, MQTT, and continuous-stream examples.