Modules & projects

Organize code with import, module, and main.ny projects.

Deep dive For importing functions, structs, enums, and constants with full examples, read the Imports guide and Built-in methods.

Project layout

myapp/ main.ny ← entry point (fn main) nyra.mod ← package manifest (require / link) nyra.lock ← pinned versions nyra.sum ← checksums .nyra/cache/ ← fetched packages (after install or auto-sync) src/ helpers.ny target/ ← build output (nyra build / run) debug/main

After nyrapkg init, only main.ny, nyra.mod, nyra.lock, and nyra.sum exist. Full file roles: NyraPkg → project files.

Importing source files

Paths are relative to the file that contains the import:

import "src/helpers.ny"
import "lib/api.ny"
import { add, mul } from "src/math.ny"
import { greet as hi } from "src/helpers.ny"

Whole-module import "path" merges all pub items. Selective import { a, b } from "path" merges only those names (plus same-file helpers they need) — prefer for lean builds. Use pub / priv on functions, structs, enums, and const (default: public). Details: Imports guide → selective.

Import alias & qualified names

Rename a whole-module import and call through :: (desugars to alias__symbol):

import "src/helpers.ny" as h

fn main() {
    print(h::greet("nyra"))
}

Without as, public symbols keep their original names. priv items stay in the defining file only. For renaming a single symbol without a module prefix, use selective import: import { greet as hi } from "…".

Running a project

CommandUse when
nyra run or nyra run .Project has main.ny + optional imports
nyra build or nyra build .Emit target/debug/main
nyra build --releaseEmit optimized target/release/main
nyra run main.nySingle self-contained file only

Build artifacts

myapp/
  main.ny
  target/
    debug/main
    release/main

Run the shipped binary directly: ./target/release/main (or main.exe on Windows). Add target/ to .gitignore.

Module declaration

module github.com.you.myapp

Optional first line; pairs with nyra.mod for NyraPkg.

nyra.mod

Line-oriented project manifest (like a tiny Cargo.toml). Minimum is just module …. Full directive table: nyra.mod syntax reference.

module example.local
version 1.0.0
tls rustls                  # optional — HTTPS backend (default rustls)

require ny-sqlite ^0.1.0
require https://github.com/example/ny-lib

link sqlite3

Edit require lines by hand or via nyrapkg add. Then nyra run . auto-syncs (fetch missing packages, prune removed ones) — or run nyrapkg sync. Details: NyraPkg → manual require. TLS backends: net/http → TLS.

Quick pattern: split UI and logic

logic.nyfn compute() -> i32 { return 100 }
main.ny
import "logic.ny"
fn main() { print(compute()) }