Chapter 20: Packages
Wyn has a built-in package manager - install, publish, and manage dependencies.
Installing Packages
bash
# Add a dependency (a git repo; bare names resolve to github.com/wynlang/<name>)
wyn pkg add sqlite
wyn pkg add github.com/user/[email protected]
# Install all dependencies from wyn.lock / wyn.toml
wyn pkg installwyn.toml
Every Wyn project has a wyn.toml manifest:
toml
[project]
name = "my-app"
version = "1.0.0"
entry = "src/main.wyn"
[dependencies]
sqlite = "github.com/wynlang/sqlite"
redis = "github.com/wynlang/redis"Using Packages
After installing, import and use:
wyn
// sqlite package provides Db module
var db = Db.open("app.db")
Db.exec(db, "CREATE TABLE users (name TEXT)")
Db.exec(db, "INSERT INTO users VALUES ('Alice')")
var name = Db.query_one(db, "SELECT name FROM users")
println(name) // Alice
Db.close(db)Lockfile
wyn pkg add/wyn pkg install maintain wyn.lock to pin exact versions:
# wyn.lock - resolved dependency graph (do not edit by hand)
sqlite github.com/wynlang/sqlite main a1b2c3d4...
redis github.com/wynlang/redis main e5f6g7h8...Subsequent installs use the locked versions for reproducible builds.
Official Packages
| Package | Description |
|---|---|
| sqlite | SQLite database |
| redis | Redis client |
| pg | PostgreSQL client |
| mysql | MySQL client |
| http-client | HTTP client |
| websocket | WebSocket client/server |
| jwt | JSON Web Tokens |
| base64 | Base64 encoding |
| args | CLI argument parsing |
| log | Structured logging |
| dotenv | .env file loading |
| validate | Input validation |
| cache | In-memory cache |
| retry | Retry with backoff |
| cron | Scheduled tasks |
| table | Terminal tables |
| color | Terminal colors |
| gui | Native GUI (SDL2) |
| raylib | Game development |
Creating a Package
bash
wyn init my-package --lib wyn
# Creates wyn.toml and src/Add your code to src/, write tests in tests/, push to GitHub. There is no central registry - publishing a package is pushing a repo (tag it with the wyn-package GitHub topic so wyn pkg search can find it).
Package Structure
my-package/
├── wyn.toml # Package manifest
├── src/
│ └── my_module.wyn # Source code
├── tests/
│ └── test_my_module.wyn
└── README.md