pytweezer.servers.influx_client module

InfluxDB write helper — the single write path into the time-series store.

Everything that pushes values into InfluxDB goes through InfluxWriter: the background pytweezer.loggers and any ad-hoc code (a device driver, a Jupyter notebook). Connection details (URL/token/org/bucket) live in one place — the INFLUXDB block of pytweezer/configuration/config.py, overridable via environment variables — so callers never have to know them.

Notebook / REPL usage (requirement: “convenient way to push from a notebook”):

from pytweezer.servers.influx_client import log
log("laser", power=1.23, wavelength=780, tags={"system": "Rb"})

Custom / driver usage (own writer instance):

from pytweezer.servers.influx_client import InfluxWriter
writer = InfluxWriter()
writer.write("chamber", {"pressure": 2.1e-9}, tags={"system": "CaF"})
writer.close()

Design note: writes never raise. A missing/unreachable InfluxDB logs a warning and the call returns — so a notebook cell or a logger loop is never taken down by the database being offline.

class pytweezer.servers.influx_client.InfluxWriter(url=None, token=None, org=None, bucket=None)[source]

Bases: object

Thin wrapper over influxdb_client bound to the configured bucket.

Lazily connects on first write so constructing a writer never fails even if InfluxDB is down. Reusable and cheap; one instance per logger/notebook is fine.

close()[source]
write(measurement, fields, tags=None, time=None)[source]

Write one point. Never raises — logs a warning on failure and returns.

Parameters:
  • measurement (str) – InfluxDB measurement name.

  • fields (dict) – field name -> value; non-numeric values are dropped.

  • tags (dict, optional) – indexed string tags (e.g. system/device).

  • time (datetime, optional) – timestamp; defaults to now (UTC).

pytweezer.servers.influx_client.get_default_writer()[source]

Return a lazily-created process-wide InfluxWriter.

pytweezer.servers.influx_client.log(measurement, fields=None, tags=None, time=None, **field_kwargs)[source]

Push one point to InfluxDB using the shared default writer.

Convenience for notebooks/REPL — connection details are hidden in config. Fields may be passed as a dict and/or as keyword arguments:

log("laser", power=1.23, wavelength=780)
log("laser", {"power": 1.23}, tags={"system": "Rb"})