Python execution context API

get_activity()

product activity getter. returns daily and weekly product activity

Example:

{
  "24hr": {"views": 93, "conversions": 11, "revenue": 562.45},
  "7d": {"views": 93, "conversions": 11, "revenue": 562.45}
}

get_attrs()

product attribute getter. returns product attributes array (list)

set_attr(name, value)

product attribute setter. sets product attribute by name and value. can only be called before or after pricing.

Args:

  • name (string) - attribute name
  • value (string) - attribute value

del_attr(name)

product attribute remover. removes product attribute by name. can only be called before or after pricing.

Args:

  • name (string) - attribute name

get_cost()

product cost getter. returns priced product cost (float)

get_inventory()

priced product inventory getter. returns product inventory level (int)

get_channel()

price channel name getter. returns current channel name (string)

get_client_channels()

Client channels list getter, applicable to omni-channel systems. (list[str])

get_ql_recommendation()

Quicklizard recommended price getter. returns price recommendation generated by QL pricing engine, which can be used in custom cost functions (float)

get_recommendation()

recommended price getter. returns price recommendation generated by custom function (float)

get_result()

code execution result getter. returns a dict with all fields related to recommendation, cost and conditions (dict)

Example: {'price': 12.32,'explanation': 'my custom code','uid': '1dee3155eccdeead','cost': 9.34, 'execute_rule': False}

get_shelf_price()

product shelf price getter. returns product shelf price (float)

get_variables()

execution context variables getter. returns dictionary with execution context variables as set in pricing rule

get_vat()

priced product VAT getter. returns product VAT (float)

get_config()

product config getter. returns product config list or empty list if undefined (list)

Example: [{"field": "size", "value": "medium"}]

get_competitor_prices()

product competitor prices getter. returns competitor prices array (list)

get_rule_condition_flag()

rule conditions flag getter. returns boolean flag that indicates whether rule should be executed or not

get_parameters()

global pricing parameters getter. returns dictionary of key / value pairs that are defined in QL's UI, under Settings -> Global Pricing Parameters.

get_created_at()

product creation date getter. returns product creation date as string

get_rule_position()

rule position getter. returns product pricing rule position as string

get_group_id()

group_id getter. returns product group id as string

get_group_name()

group name getter. returns product group name as string

get_label()

product label getter. returns product label as string

get_product_id()

product id getter. returns the raw product id as string

get_pricing_explanation():

pricing explanation getter. returns product pricing explanation as string. available only in post-pricing functions.

kv_get(key, scope=None)

get value from K/V store and return it, or None if an error occurred

Args:

  • key (string) - key to get value from
  • scope (string) - optional global scope value was saved on

kv_del(key, scope=None)

delete value from K/V store by key

Args:

  • key (string) - key delete from store
  • scope (string) - optional global scope value was saved on

kv_set(key, val, ttl, scope=None)

set value in K/V store

Args:

  • key (string) - unique key to store value
  • value (string) - value to store under key in K/V store
  • ttl (int) - value time-to-leave in seconds. Defaults to 172800 (2 day)
  • scope (string) - optional global scope to save value on

Please Note

Maximum TTL is 7 days. Values greater than 7 days will be decreases to match that limit

Scope Override

K/V values are scoped to client key. You can override this scope by passing a unique string to the scope argument, which will allow you to share values between client keys. Override scopes are global - If you override the default scope, you should make sure your scope value is unique and cannot be reproduced by other users.

kv_incr(key, ttl, scope=None)

increment counter identified by key by 1

Args:

  • key (string) - key of the counter to increment
  • ttl (int) - value time-to-leave in seconds. Defaults to 172800 (2 day)
  • scope (string) - optional global scope to save value on

Please Note

Maximum TTL is 7 days. Values greater than 7 days will be decreases to match that limit

kv_decr(key, ttl, scope=None)

decrease counter identified by key by 1

Args:

  • key (string) - key of the counter to decrease
  • ttl (int) - value time-to-leave in seconds. Defaults to 172800 (2 day)
  • scope (string) - optional global scope to save value on

Please Note

Maximum TTL is 7 days. Values greater than 7 days will be decreases to match that limit

set_cost(cost)

cost setter. used to set cost after rule logic was executed

Args:

  • cost (float) - calculated cost to set

set_explanation(string)

recommended price explanation setter. used to set recommendation explanation text

Args:

  • str (string) - recommended price explanation to set

set_recommendation(recommendation)

recommended price setter. used to set recommended price after rule logic was executed

Args:

  • recommendation (float) - recommended price to set

set_rule_condition_flag(flag)

rule conditions flag setter. sets a boolean flag that indicates whether rule should be executed or not

Args:

  • flag (bool) - rule conditions flag

send_to_pricing(product_ids)

accepts a list of product ids that should be sent to pricing (in the current channel) after your custom code finished running. can only be called after pricing

Args:

  • product_ids (list[str]) - a list of product ids to send to pricing

send_to_pricing_by_channel(product_id, channel)

accepts a product id and channel that should be sent to pricing after your custom code finished running. can only be called after pricing. (applicable to omni-channel systems)

Args:

  • product_id (str) - product id to send to pricing
  • channel (str) - product channel

log(msg)

append log message to logs array. use while writing code, to print and display log messages

Args:

  • msg (string) - message to log

add_widget(uid, channel, kind, title, position, data, ttl)

add widget to be rendered by QL UI on dimension page identified by uid.

For table widgets, pass an array of arrays, where the first array contains column names, and each subsequent array contains a row of data. For example:

[
  ['name', 'value'],
  ['name A', 'value A'],
  ['name B', 'value B']
]

For chart:line widgets pass an array of x / y points, where x contains a single value, and y contains one or more named series (Y axis series names should be consistent across all rows). For example:

[
  {x: 'Sunday', y: {'Views': 4, 'Sales': 2}},
  {x: 'Monday', y: {'Views': 11, 'Sales': 3}}
]

For chart:composite widgets pass a dict with two fields:

  • data - an array of x / y points, where x contains a single value, and y contains one or more named series (Y axis series names should be consistent across all rows).
  • types - a dict with information about the chart type for each series. Supported types are: 'line', 'bar', 'area'

For example:

{
  data: [
    {x: 'Sunday', y: {'Views': 4, 'Sales': 2}},
    {x: 'Monday', y: {'Views': 11, 'Sales': 3}}
  ],
  types: {
    'Views': 'line',
    'Sales': 'bar'
  }
}

Args:

  • uid (string) - widget target entity identifier. can be one of product UID, group ID
  • channel (string) - widget target price channel. 'all' / current channel name
  • kind (string) - widget kind. can be one of 'table', 'chart:line', 'chart:composite'
  • title (string) - widget title as it should be displayed in UI
  • position (int) - widget display position. position serves as an ID for the widget - writing different data to the same position overrides old data
  • data (list/dict) - widget data
  • ttl (int) - widget data TTL in seconds

del_widget(uid, channel, position):

delete widget for entity identified by uid in position position and channel channel.

Args:

  • uid (string) - widget target entity identifier. can be one of product UID, group ID
  • channel (string) - widget target price channel. 'all' / current channel name
  • position (int) - widget display position. position serves as an ID for the widget

get_widget(uid, channel, position):

get widget for entity identified by uid in position position and channel channel.

Args:

  • uid (string) - widget target entity identifier. can be one of product UID, group ID
  • channel (string) - widget target price channel. 'all' / current channel name
  • position (int) - widget display position. position serves as an ID for the widget

get_widgets(uid, channel):

list all widgets entity identified by uid in channel channel.

Args:

  • uid (string) - widget target entity identifier. can be one of product UID, group ID
  • channel (string) - widget target price channel. 'all' / current channel name

send_message(recipient, subject, message):

Send message to recipient by email

Args:

  • recipient (string) - message recipient email address
  • subject (string) - message subject
  • message (str - message body