pyface.data_view.data_formats module

pyface.data_view.data_formats.to_json(data, default=None)[source]

Serialize an object to a JSON bytestring.

Parameters
  • data (Any) – The data to be serialized.

  • default (Callable or None) – Callable that takes a Python object and returns a JSON-serializable data structure.

Returns

raw_data – The serialized data as a bytestring.

Return type

bytes

pyface.data_view.data_formats.from_json(raw_data, object_hook=None)[source]

Deserialize a JSON bytestring.

Parameters
  • raw_data (bytes) – The serialized JSON data as a byte string.

  • object_hook (Callable) – Callable that takes a dictionary and returns an corresponding Python object.

Returns

data – The data extracted.

Return type

Any

pyface.data_view.data_formats.standard_text_format = DataFormat(mimetype='text/plain', serialize=functools.partial(<built-in function encode>, encoding='utf-8'), deserialize=functools.partial(<built-in function decode>, encoding='utf-8'))

The text/plain format with utf-8 encoding.

pyface.data_view.data_formats.html_format = DataFormat(mimetype='text/html', serialize=functools.partial(<built-in function encode>, encoding='utf-8'), deserialize=functools.partial(<built-in function decode>, encoding='utf-8'))

The text/html format with utf-8 encoding.

pyface.data_view.data_formats.json_format = DataFormat(mimetype='application/json', serialize=<function to_json>, deserialize=<function from_json>)

A generic JSON format.

pyface.data_view.data_formats.to_csv_row(data, delimiter=',', encoding='utf-8', **kwargs)[source]

Serialize a list to a single-row CSV bytestring.

Parameters
  • data (list) – The list to be serialized. Any elements which are not strings will be converted to strings by calling str().

  • delimiter (str) – The CSV delimiter.

  • encoding (str) – The encoding of the bytes

  • **kwargs – Additional arguments to csv.writer.

Returns

raw_data – The serialized data as a bytestring.

Return type

bytes

pyface.data_view.data_formats.from_csv_row(raw_data, delimiter=',', encoding='utf-8', **kwargs)[source]

Deserialize the first row of a CSV bytestring as a list.

Any rows beyond the first are ignored.

Parameters
  • raw_data (bytes) – The serialized CSV data as a byte string.

  • delimiter (str) – The CSV delimiter.

  • encoding (str) – The encoding of the bytes

  • **kwargs – Additional arguments to csv.reader.

Returns

data – The data extracted as a list of strings.

Return type

list of str

pyface.data_view.data_formats.to_csv_column(data, delimiter=',', encoding='utf-8', **kwargs)[source]

Serialize a list to a single-column CSV bytestring.

Parameters
  • data (list) – The list to be serialized. Any elements which are not strings will be converted to strings by calling str().

  • delimiter (str) – The CSV delimiter.

  • encoding (str) – The encoding of the bytes

  • **kwargs – Additional arguments to csv.writer.

Returns

raw_data – The serialized data as a bytestring.

Return type

bytes

pyface.data_view.data_formats.from_csv_column(raw_data, delimiter=',', encoding='utf-8', **kwargs)[source]

Deserialize the first column of a CSV bytestring as a list.

Any columns beyond the first are ignored.

Parameters
  • raw_data (bytes) – The serialized CSV data as a byte string.

  • delimiter (str) – The CSV delimiter.

  • encoding (str) – The encoding of the bytes

  • **kwargs – Additional arguments to csv.reader.

Returns

data – The data extracted as a list of strings.

Return type

list of str

pyface.data_view.data_formats.to_csv(data, delimiter=',', encoding='utf-8', **kwargs)[source]

Serialize a list of lists to a CSV bytestring.

Parameters
  • data (list of lists) – The data to be serialized. Any elements which are not strings will be converted to strings by calling str().

  • delimiter (str) – The CSV delimiter.

  • encoding (str) – The encoding of the bytes

  • **kwargs – Additional arguments to csv.writer.

Returns

raw_data – The serialized data as a bytestring.

Return type

bytes

pyface.data_view.data_formats.from_csv(raw_data, delimiter=',', encoding='utf-8', **kwargs)[source]

Deserialize a CSV bytestring.

Parameters
  • raw_data (bytes) – The serialized CSV data as a byte string.

  • delimiter (str) – The CSV delimiter.

  • encoding (str) – The encoding of the bytes

  • **kwargs – Additional arguments to csv.reader.

Returns

data – The data extracted as a list of lists of strings.

Return type

list of list of str

pyface.data_view.data_formats.to_npy(data)[source]

Serialize an array to a bytestring using .npy format.

Parameters

data (array-like) – The array to be serialized.

Returns

raw_data – The serialized data as a bytestring.

Return type

bytes

pyface.data_view.data_formats.from_npy(raw_data)[source]

Deserialize a .npy-format bytestring.

Parameters

raw_data (bytes) – The serialized CSV data as a byte string.

Returns

data – The data extracted as a list of lists of strings.

Return type

list of list of str