Skip to content

Package Inputs

Most real packages need to accept input and expose multiple functions. This tutorial covers both.

When Brane calls a function in your package, it passes input values via environment variables. The variable names match the input parameter names directly.

For example, if your function declares an input called text, Brane sets the environment variable text to the provided value.

Let’s build a package with two functions: encode and decode.

Create base64_tool.py:

#!/usr/bin/env python3
import base64
import os
import sys
import yaml
def encode():
text = os.environ.get("text", "")
encoded = base64.b64encode(text.encode()).decode()
return {"encoded": encoded}
def decode():
text = os.environ.get("text", "")
decoded = base64.b64decode(text.encode()).decode()
return {"decoded": decoded}
if __name__ == "__main__":
# Brane passes the function name as the first argument
command = sys.argv[1] if len(sys.argv) > 1 else ""
if command == "encode":
result = encode()
elif command == "decode":
result = decode()
else:
print(f"Unknown command: {command}", file=sys.stderr)
sys.exit(1)
print(yaml.dump(result, default_flow_style=True).strip())

The key pattern:

  1. Read sys.argv[1] to determine which function was called
  2. Read inputs from environment variables
  3. Print the result as YAML to stdout

Create container.yml:

name: base64_tool
version: 1.0.0
kind: ecu
dependencies:
- python3
- python3-yaml
files:
- base64_tool.py
entrypoint:
kind: task
exec: base64_tool.py
actions:
'encode':
command:
args:
- encode
input:
- name: text
type: string
output:
- name: encoded
type: string
'decode':
command:
args:
- decode
input:
- name: text
type: string
output:
- name: decoded
type: string

Key differences from the hello-world package:

  • Two actions (encode and decode) instead of one
  • command.args passes the function name as a command-line argument
  • input declares the expected parameters with their types
  • Each action has its own output with a corresponding YAML key
Terminal window
brane package build ./container.yml
brane package test base64_tool

Select the encode function, enter some text, and verify the output.

import base64_tool;
let encoded := encode("Hello, Brane!");
println(encoded);
let decoded := decode(encoded);
println(decoded);
TypeBraneScriptDescription
string"text"Text values
integer42Whole numbers
real3.14Floating-point numbers
booleantrue / falseBoolean values
Array[T][1, 2, 3]Arrays of a single type
  • Always handle missing or empty environment variables gracefully
  • Use YAML for output — Brane expects it
  • Test each function locally before pushing
  • Keep packages focused: one package per related group of functions