Variables
Variable scopes
Sequor supports four variable scopes, organized in a hierarchy. Each child scope can override variables with the same name from parent scopes.
Variable scopes:
- Environment variables - Defined in Sequor environments by the user and typically used for credentials or environments-specific parameters (e.g. database connection strings or directory paths). These are constants that cannot be modified during flow execution. For information on defining environment variables, see Environments
- Project variables - Set by operations (e.g.
set_variable
orhttp_request
) during flow execution. These are persistent variables that survive between flow executions. - Source variables - Defined the
variables
section ofhttp
type sources and can be referenced fromhttp_request
operations using that source. These variables do not survive beyond the operation’s execution. - Local variables - Set by the same operations as project variables but with
scope: local
. These are temporary variables that do not survive flow execution.
Variable types
Variables can be of any Python type. The type is determined by:
- When setting variables using
return { "variables": ... }
(for example, in an http_request operation), the variable type matches the Python value’s type. - When using the
set_variable
operation, the variable value is always stored as a string.
Setting variables in operations
There are two syntax formats for setting variables in operations:
- Compact form - Variable value is defined as a simple string. This automatically sets the variable in the project scope.
"var1": "value1"
- Extended form - Variable value is defined as a YAML object with
value
andscope
keys. The scope can be eitherlocal
orproject
."var2": { "value": "value2", "scope": "local" }
The following examples demonstrate setting project and local variables using set_variable
and http_operations
operations:
steps:
- op: set_variable
set:
"var1": "value1" # Project scope variable (compact form) - persists after flow execution
"var2": { # Local scope variable (extended form) - temporary during flow execution
value: "value2",
scope: "local"
},
"var3": { # Project scope variable (extended form) - persists after flow execution
value: "value3",
scope: "project"
}
- op: http_request
id: get_customers
request:
source: "bigcommerce_rest"
url: "https://api.bigcommerce.com/stores/{{ var('store_hash') }}/{{ var('api_version') }}/customers"
method: GET
parameters_expression: |
def evaluate(context):
return {
"limit": 5, # intentionally small limit for testing; use 100 or even 1000 for production
"page": context.var("next_page") if context.is_var_defined("next_page") else 1
}
headers:
"Accept": "application/json"
response:
parser_expression: |
def evaluate(context, response):
if response.status_code != 200:
raise Exception("Error response code: " + str(response.status_code) + "; body: " + response.text)
json_data = response.json()
current_page = json_data["meta"]["pagination"]["current_page"]; # integer
total_pages = json_data["meta"]["pagination"]["total_pages"]; # integer
return {
"variables": {
"next_page": { Local scope variable (extended form) - temporary during flow execution
"value": current_page + 1,
"scope": "local"
}
},
"tables": [{
"source": "stage",
"table": "bc_customers",
"data": json_data['data'],
"model": {
"columns": [
{"name": "id", "type": "text"},
{"name": "first_name", "type": "text"},
{"name": "last_name", "type": "text"}
]
}
}],
"while": current_page < total_pages
}```
Last updated on