Skip to Content
We are live but in Staging πŸŽ‰
Scriptum LanguageInline Python

Inline Python

For the occasional transformation that is awkward to express with Scriptum’s expressions and built-ins, you can drop into Python inline with do ... with python. The code field holds the function body β€” use a triple-quoted string for readable multi-line code. The function is named handler(event, context); event carries the inputs you pass alongside code, and the return value becomes the step output. (Adapted from examples/python_normalize.scriptum.)

do "normalize text" with python code = """ import os import re def handler(event, context): text = event.get('text', '') strip = event.get('strip_punctuation', False) if strip: text = re.sub(r'[^\\w\\s]', '', text) normalized = text.strip().lower() words = [w for w in normalized.split() if w] return { "normalized": normalized, "word_count": len(words), "char_count": len(normalized), } """ text = text strip_punctuation = strip_punctuation env = { NORMALIZER_PROFILE: NORMALIZER_PROFILE } dependencies = ["regex>=2024.5.15"] timeout_ms = 20000 -> result emit "Done" normalized = result.normalized word_count = result.word_count

Notes on inline Python:

  • Inputs you list (text, strip_punctuation, …) are passed in event.
  • env = { ... } injects environment values; timeout_ms bounds runtime.
  • A dependencies list declares packages, but dependency resolution is currently limited β€” prefer the standard library and a small, well-known set of packages, and treat heavier dependency graphs as not yet reliable.

That completes the language tour. For the bigger picture β€” script, draft, version, thread β€” see Core Concepts; for the gRPC surface that creates, watches, and resumes threads, see the API Reference.