Available Built-in Functions
Precision Bridge formulas run in a secure sandbox with access to a curated set of Python built-in functions. This article provides a complete reference of every built-in function available in formulas, organized by category.
Note:
importstatements are not available in formulas. All functions listed here are pre-loaded and ready to use. You do not need to import anything.
Type Constructors
These functions create or convert values to a specific type.
| Function | Description | Example |
|---|---|---|
str() |
Convert to string |
str(42) returns '42'
|
int() |
Convert to integer |
int('7') returns 7
|
float() |
Convert to floating-point number |
float('3.14') returns 3.14
|
bool() |
Convert to boolean |
bool(0) returns False
|
list() |
Convert iterable to list |
list(range(3)) returns [0, 1, 2]
|
tuple() |
Convert iterable to tuple |
tuple([1, 2]) returns (1, 2)
|
dict() |
Create dictionary from key-value pairs |
dict(name='John', age=30) returns {'name': 'John', 'age': 30}
|
set() |
Convert iterable to set (unique values) |
set([1, 1, 2, 3]) returns {1, 2, 3}
|
Examples
str([priority]) + ' - ' + [short_description]
Converts the numeric priority to a string before concatenation.
int([score]) if [score] is not None else 0
Safely converts a score field to an integer, defaulting to 0.
Math Functions
| Function | Description | Example |
|---|---|---|
abs() |
Absolute value |
abs(-5) returns 5
|
min() |
Return the smallest argument |
min(3, 1, 4, 1, 5) returns 1
|
max() |
Return the largest argument |
max(3, 1, 4, 1, 5) returns 5
|
pow() |
Raise to a power |
pow(2, 10) returns 1024
|
round() |
Round to N decimal places |
round(3.14159, 2) returns 3.14
|
sum() |
Sum all items in an iterable |
sum([10, 20, 30]) returns 60
|
range() |
Generate a sequence of integers |
list(range(1, 6)) returns [1, 2, 3, 4, 5]
|
Examples
abs([temperature_diff])
Returns the absolute value of a temperature difference.
max([score1], [score2], [score3])
Returns the highest score across three fields.
round(float([price]), 2)
Rounds a price value to two decimal places.
sum([int(x) for x in [scores].split(',')])
Splits a comma-separated scores string, converts each to an integer, and sums them.
Iterable Functions
These functions operate on lists, tuples, sets, and other iterable types.
| Function | Description | Example |
|---|---|---|
len() |
Return the number of items |
len([1, 2, 3]) returns 3
|
sorted() |
Return a new sorted list |
sorted([3, 1, 2]) returns [1, 2, 3]
|
reversed() |
Return items in reverse order |
list(reversed([1, 2, 3])) returns [3, 2, 1]
|
enumerate() |
Pair each item with its index |
list(enumerate(['a', 'b'])) returns [(0, 'a'), (1, 'b')]
|
zip() |
Combine iterables element-wise |
list(zip([1, 2], ['a', 'b'])) returns [(1, 'a'), (2, 'b')]
|
all() |
True if all items are truthy |
all([True, True, False]) returns False
|
any() |
True if any item is truthy |
any([False, True, False]) returns True
|
filter() |
Keep items where the function returns True |
list(filter(None, ['', 'a', '', 'b'])) returns ['a', 'b']
|
map() |
Apply a function to each item |
list(map(str, [1, 2, 3])) returns ['1', '2', '3']
|
iter() |
Get an iterator from an iterable | iter([1, 2, 3]) |
next() |
Get the next item from an iterator |
next([1, 2, 3]) returns 1
|
slice() |
Create a slice object |
my_list[slice(0, 3)] returns first 3 items |
Examples
sorted([tags].split(','), reverse=True)
Splits tags and sorts them in reverse alphabetical order.
len([description])
Returns the character count of the description field.
any([flag1, flag2, flag3])
Returns True if any of the three flag variables is truthy.
list(zip([keys].split(','), [values].split(',')))
Pairs up corresponding keys and values from two comma-separated strings.
Note: The
next()function in Precision Bridge is enhanced to accept both iterators and iterables (like lists). In standard Python,next()only works on iterators. In formulas,next([1, 2, 3])returns1directly without needingiter()first.
Type Checking Functions
| Function | Description | Example |
|---|---|---|
type() |
Return the type of a value |
type(42) returns <class 'int'>
|
isinstance() |
Check if value is an instance of a type |
isinstance([value], str) returns True or False
|
issubclass() |
Check if a type is a subclass of another |
issubclass(bool, int) returns True
|
callable() |
Check if an object is callable |
callable(len) returns True
|
hasattr() |
Check if an object has a named attribute |
hasattr(my_obj, 'get') returns True
|
getattr() |
Get an attribute from an object | getattr(my_obj, 'name', 'default') |
Examples
isinstance([value], str)
Returns True if the field contains a string value.
'string' if isinstance([field], str) else 'other'
Checks the type and returns a label accordingly.
hasattr(my_variable, 'get')
Returns True if the variable is a dictionary-like object with a .get() method.
Character Functions
| Function | Description | Example |
|---|---|---|
chr() |
Return the character for a code |
chr(65) returns 'A'
|
ord() |
Return the code for a character |
ord('A') returns 65
|
Examples
chr(ord([char]) + 1)
Returns the next character in the ASCII table.
ord([letter]) - ord('A') + 1
Converts a letter to its position in the alphabet (A=1, B=2, etc.).
Date and Time
The following date/time types are available as constructors and provide full method access:
| Type | Description | Example |
|---|---|---|
datetime |
Date and time combined | datetime(2024, 1, 15, 10, 30, 0) |
date |
Date only | date(2024, 1, 15) |
time |
Time only | time(10, 30, 0) |
timedelta |
A duration or difference | timedelta(days=30) |
timezone |
A fixed timezone offset, used to anchor a datetime | timezone.utc |
Working with the current date and time
Two forms exist for asking the system for "now". Prefer the UTC-anchored form below in any formula that compares against other datetime values, serialises a result, or runs across environments with different host timezones:
datetime.now(timezone.utc)
This returns a timezone-aware datetime in UTC. The result is the same on
every machine, regardless of the host's local timezone, so derived values
like [submit_date].year == datetime.now(timezone.utc).year - 1 behave
consistently in development, staging, and production.
The bare form is also available:
datetime.now()
This returns a naive datetime in the host machine's local timezone. It has
no timezone information attached, and comparisons against timezone-aware
datetimes will raise a TypeError. Use this form only when you genuinely
want host-local wall-clock time and you control the host's timezone.
System Variables: CURRENT_EXECUTION_TIMESTAMP and LAST_EXECUTION_TIMESTAMP
Every procedure has two built-in system variables for execution-relative time:
| Variable | Holds | Updated |
|---|---|---|
CURRENT_EXECUTION_TIMESTAMP |
Start time of the current procedure run (UTC, timezone-aware). | Set when each execution begins; stable for the rest of the run. |
LAST_EXECUTION_TIMESTAMP |
Start time of the previous successful run (UTC, timezone-aware). | Updated at the end of each successful run. Empty on the very first run. |
These are not equivalent to "now". They are tied to execution start times, not the moment the formula is evaluated. Use them when you need behaviour relative to the procedure's own run history:
-
Delta / incremental migration filters —
[sys_updated_on] > LAST_EXECUTION_TIMESTAMPextracts everything modified since the previous run. The platform maintains the variable automatically — no Assign Variables step, no external persistence required. -
Stamping run metadata onto migrated records —
CURRENT_EXECUTION_TIMESTAMPgives every record from the same run an identical timestamp, useful for audit columns or batch markers. -
Run-window comparisons —
[updated_at] > LAST_EXECUTION_TIMESTAMP and [updated_at] <= CURRENT_EXECUTION_TIMESTAMPexactly bounds the records the current run is responsible for.
For wall-clock reasoning that does not depend on execution history — "today", "this year", "more than 30 days ago" — use datetime.now(timezone.utc) instead.
LAST_EXECUTION_TIMESTAMP is empty (None) on the very first run. Either toggle the Override switch on the variable for the first run (pick a starting cutoff from the past-executions combobox or a custom value), or write the filter with a fallback such as LAST_EXECUTION_TIMESTAMP or datetime(2000, 1, 1, tzinfo=timezone.utc). The Override switch is also how you re-run from a specific point in time.
See Procedures and Variables — System Variables and Migration Strategy — Incremental Migration for the broader workflow.
Examples
Create a specific date:
date(2024, 6, 15)
Get today's date in UTC:
datetime.now(timezone.utc).date()
Test whether a field is from last year (UTC):
[submit_date].year == datetime.now(timezone.utc).year - 1
Calculate a date 30 days from now (UTC):
datetime.now(timezone.utc) + timedelta(days=30)
Calculate the difference between two dates:
(datetime.now(timezone.utc) - datetime(2024, 1, 1, tzinfo=timezone.utc)).days
Returns the number of days since January 1, 2024.
Format a datetime as a string:
datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S %Z')
Produces a string like '2024-06-15 10:30:00 UTC'.
Important Notes
-
No imports available. All functions listed above are pre-loaded in the formula environment. You cannot use
importto bring in additional modules. - Security sandbox. The formula environment restricts access to file system operations, network calls, and other potentially unsafe operations. The available functions are carefully curated for safety.
- PB-specific functions. In addition to the Python built-ins listed here, Precision Bridge provides its own library of specialized functions for string manipulation, JSON processing, XML handling, date formatting, and more. See the Functions Reference for the complete list.
-
Exception types. Standard Python exception types (e.g.,
ValueError,TypeError,KeyError) are available in the formula environment. These are primarily useful for understanding error messages rather than explicit exception handling, since formulas are single expressions.
Quick Reference
Here is the complete list of available built-in names at a glance:
Type constructors: str, bool, int, float, list, tuple, dict, set
Math: abs, min, max, pow, round, sum, range
Iterables: len, sorted, reversed, enumerate, zip, all, any, filter, map, iter, next, slice
Type checking: type, isinstance, issubclass, callable, hasattr, getattr
Characters: chr, ord
Date/Time: datetime, date, time, timedelta, timezone
Next Steps
- Start with the basics in Introduction to Formulas
- Learn about data types in Working with Types
- Explore the PB-specific functions in the Functions Reference
Comments
0 comments
Please sign in to leave a comment.