Zamin ships with a comprehensive standard library. Built-in functions are available globally, and all other modules are available without import. This page covers every module and every function in the standard library.
Structured logging with configurable log levels. Output goes to stderr.
Functions
Function
Signature
Description
debug
logging.debug(*args)
Logs a DEBUG message (only shown if level is DEBUG).
info
logging.info(*args)
Logs an INFO message (shown at INFO level and below).
warn
logging.warn(*args)
Logs a WARN message (shown at WARN level and below).
error
logging.error(*args)
Logs an ERROR message (always shown).
set_level
logging.set_level(level)
Sets the minimum log level. Accepts: "DEBUG", "INFO", "WARN", "ERROR".
basic_config
logging.basic_config(level?)
Initializes logging with an optional level (default: DEBUG).
Examples
Zamin
logging.set_level("DEBUG");
logging.debug("Starting application");
logging.info("Server running on port 8080");
logging.warn("Disk space low");
logging.error("Connection failed");
// Output format: [timestamp][LEVEL] message
logging.set_level("WARN");
logging.debug("this is hidden");
logging.warn("this is visible");
subprocess Module
Run external commands and capture their output.
Functions
Function
Signature
Description
run
subprocess.run(cmd)
Runs cmd as a direct command. Returns a result dict with returncode, stdout, and stderr.
run_shell
subprocess.run_shell(cmd)
Runs cmd via the system shell (sh -c or cmd /C). Returns a result dict.
run_output
subprocess.run_output(cmd)
Runs cmd and returns only the stdout as a string.
run_shell_output
subprocess.run_shell_output(cmd)
Runs cmd via shell and returns only the stdout as a string.
Result Dict
Key
Type
Description
returncode
int
The exit code of the process.
stdout
string
Captured standard output.
stderr
string
Captured standard error.
Examples
Zamin
let result = subprocess.run("echo hello");
print(result["returncode"]); // 0
print(result["stdout"]); // "hello\n"
let output = subprocess.run_output("whoami");
print(output); // "current username"
let ls = subprocess.run_shell_output("ls -la");
print(ls);
let err = subprocess.run_shell("cat /nonexistent");
print(err["stderr"]); // error message
print(err["returncode"]); // non-zero
path Module
File path manipulation and filesystem operations. Paths use forward slashes internally.
Functions
Function
Signature
Description
join
path.join(*parts)
Joins path components with /.
basename
path.basename(p)
Returns the last component of a path (filename).
dirname
path.dirname(p)
Returns the directory portion of a path.
ext
path.ext(p)
Returns the file extension (without the dot).
is_file
path.is_file(p)
Returns true if p is a regular file.
is_dir
path.is_dir(p)
Returns true if p is a directory.
size
path.size(p)
Returns the file size in bytes.
rename
path.rename(old, new)
Renames/moves a file from old to new.
copy
path.copy(src, dst)
Copies a file from src to dst.
remove
path.remove(p)
Deletes the file at p.
remove_dir
path.remove_dir(p)
Recursively deletes the directory at p.
list_dir
path.list_dir(p?)
Returns a list of filenames in the directory (default: ".").
walk
path.walk(p?)
Recursively walks a directory. Returns a list of all file paths.
Unit testing utilities. Run with zamin test to execute all tests in the tests/ directory.
Functions
Function
Signature
Description
assert_eq
test.assert_eq(expected, actual, msg?)
Asserts that expected equals actual. Optional message.
assert_ne
test.assert_ne(expected, actual, msg?)
Asserts that expected is not equal to actual.
assert_true
test.assert_true(val, msg?)
Asserts that val is truthy.
assert_false
test.assert_false(val, msg?)
Asserts that val is falsy.
assert_contains
test.assert_contains(container, item, msg?)
Asserts that container (list, string, dict, or set) contains item.
assert_raises
test.assert_raises(fn, expected_msg?, args?)
Asserts that calling fn raises an error. Optionally checks the error message.
run_test
test.run_test(name, fn)
Runs a test function by name. Prints PASS or FAIL.
Examples
Zamin
func add(a, b) { return a + b; }
func divide(a, b) {
if b == 0 { throw "division by zero"; }
return a / b;
}
// Basic assertions
test.assert_eq(add(2, 3), 5, "addition works");
test.assert_eq(add(-1, 1), 0);
test.assert_ne(add(1, 1), 3);
test.assert_true(1 + 1 == 2);
test.assert_false(1 == 2);
// Contains
test.assert_contains([1, 2, 3], 2);
test.assert_contains("hello world", "world");
test.assert_contains({"a": 1}, "a");
// Raises
test.assert_raises(|| divide(1, 0), "division by zero");
// Named test runner
test.run_test("addition", func() {
test.assert_eq(add(2, 3), 5);
test.assert_eq(add(0, 0), 0);
});
time Module
Time-related functions for timestamps and delays.
Functions
Function
Signature
Description
now
time.now()
Returns the current time as a Unix timestamp with sub-second precision (float).
unix
time.unix()
Returns the current Unix timestamp as an integer (seconds since epoch).
sleep
time.sleep(ms)
Pauses execution for ms milliseconds.
Examples
Zamin
let start = time.now();
print(f"Current time: {start}"); // e.g. 1752705600.123
print(time.unix()); // e.g. 1752705600
time.sleep(1000); // sleep for 1 second
print("Resumed after 1 second");
let elapsed = time.now() - start;
print(f"Elapsed: {elapsed}s");
rand Module
Random number generation and random selection.
Functions
Function
Signature
Description
int
rand.int(min, max)
Returns a random integer between min and max (inclusive).
float
rand.float()
Returns a random float between 0.0 (inclusive) and 1.0 (exclusive).
choice
rand.choice(list)
Returns a random element from list.
Examples
Zamin
// Random integer between 1 and 100
let dice = rand.int(1, 6);
print(f"You rolled: {dice}");
// Random float [0, 1)
let r = rand.float();
print(f"Random: {r}");
// Random choice
let colors = ["red", "green", "blue"];
let pick = rand.choice(colors);
print(f"Picked: {pick}");
matrix Module
Basic matrix creation and initialization for numerical computing.
Functions
Function
Signature
Description
from_rows
matrix.from_rows(rows)
Creates a matrix from a list of rows (each row is a list of numbers).
zeros
matrix.zeros(rows, cols)
Creates a matrix filled with zeros.
ones
matrix.ones(rows, cols)
Creates a matrix filled with ones.
identity
matrix.identity(n)
Creates an n x n identity matrix.
random
matrix.random(rows, cols)
Creates a matrix with random values between 0.0 and 1.0.
Examples
Zamin
// Create from explicit rows
let m = matrix.from_rows([
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0]
]);
print(m); // matrix 2x3
// Zero and one matrices
let z = matrix.zeros(3, 3); // 3x3 matrix of zeros
let o = matrix.ones(2, 4); // 2x4 matrix of ones
// Identity matrix
let I = matrix.identity(3); // 3x3 identity matrix
// [[1, 0, 0],
// [0, 1, 0],
// [0, 0, 1]]
// Random matrix
let r = matrix.random(4, 4); // 4x4 random values