# Modules & imports

> Importing standard-library and local modules in Langoost — namespace imports, named imports, sub-module access, and module resolution order.

# Modules & imports

## Namespace import

Import an entire module under its name and access members with a dot:

```goost
import strings
import math

strings.upper("hello")    // "HELLO"
math.sqrt(16.0)           // 4.0
```

## Named import

Import specific exports directly into scope:

```goost
import { abs, sqrt, PI } from "math"

println(sqrt(PI))
```

## Sub-modules

Many modules are organized into sub-modules, reached with further dot access
after importing the parent:

```goost
import time
import net
import thread

time.clock.now()                    // current time, RFC3339
net.tcp.connect("localhost", 8080)
thread.mutex.new()
```

## Local modules

Any `.goost` file is a module. Import it by name (without the extension) to use
its top-level functions:

```goost
// math_utils.goost defines fn clamp(...)
import math_utils

println(math_utils.clamp(15, 0, 10))   // 10
```

## Resolution order

When you `import name`, Langoost resolves it in this order:

1. **Standard-library modules** — always checked first; stdlib names cannot be
   shadowed by local files.
2. **Installed packages** — `./langoost_modules/` (so installed deps win over
   ambient files). See [Packages](#packages).
3. **Filesystem** — the directory of the script being run, then the current
   working directory.

## Packages

Langoost has a simple package manager. Declare dependencies in a
`langoost.json` manifest:

```json
{
  "name": "myapp",
  "version": "0.1.0",
  "dependencies": {
    "router": "github:someone/langoost-router",
    "shared": "file:../shared",
    "json2":  "https://example.com/json2.tar.gz"
  }
}
```

Then run `langoost install` (see the **[CLI reference](/docs/cli#install)**),
which fetches each dependency into `./langoost_modules/<name>/`. Dependency
sources can be:

- **Git** — `git+https://…` or the `github:user/repo` shorthand
- **Local paths** — `file:../path/to/pkg`
- **HTTPS archives** — a `.tar.gz` or `.zip` URL

Transitive dependencies are resolved from each package's own manifest. Once
installed, `import "name"` finds the package by trying `<name>.goost`,
`<name>/main.goost`, then `<name>/<name>.goost`.

There is no semver resolution or lockfile yet — it's a pragmatic
share-the-code workflow.

## Module cache

Compiled modules are cached by absolute path and modification time. After the
first import, unchanged modules are served from cache as a map lookup — no
recompilation. In long-running server mode this keeps imports effectively free.

Browse everything available out of the box in the
**[standard library](/docs/stdlib)**.