# Custom Python functions
Quicklizard's pricing engine supports running custom functions written in Python.
You may define five kinds of functions - a pricing rule function, a condition function, a cost function, before pricing, or after pricing.
# Pricing rule functions
Use these functions to apply custom logic that generates a new price recommendation in a way that is not available as part of the pre-defined pricing rules on QL's online UI.
For example, you can create a function that creates a new price recommendation based on competitor prices and a given factor, and then reuse that function with different factor values in several pricing groups defined in our online UI.
# Condition functions
Use these functions to apply custom logic that returns a flag that indicates whether pricing rule should be executed or not in a way that is not available as part of the pre-defined pricing conditions on QL's online UI.
# Cost functions
Use these functions to apply custom logic to calculate your product's cost dynamically. These functions are suitable for situations where your cost is not fixed, but depends on product attributes and / or your product's shelf price.
# Before Pricing (Pre-Processor) Functions
Use these functions to apply custom logic before a product is priced by either our pricing engine or your custom functions.
# After Pricing (Post-Processor) Functions
Use these functions to apply custom logic after a product has been priced by either our pricing engine or your custom functions.
# Context Limitations
Some capabilities of the Python API Context can only be used before or after pricing:
- Setting / Removing attributes - Can be used before and after pricing
- Send products to pricing - Can be used after pricing
# Global Pricing Parameters
If needed, you can define key / value pairs that are globally available to all function types via QL's UI, under Settings -> Global Pricing Parameters.
This mechanism is useful in case you wish to define global attributes, such as shipping costs, currency conversion rates, locales etc. and access them in one or more of your custom functions.
# Execution environment
When a custom function is invoked, it receives a context with a payload that contains all the relevant product fields:
- shelf price
- cost (if available)
- inventory (if available)
- vat (if available)
- competitor prices
For most of the functions kinds, the execution context also contains user-defined variables, that let you reuse the same function multiple times in different pricing groups.
The execution context lets you access the above information about a currently priced product, along with variables if applicable, run your custom logic, and finally apply the result to the relevant fields (cost or price recommendation).
# Function Execution Order
Our pricing engine will execute your custom function in a specific order, based on your global, pricing group and strategy settings.
# Global Pre-Processors and Post-Processors
These are custom before and after pricing functions that are defined in your account settings area and are always executed before and after the relevant pricing group rules conditions and limits are applied to a given product.
Global pre and post processors are always executed, regardless of the pricing group a given product is associated with.
You may select which pre and post processors should be executed in QL's UI under the Settings area. You may select multiple pre and post processors and they will be executed in the order in which they are defined.
# Local Pre-Processors and Post-Processors
These are custom before and after pricing functions that are executed in the context of a pricing group and pricing strategy.
A local pre-processor is executed before the pricing logic is applied. A local post-processor is executed after the pricing logic is applied.
Each group and strategy may have a single pre-processor and a single post-processor attached to it.