Language

Modules and imports

Each .vary file is a module and directories are packages. You use imports to pull in functions, classes, and other definitions. The compiler resolves the full dependency graph at compile time.

For how project modules and bundled libraries relate to the standard library, built-ins, and DSLs, see Language surfaces.

main.vary orders.vary pricing.vary utils/format.vary stdlib: time stdlib: json
main.vary orders.vary pricing.vary utils/format.vary stdlib: time stdlib: json

When the type checker encounters an import, it recursively compiles the imported module first, extracts its public signatures, and only then continues checking the importer. A topological walk of this graph gives the load order: leaves first, then their parents, and so on up to the entry file.

The prelude

A small set of types and functions is available in every file without imports. Everything else requires an explicit import statement.

Prelude types (always available):

CategoryTypes
PrimitivesInt, Float, Bool, Str, None
CollectionsList, Dict, Set
ResultsResult, Ok, Err
SpecialNever

Prelude functions (always available): print, input, len, str, int, float, bool, range, abs, min, max, sorted, map, filter, reduce, any, all, sum, and others.

Non-prelude types require imports. If you use Json, Path, Clock, Rng, Decimal, or any other stdlib type, you must import the owning module. The compiler tells you which module to import:

error: Type 'Json' requires 'import json'

Common imports:

TypeRequired import
Json, JsonValue, JsonErrorimport json
Decoder, DecodeErrorimport json
Pathimport path
ReadPath, WritePath, DirPathimport fs
Clock, Duration, Date, Instantimport time
Rngimport random
TemplateEngine, TemplateErrorimport template
HttpResponse, HttpErrorimport http
Decimalimport decimal
Moneyimport money
Urlimport url
CryptoHashimport crypto
Command, ProcessResultimport process

This makes dependencies visible: you can tell which modules a file uses by reading its import block.

Imports

import math_utils
import math_utils as m
from math_utils import square, cube
from math_utils import square as sq

Modules are files. A file math_utils.vary defines module math_utils.

Access control

Names starting with _ are private and not exported:

def public_func() -> Int {
    return _helper()
}

def _helper() -> Int {
    return 42
}

Controlling exports

By default, all non-underscore names are exported. Use __all__ to restrict:

let __all__ = ["public_func", "CONSTANT"]

def public_func() -> Int {
    return 42
}

def internal_func() -> Int {
    return 0
}

let CONSTANT: Int = 100

Only public_func and CONSTANT are importable from this module.

Relative imports

Use dots to import relative to the current file's directory:

from .sibling import helper          # same directory
from ..parent_module import Config   # parent directory
from .subpkg.util import format      # subdirectory

One dot (.) means the current directory, two dots (..) means the parent, and so on. Relative imports only resolve within the project - they cannot escape the module root.

Module root discovery

An explicit --module-root takes precedence, followed by source roots configured in the project's vary.toml, then the importing file's directory. Configuration discovery may find an ancestor vary.toml; module lookup does not search arbitrary ancestor directories. Without configuration, the entry file's directory is the module root. Stdlib lookup follows project lookup for ordinary names.

Bundled library namespaces

The CLI bundles libraries listed in its libraries/catalog.toml. The current catalog includes ai. Import its namespace directly, for example from ai.context import AiContext. Bundled libraries are ordinary Vary source, separate from the standard library, and use the CLI's release version.

The compiler loads the catalog from its own installation and compiles only what you import. VARY_STDLIB does not change this lookup. If your project also defines an ai module or directory, rename it or remove the old library source root: the compiler rejects the collision rather than choosing one. An incomplete installation reports the missing module and searched paths.

← Readable blocks
Concurrency →