Imports
Kite's import system allows modular code organization with file and directory imports.
Import Syntax
Wildcard Import
Import all exported symbols from a file:
import * from "path/to/file.kite"Named Import
Import specific symbols:
import symbol1, symbol2 from "path/to/file.kite"File Imports
Wildcard File Import
// stdlib.kitefun double(number x) number { return x * 2}var greeting = "Hello"// main.kiteimport * from "stdlib.kite"var result = double(5) // 10var msg = greeting // "Hello"Named File Import
// mathUtils.kitefun add(number a, number b) number { return a + b }fun multiply(number a, number b) number { return a * b }var PI = 3.14159// main.kiteimport add, PI from "mathUtils.kite"var sum = add(1, 2) // add is availablevar area = PI * r * r // PI is available// multiply is NOT available (not imported)Directory Imports
Wildcard Directory Import
Import all symbols from all .kite files in a directory:
import * from "providers/networking"// Loads all .kite files in providers/networking/// Imports all symbols from all filesNamed Directory Import
Import specific symbols from a directory:
import NatGateway from "providers/networking"// Scans all .kite files in providers/networking/// Imports only the symbol named 'NatGateway'Multiple symbols:
import NatGateway, VPC, Subnet from "providers/networking"// Imports only the specified symbols// Other symbols are NOT importedPath Resolution
File vs Directory Detection
- Paths ending with
.kiteare treated as files - Paths without
.kiteextension are treated as directories
import * from "utils.kite" // File importimport * from "utils" // Directory importRelative Paths
Imports are relative to the current file:
project/├── main.kite├── utils/│ ├── helpers.kite│ └── validators.kite└── providers/ └── aws/ └── s3.kite// main.kiteimport * from "utils/helpers.kite"import S3 from "providers/aws"Importing Different Types
Functions
// math.kitefun add(number a, number b) number { return a + b }fun subtract(number a, number b) number { return a - b }// main.kiteimport add, subtract from "math.kite"var sum = add(5, 3) // 8var diff = subtract(5, 3) // 2Variables
// config.kitevar DEFAULT_PORT = 8080var DEFAULT_HOST = "localhost"// main.kiteimport DEFAULT_PORT, DEFAULT_HOST from "config.kite"resource Server web { port = DEFAULT_PORT host = DEFAULT_HOST}Schemas
// schemas/server.kiteschema ServerConfig { string name number port = 8080}// main.kiteimport ServerConfig from "schemas/server.kite"resource ServerConfig web { name = "web-server"}Components
// components/webapp.kitecomponent WebApp { input string name input number port = 8080}// main.kiteimport WebApp from "components/webapp.kite"component WebApp api { name = "api-server" port = 3000}Structs
// types/user.kitestruct User { string name string email number age}// main.kiteimport User from "types/user.kite"var user = User("John", "john@example.com", 30)Provider Imports
Import cloud provider resources:
// Import AWS provider componentsimport * from "providers/aws"resource EC2.Instance server { name = "web-server" instanceType = "t3.micro"}resource S3.Bucket storage { name = "my-bucket"}Selective provider imports:
import EC2, S3 from "providers/aws"import VPC, Subnet from "providers/aws/networking"Environment Isolation
Imported files execute in isolated environments:
// utils.kitevar internalCounter = 0fun increment() number { internalCounter++ return internalCounter}// main.kiteimport increment from "utils.kite"increment() // 1increment() // 2// internalCounter is NOT accessible hereCircular Import Detection
Kite detects circular imports at type-check time:
// a.kiteimport * from "b.kite"var fromA = "A"// b.kiteimport * from "a.kite" // ERROR: Circular import detectedvar fromB = "B"Import Caching
Parsed programs are cached to avoid re-parsing:
// Both imports share the same parsed moduleimport helper1 from "utils.kite"import helper2 from "utils.kite"Best Practices
Use Named Imports
Prefer named imports for clarity:
// Good - explicit about what's importedimport createBucket, deleteBucket from "s3Utils.kite"// Less clear - imports everythingimport * from "s3Utils.kite"Organize by Feature
project/├── main.kite├── components/│ ├── webServer.kite│ └── database.kite├── schemas/│ ├── serverConfig.kite│ └── dbConfig.kite├── utils/│ ├── helpers.kite│ └── validators.kite└── providers/ ├── aws/ └── gcp/Use Directory Imports for Related Symbols
// Import all networking componentsimport VPC, Subnet, SecurityGroup from "providers/aws/networking"Next: Learn about Decorators - metadata and constraints.