# Starlark — Configuration Language for Build Systems > A deterministic dialect of Python designed for configuration and build system definitions, used by Bazel, Buck2, and other build tools. ## Install Save as a script file and run: # Starlark — Configuration Language for Build Systems ## Quick Use ```python # BUILD file example (Bazel) load("@rules_python//python:defs.bzl", "py_binary") py_binary( name = "hello", srcs = ["hello.py"], deps = [":lib"], ) ``` ## Introduction Starlark (formerly known as Skylark) is a configuration language designed by Google for use in build systems. It is a strict subset of Python with intentional restrictions — no classes, no exceptions, no mutation after freezing — that guarantee deterministic, hermetic evaluation suitable for parallel and cached builds. ## What Starlark Does - Defines build targets, rules, and dependencies in a Python-like syntax - Guarantees deterministic evaluation for reproducible builds - Provides sandboxed execution with no file I/O or network access - Enables macro and rule authoring for custom build logic - Powers configuration in Bazel, Buck2, Pants, and other build systems ## Architecture Overview Starlark is an interpreted language with a two-phase execution model: a loading phase that evaluates BUILD files and produces a dependency graph, and an analysis phase that resolves configurations. The language is frozen after loading — all values become immutable — preventing non-determinism. Implementations exist in Go (go.starlark.net), Java (within Bazel), and Rust. ## Self-Hosting & Configuration - Used automatically when writing BUILD or .bzl files for Bazel - Go implementation available: `go get go.starlark.net/starlark` - Rust implementation: starlark-rust crate for embedding - REPL available via `starlark` command for interactive testing - Linting via Buildifier for Bazel-specific Starlark files ## Key Features - Python-like syntax with near-zero learning curve for Python developers - Guaranteed termination — no while loops or recursion allowed - Hermetic execution with no side effects or I/O - First-class functions and comprehensions for expressive configs - Parallel-safe evaluation due to immutability after load phase ## Comparison with Similar Tools - **CUE** — Stronger typing and validation; Starlark is more flexible and imperative - **Jsonnet** — Similar functional config language; Starlark has Python syntax - **Nickel** — Contract-based with gradual typing; newer and less ecosystem support - **HCL (Terraform)** — Domain-specific for infrastructure; Starlark is general-purpose for builds ## FAQ **Q: Is Starlark the same as Python?** A: No. It is a subset with no classes, exceptions, global state, or I/O. Most simple Python expressions work, but programs that depend on mutation or side effects do not. **Q: Can I use Starlark outside of Bazel?** A: Yes. The Go and Rust implementations can be embedded in any application as a configuration or scripting language. **Q: Why does Starlark forbid while loops?** A: To guarantee termination. All iteration uses for loops over finite sequences, ensuring every evaluation completes in bounded time. **Q: How do I debug Starlark code?** A: Use the print() function for logging during evaluation, or use the interactive REPL. Bazel also provides --output=starlark for query debugging. ## Sources - https://github.com/bazelbuild/starlark - https://bazel.build/rules/language --- Source: https://tokrepo.com/en/workflows/asset-3ff0e9fb Author: Script Depot