Skip to content

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 install

wyn.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

PackageDescription
sqliteSQLite database
redisRedis client
pgPostgreSQL client
mysqlMySQL client
http-clientHTTP client
websocketWebSocket client/server
jwtJSON Web Tokens
base64Base64 encoding
argsCLI argument parsing
logStructured logging
dotenv.env file loading
validateInput validation
cacheIn-memory cache
retryRetry with backoff
cronScheduled tasks
tableTerminal tables
colorTerminal colors
guiNative GUI (SDL2)
raylibGame 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

MIT License - v1.19.1