Define Configuration

In this stage, you define your configuration in Python using the Forge facade API. Because configuration is ordinary Python code, you can apply standard software engineering patterns to keep it clean, reusable, and maintainable.

This page presents common patterns, ordered from the simplest single-script approach to more structured techniques for larger projects. Choose the ones that fit your project’s size and complexity.

The examples demonstrate common patterns. They are not guaranteed to run because the Forge facade API might have evolved since this page was written.

Basic Pattern: Inline Script

The simplest approach is a single Python script that creates facade instances, sets values, and exports the result. This is appropriate for small, self-contained configurations.

from ves_socom.facades import ComDaemonFacade, CommunicationContextFacade, SubnetFacade

if __name__ == "__main__":
    daemon = ComDaemonFacade.create("my_comdaemon")
    ctx = CommunicationContextFacade.create()
    daemon.add_communication_context(ctx)

    subnet = SubnetFacade.create(
        ip_address="127.0.0.1",
        sd_ip_port=12330,
        sd_multicast_ip_address="224.0.0.17",
        communication_context=ctx,
    )
    daemon.add_subnet(subnet)
    daemon.export("./cfg")

Pattern: Named Constants

Hard-coded values scattered across a script are difficult to review and maintain. Extract all project-specific values into named constants at the top of the file. This makes every meaningful value visible in one place and easy to change.

from ves_socom.facades import ComDaemonFacade, CommunicationContextFacade, SubnetFacade

# Network configuration constants
_SUBNET_IP_ADDRESS = "127.0.0.1"
_SD_IP_PORT = 12330
_SD_MULTICAST_IP_ADDRESS = "224.0.0.17"

if __name__ == "__main__":
    daemon = ComDaemonFacade.create("my_comdaemon")
    ctx = CommunicationContextFacade.create()
    daemon.add_communication_context(ctx)

    subnet = SubnetFacade.create(
        ip_address=_SUBNET_IP_ADDRESS,
        sd_ip_port=_SD_IP_PORT,
        sd_multicast_ip_address=_SD_MULTICAST_IP_ADDRESS,
        communication_context=ctx,
    )
    daemon.add_subnet(subnet)
    daemon.export("./cfg")

Pattern: Shared Constants Across Modules

When multiple configuration scripts need the same values (for example, IP addresses shared between a daemon and a user application), define the constants in a separate module and import them.

src/constants.py
# Shared network constants for the project
SUBNET_IP_ADDRESS = "127.0.0.1"
SD_IP_PORT = 12330
SD_MULTICAST_IP_ADDRESS = "224.0.0.17"
src/my_comdaemon.py
from ves_socom.facades import ComDaemonFacade, CommunicationContextFacade, SubnetFacade
from constants import SUBNET_IP_ADDRESS, SD_IP_PORT, SD_MULTICAST_IP_ADDRESS

if __name__ == "__main__":
    daemon = ComDaemonFacade.create("my_comdaemon")
    ctx = CommunicationContextFacade.create()
    daemon.add_communication_context(ctx)

    subnet = SubnetFacade.create(
        ip_address=SUBNET_IP_ADDRESS,
        sd_ip_port=SD_IP_PORT,
        sd_multicast_ip_address=SD_MULTICAST_IP_ADDRESS,
        communication_context=ctx,
    )
    daemon.add_subnet(subnet)
    daemon.export("./cfg")

Any script that imports constants.py will automatically use the updated value when it changes.

Pattern: Factory Functions

If you create the same structure in multiple places—for example, a subnet with a fixed set of defaults—extract it into a factory function. This avoids copy-paste errors and makes the intent of each call explicit.

from ves_socom.facades import (
    ComDaemonFacade,
    CommunicationContextFacade,
    DataIpPortFacade,
    SubnetFacade,
)

from constants import SUBNET_IP_ADDRESS, SD_IP_PORT, SD_MULTICAST_IP_ADDRESS


def create_default_subnet(ctx: CommunicationContextFacade) -> SubnetFacade:
    """Create a subnet with the project's standard network settings."""
    subnet = SubnetFacade.create(
        ip_address=SUBNET_IP_ADDRESS,
        sd_ip_port=SD_IP_PORT,
        sd_multicast_ip_address=SD_MULTICAST_IP_ADDRESS,
        communication_context=ctx,
    )
    subnet.add_data_ip_port(DataIpPortFacade.create(daemon_context=ctx))
    return subnet


if __name__ == "__main__":
    daemon = ComDaemonFacade.create("my_comdaemon")
    ctx = CommunicationContextFacade.create()
    daemon.add_communication_context(ctx)
    daemon.add_subnet(create_default_subnet(ctx))
    daemon.export("./cfg")

Pattern: Custom Facade by Inheritance

For larger projects, you may want to create a project-specific facade that encapsulates your team’s conventions and hides configuration details that never change. Subclass the Forge facade and override or extend it.

from ves_socom.facades import ComDaemonFacade, CommunicationContextFacade, SubnetFacade
from constants import SUBNET_IP_ADDRESS, SD_IP_PORT, SD_MULTICAST_IP_ADDRESS


class ProjectComDaemonFacade(ComDaemonFacade):
    """Project-specific ComDaemon facade with standard network defaults pre-applied."""

    @classmethod
    def create_with_defaults(cls, name: str) -> "ProjectComDaemonFacade":
        daemon = cls.create(name)
        ctx = CommunicationContextFacade.create()
        daemon.add_communication_context(ctx)

        subnet = SubnetFacade.create(
            ip_address=SUBNET_IP_ADDRESS,
            sd_ip_port=SD_IP_PORT,
            sd_multicast_ip_address=SD_MULTICAST_IP_ADDRESS,
            communication_context=ctx,
        )
        daemon.add_subnet(subnet)
        return daemon


if __name__ == "__main__":
    daemon = ProjectComDaemonFacade.create_with_defaults("my_comdaemon")
    # apply any project-specific overrides here
    daemon.export("./cfg")

Using inheritance keeps individual configuration scripts short and focused on what varies between Configurable Units, while the shared logic lives in one place.

Pattern: Parameterized Scripts

Configuration often differs between build variants (for example, development vs. production) or deployment targets. Rather than maintaining separate scripts, accept parameters at the command line and branch on them.

import argparse
from ves_socom.facades import ComDaemonFacade, CommunicationContextFacade, SubnetFacade

_NETWORK_PROFILES = {
    "dev":  {"ip": "127.0.0.1",   "sd_port": 12330, "multicast": "224.0.0.17"},
    "prod": {"ip": "192.168.1.10", "sd_port": 30490, "multicast": "239.192.255.250"},
}

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--profile", choices=_NETWORK_PROFILES.keys(), default="dev")
    parser.add_argument("--output", default="./cfg")
    args = parser.parse_args()

    profile = _NETWORK_PROFILES[args.profile]
    daemon = ComDaemonFacade.create("my_comdaemon")
    ctx = CommunicationContextFacade.create()
    daemon.add_communication_context(ctx)

    subnet = SubnetFacade.create(
        ip_address=profile["ip"],
        sd_ip_port=profile["sd_port"],
        sd_multicast_ip_address=profile["multicast"],
        communication_context=ctx,
    )
    daemon.add_subnet(subnet)
    daemon.export(args.output)

Run it as:

uv run ./src/my_comdaemon.py --profile prod --output ./cfg/prod