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:
| Feature | OpalScript | Python |
|---|
| Import statements | Not supported (modules pre-loaded) | Supported |
| Classes | Not supported | Supported |
| Exceptions | Not supported (try/except) | Supported |
| While loops | Not supported (use for with range()) | Supported |
| Global variables | Limited mutation | Full support |
| Standard library | Minimal | Extensive |
These limitations ensure scripts are predictable, terminate reliably, and execute safely.
Quick Reference
Utility Functions (All Script Types)
| Module | Function | Description |
|---|
| accesslib | check_access(principal, entity, [level]) | Check access permissions |
| notificationslib | notify_user(user_id, title, body) | Notify a specific user via email and Slack (if configured) |
| notificationslib | notify_admins(title, body) | Notify all Opal admins |
| notificationslib | notify_owner(owner_id, title, body) | Notify an owner via Slack channel (if configured) or all owner members |
Request Review Functions
| Module | Function | Description |
|---|
| context | get_request() | Get the request being reviewed |
| actions | approve([comment]) | Approve the request |
| actions | deny(comment) | Deny the request (comment required) |
| actions | comment(comment) | Add a comment |
Request Attributes
| Attribute | Type | Always Present |
|---|
id | String | Yes |
reason | String | Yes |
requester_id | String | Yes |
status | String | Yes |
target_user_id | String | No |
target_group_id | String | No |
requested_duration_minutes | int | No |
requested_resources | List | Yes (may be empty) |
requested_groups | List | Yes (may be empty) |
custom_fields | Dict | Yes (may be empty) |
Last modified on February 20, 2026