Skip to main content
Documentation

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.kite
fun double(number x) number {
    return x * 2
}

var greeting = "Hello"
// main.kite
import * from "stdlib.kite"

var result = double(5)  // 10
var msg    = greeting      // "Hello"

Named File Import

// mathUtils.kite
fun add(number a, number b) number { return a + b }
fun multiply(number a, number b) number { return a * b }
var PI = 3.14159
// main.kite
import add, PI from "mathUtils.kite"

var sum  = add(1, 2)     // add is available
var 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 files

Named 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 imported

Path Resolution

File vs Directory Detection

  • Paths ending with .kite are treated as files
  • Paths without .kite extension are treated as directories
import * from "utils.kite"     // File import
import * from "utils"          // Directory import

Relative Paths

Imports are relative to the current file:

project/
├── main.kite
├── utils/
│   ├── helpers.kite
│   └── validators.kite
└── providers/
    └── aws/
        └── s3.kite
// main.kite
import * from "utils/helpers.kite"
import S3 from "providers/aws"

Importing Different Types

Functions

// math.kite
fun add(number a, number b) number { return a + b }
fun subtract(number a, number b) number { return a - b }
// main.kite
import add, subtract from "math.kite"

var sum  = add(5, 3)       // 8
var diff = subtract(5, 3) // 2

Variables

// config.kite
var DEFAULT_PORT = 8080
var DEFAULT_HOST = "localhost"
// main.kite
import DEFAULT_PORT, DEFAULT_HOST from "config.kite"

resource Server web {
    port = DEFAULT_PORT
    host = DEFAULT_HOST
}

Schemas

// schemas/server.kite
schema ServerConfig {
    string name
    number port = 8080
}
// main.kite
import ServerConfig from "schemas/server.kite"

resource ServerConfig web {
    name = "web-server"
}

Components

// components/webapp.kite
component WebApp {
    input string name
    input number port = 8080
}
// main.kite
import WebApp from "components/webapp.kite"

component WebApp api {
    name = "api-server"
    port = 3000
}

Structs

// types/user.kite
struct User {
    string name
    string email
    number age
}
// main.kite
import User from "types/user.kite"

var user = User("John", "john@example.com", 30)

Provider Imports

Import cloud provider resources:

// Import AWS provider components
import * 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.kite
var internalCounter = 0

fun increment() number {
    internalCounter++
    return internalCounter
}
// main.kite
import increment from "utils.kite"

increment()  // 1
increment()  // 2

// internalCounter is NOT accessible here

Circular Import Detection

Kite detects circular imports at type-check time:

// a.kite
import * from "b.kite"
var fromA = "A"

// b.kite
import * from "a.kite"  // ERROR: Circular import detected
var fromB = "B"

Import Caching

Parsed programs are cached to avoid re-parsing:

// Both imports share the same parsed module
import helper1 from "utils.kite"
import helper2 from "utils.kite"

Terraform Provider Imports

Use the tf/ prefix to import types from any Terraform provider:

import Instance, Vpc from "tf/aws"
import Monitor from "tf/datadog"
import Zone from "tf/cloudflare"

Type names are automatically converted from Terraform's snake_case to Kite's PascalCase. See Terraform Bridge for full documentation.

Best Practices

Use Named Imports

Prefer named imports for clarity:

// Good - explicit about what's imported
import createBucket, deleteBucket from "s3Utils.kite"

// Less clear - imports everything
import * 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/
// Import all networking components
import VPC, Subnet, SecurityGroup from "providers/aws/networking"

Next: Learn about Decorators - metadata and constraints.