FilePublisher#

class FilePublisher(
directory: str | Path | None = None,
format: Literal['json', 'jsonl', 'csv', 'avro'] = 'avro',
custom_file_name: str | None = None,
*,
file: IO[Any] | None = None,
)[source]#

Bases: object

Write Measurement/Command data to a file or to an open stream.

Parameters:
  • directory

    Output directory, created if missing. Defaults to instro-measurements in the current working directory.

  • format

    "jsonl", "csv", "avro" (default), or "json" (deprecated).

  • custom_file_name

    Filename without extension; defaults to measurements-<local-timestamp>.

  • file

    Open stream to write to instead of a file: binary for "avro", text for "jsonl" and "csv". "json" does not support streams. close() leaves the stream open.

Raises:

ValueError – If file is combined with directory, custom_file_name, or "json", the format is unknown, or file is the wrong kind of stream for the format.

Methods

close

Close the file this publisher opened.

open

publish

Publish data to file using the appropriate writer.

directory: Path | None#
file_path: Path | None#
publish(
data: Measurement | Command,
**kwargs,
) → None[source]#

Publish data to file using the appropriate writer.

open() → None[source]#
close() → None[source]#

Close the file this publisher opened. A stream passed as file stays open.