Carvel Logo

Built-in ytt Library

General modules


See @ytt:struct module docs.


load("@ytt:assert", "assert")"expected value foo, but was {}".format(value)) # stops execution
x = data.values.env.mysql_password or"missing env.mysql_password")


See Data Values reference for more details

load("@ytt:data", "data")

data.values # struct that has input values

# relative to current package
data.list()                # ["template.yml", "data/data.txt"]"data/data.txt") # "data-txt contents"

# relative to library root (available in v0.27.1+)
data.list("/")              # list files 
data.list("/data/data.txt") # read file


load("@ytt:regexp", "regexp")

regexp.match("[a-z]+[0-9]+", "__hello123__") # True

regexp.replace("[a-z]+[0-9]+", "__hello123__", "foo")                 # __foo__
regexp.replace("(?i)[a-z]+[0-9]+", "__hello123__HI456__", "bye")      # __bye__bye__
regexp.replace("([a-z]+)[0-9]+", "__hello123__bye123__", "$1")        # __hello__bye__
regexp.replace("[a-z]+[0-9]+", "__hello123__", lambda s: str(len(s))) # __8__

# example of passing the "dot matches newline" flag and using replace to extract a single match from a multiline input string
input_str = "\\ multline string\n\nconst (\n\t// Value is what we want to scrape\n\tValue = 12\n)\n\nfunc main() {..."
regexp.replace("(?s).*Value = ([0-9]+).*", input_str, "$1") # 12

See the RE2 docs for more on regex syntax. Note that flags such as multiline mode are passed in the pattern string as in the golang regexp library.

When calling replace you can pass either a string or a lambda function as the third parameter. When given a string, $ symbols are expanded, so that $1 expands to the first submatch. When given a lambda function, the match is directly replaced by the result of the function.

While match and replace are currently the only regexp verbs supported, it is possible to mimic find by using replace to replace all its input with a capture group (see example above).


load("@ytt:url", "url")

url.path_segment_encode("part part")   # "part%20part"
url.path_segment_decode("part%20part") # "part part"

url.query_param_value_encode("part part") # "part+part"
url.query_param_value_decode("part+part") # "part part"

url.query_params_encode({"x":["1"],"y":["2","3"],"z":[""]}) # "x=1&y=2&y=3&z="
url.query_params_decode("x=1&y=2&y=3;z")                    # {"x":["1"],"y":["2","3"],"z":[""]}

u = url.parse("")
u.string()                 # ""                # "alice"
u.user.password            # "secret"
u.user.string()            # "alice:secret"
u.without_user().string()  # ""


load("@ytt:version", "version") (see version module doc)

Serialization modules


load("@ytt:base64", "base64")

base64.encode("regular")      # "cmVndWxhcg=="
base64.decode("cmVndWxhcg==") # "regular"


load("@ytt:json", "json")

json.encode({"a": [1,2,3,{"c":456}], "b": "str"})
json.encode({"a": [1,2,3,{"c":456}], "b": "str"}, indent=3)


As of v0.35.0, json.encode() with indent argument encodes result in multi-line string.


load("@ytt:yaml", "yaml")

yaml.encode({"a": [1,2,3,{"c":456}], "b": "str"})

Hashing modules


load("@ytt:md5", "md5")

md5.sum("data") # "8d777f385d3dfec8815d20f7496026dc"


load("@ytt:sha256", "sha256")

sha256.sum("data") # "3a6eb0790f39ac87c94f3856b2dd2c5d110e6811602261a9a923d3bb23adc8b7"

Schema Module

See Schema specific docs.

Overlay module

See Overlay specific docs.

Library module

See Library specific docs.

Template module

See Template specific docs.