glide.transform module

A home for common transform nodes

Nodes:

  • Func

  • Map

  • Sort

  • Transpose

  • DictKeyTransform

  • HashKey

  • JSONDumps

  • JSONLoads

  • EmailMessageTransform

class glide.transform.DictKeyTransform(name, _log=False, _debug=False, **default_context)[source]

Bases: glide.core.Node

run(data, drop=None, **transforms)[source]

Rename/replace keys in an iterable of dicts

Parameters
  • data – Data to process. Expected to be a list/iterable of dict rows.

  • drop (list, optional) – A list of keys to drop after transformations are complete.

  • **transforms – key->value pairs used to populate columns of each dict row. If the value is a callable it is expected to take the row as input and return the value to fill in for the key.

class glide.transform.EmailMessageTransform(name, _log=False, _debug=False, **default_context)[source]

Bases: glide.core.Node

Update EmailMessage objects

run(msg, frm=None, to=None, subject=None, body=None, html=None, attachments=None)[source]

Update the EmailMessage with the given arguments

Parameters
  • msg (EmailMessage) – EmailMessage object to update

  • frm (str, optional) – Update from address

  • to (str, optional) – Update to address(es)

  • subject (str, optional) – Update email subject

  • body (str, optional) – Update email body

  • html (str, optional) – Update email html

  • attachments (list, optional) – Replace the email attachments with these

class glide.transform.Func(name, _log=False, _debug=False, **default_context)[source]

Bases: glide.core.Node

Call func with data and push the result

run(data, func)[source]

Call func with data and push the result

Parameters
  • data – Data to process

  • func (callable) – Function to pass data to

class glide.transform.HashKey(name, _log=False, _debug=False, **default_context)[source]

Bases: glide.core.Node

run(data, columns=None, hash_func=<built-in function openssl_md5>, hash_dest='id', encoding='utf8')[source]

Create a unique hash key from the specified columns and place it in each row.

Parameters
  • data – An iterable of dict-like rows

  • columns (list, optional) – A list of columns to incorporate into the key. If None, the keys of the first row will be used. If the first row is not an OrderedDict, the keys will be sorted before use.

  • hash_func (callable, optional) – A callable from the hashlib module

  • hash_dest (str, optional) – Column name to put the calculated key

  • encoding (str, optional) – How to encode the values before hashing

class glide.transform.JSONDumps(name, _log=False, _debug=False, **default_context)[source]

Bases: glide.core.Node

Call json.dumps on the data

run(data)[source]

Call json.dumps on the data and push

class glide.transform.JSONLoads(name, _log=False, _debug=False, **default_context)[source]

Bases: glide.core.Node

Call json.loads on the data

run(data)[source]

Call json.loads on the data and push

class glide.transform.Map(name, _log=False, _debug=False, **default_context)[source]

Bases: glide.core.Node

Call the built-in map() function with func and data

run(data, func, as_list=False)[source]

Call the built-in map() function with func and data

Parameters
  • data – Data to process

  • func (callable) – Function to pass to map()

  • as_list (bool, optional) – If True, read the map() result into a list before pushing

class glide.transform.Sort(name, _log=False, _debug=False, **default_context)[source]

Bases: glide.core.Node

Sort data before pushing

run(data, key=None, reverse=False, inplace=False)[source]

Sort data before pushing

Parameters
  • data – The data to sort

  • key (callable, optional) – Passed to the underlying sort methods

  • reverse (bool, optional) – Passed to the underlying sort methods

  • inplace (bool, optional) – If True, try to use list.sort(), otherwise use sorted()

class glide.transform.Transpose(name, _log=False, _debug=False, **default_context)[source]

Bases: glide.core.Node

Transpose tabular data using zip

run(data)[source]

Transpose tabular data using zip