Skip to content

Config Manager

Xellu edited this page May 29, 2026 · 4 revisions

The config manager uses TOML configuration files for your project and services.

from nautica import Config, ConfigBuilder

Built-in Configs

Nautica creates two config files at the root of your project automatically:

File ID Description
config.n3 nautica Core Nautica settings
package.n3 package Project metadata

These are the only configs that live at the project root. All other configs are created under config/.

Reading Values

Use dotted key paths to read values from a config:

Config("nautica")["nautica.debug"] # True/False
Config("nautica")["http.port"] # 8100
Config("nautica")["http.static.directory"] # /path/to/directory

You can also call it directly:

Config("nautica")("http.port") # same as above

Both return None if the key doesn't exist

Writing Values

Config("nautica")["http.port"] = 9000

Changes are saved automatically.

ConfigBuilder

ConfigBuilder is used to define config keys with default values and optional comments:

ConfigBuilder()
    .add("key", default_value, comment="Optional comment")
    .build()

Keys use dot notation to define nested TOML tables:

ConfigBuilder()
    .add("database.host", "127.0.0.1", comment="Database host")
    .add("database.port", 5432)
    .add("database.name", "mydb")
    .build()

Turns into:

[database]
host = "127.0.0.1" # Database host
port = 5432
name = "mydb"

Creating a Config

Services can register their own config files using Config.New(). This should be done in onInstall():

from nautica import Service, Config, ConfigBuilder

class MyService(Service):
    def onInstall(self):
        Config.New("myservice",
            ConfigBuilder()
                .add("myservice.enabled", True, comment="Enable MyService")
                .add("myservice.host", "127.0.0.1")
                .add("myservice.port", 8200)
                .build()
        )

This creates config/myservice.toml with the defined keys and values. If the file already exists, missing keys are added without overwriting existing values.

Updating a Config

Use Config.Update() to add keys to an existing config without replacing it. This is useful for built-in configs like nautica that multiple services contribute to:

class MyService(Service):
    def onInstall(self):
        Config.Update("nautica",
            ConfigBuilder()
                .add("services.myservice", True, comment="Enable MyService")
                .build()
        )

Use Config.New() for your own config files, and Config.Update() when adding keys to an existing one like nautica.

Clone this wiki locally