Skip to main content

Language Basics

OpalScript uses Starlark syntax, which is similar to Python. This section gives you a quick overview of Starlark syntax and its key differences from Python.

Syntax Overview

# Variables
count = 10
name = "alice"
is_active = True

# Conditionals
if count > 5:
    print("high")
elif count > 0:
    print("low")
else:
    print("zero")

# Loops
for item in [1, 2, 3]:
    print(item)

for i in range(10):
    print(i)

# Functions
def calculate_score(base, multiplier):
    return base * multiplier

# String operations
text = "Hello World"
lower_text = text.lower()          # "hello world"
contains_hello = "hello" in lower_text  # True

# Lists
items = ["a", "b", "c"]
items.append("d")
first = items[0]

# Dictionaries
config = {"key": "value", "count": 42}
value = config["key"]
config["new_key"] = "new_value"

Key Differences from Python

OpalScript (Starlark) has some intentional limitations compared to Python:
FeatureOpalScriptPython
Import statementsNot supported (modules pre-loaded)Supported
ClassesNot supportedSupported
ExceptionsNot supported (try/except)Supported
While loopsNot supported (use for with range())Supported
Global variablesLimited mutationFull support
Standard libraryMinimalExtensive
These limitations ensure scripts are predictable, terminate reliably, and execute safely.

Quick Reference

Utility Functions (All Script Types)

ModuleFunctionDescription
accesslibcheck_access(principal, entity, [level])Check access permissions
notificationslibnotify_user(user_id, title, body)Notify a specific user via email and Slack (if configured)
notificationslibnotify_admins(title, body)Notify all Opal admins
notificationslibnotify_owner(owner_id, title, body)Notify an owner via Slack channel (if configured) or all owner members

Request Review Functions

ModuleFunctionDescription
contextget_request()Get the request being reviewed
actionsapprove([comment])Approve the request
actionsdeny(comment)Deny the request (comment required)
actionscomment(comment)Add a comment

Request Attributes

AttributeTypeAlways Present
idStringYes
reasonStringYes
requester_idStringYes
statusStringYes
target_user_idStringNo
target_group_idStringNo
requested_duration_minutesintNo
requested_resourcesListYes (may be empty)
requested_groupsListYes (may be empty)
custom_fieldsDictYes (may be empty)