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
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 |
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) |

