Learn
Import Patterns
Practical patterns for module graphs, templates, imports, and missing sources.
Import Patterns
This page turns the module model into practical patterns for readers who need more than one file.
Template plus Environment
Use a base file for defaults and an environment file for overrides.
// base.pklname = "api"port = 8080replicas = 1// prod.pklamends "base.pkl"replicas = 4The CLI loads the imported source graph before typechecking or evaluation.
Named Imports
Use named imports when the imported module is a dependency, not a base template.
import "database.pkl" as dbservice { host = db.host port = db.port}Expression Imports
Use import("...") when a module value should be assigned or passed around.
database = import("database.pkl")port = database.portImport Graphs
Treat imports as a graph of reviewed source files. Keep shared constants, classes, and templates in small modules, then import them from the modules that own rendered output.
// shared.pkldefaultPort = 8080// service.pklimport "shared.pkl" as sharedport = shared.defaultPortCycles and Missing Sources
Unresolved imports and cyclic imports should be treated as source-graph errors. Fix the graph first, then debug types or output.