Export Configuration

In this stage, you export your in-memory Forge configuration to JSON files that the code generator and the target device can consume.

Forge provides three ways to export configuration, ranging from a one-line convenience call to a fully explicit batch export. All approaches produce the same output format: one JSON file per configuration schema, written to a directory you specify.

This page covers the common export patterns. For the complete API reference, return type details, and advanced options, refer to the fsp-config-foundation documentation.

Output Layout

Every export operation writes one JSON file per configuration pillar schema into the output folder:

output/
    ApiSchemaClassName.json
    ImplementationSchemaClassName.json
    RuntimeSchemaClassName.json

Re-running an export overwrites existing files with matching names. Files from a previous run that are no longer produced are left untouched. Remove the output folder first if you need a fully clean snapshot.

Option 1: Export Directly from the Facade

The simplest approach. Every facade provides an export() convenience method.

# Export a single ConfigUnit to a folder
daemon.export("./cfg/my_comdaemon")

This is equivalent to calling ExportTool.export_config_unit() and is the recommended approach for scripts that export a single Configurable Unit.

Option 2: Export with ExportTool

Use ExportTool when you need more control or want to handle the export result programmatically. ExportTool operates on ConfigUnitFacade instances—pass the facade object directly, not the underlying data model. The return value is an ExportedFiles mapping from file stem to the JSON string written to disk.

Export a Single Configurable Unit

from fsp_config_foundation.export_tool import ExportTool

tool = ExportTool()
exported = tool.export_config_unit(daemon, "./cfg/my_comdaemon")

# Inspect what was written
for file_stem, json_content in exported.items():
    print(f"Written: {file_stem}.json")

Export Multiple Configurable Units in One Call

When your script produces several Configurable Units, export them all at once with export_config_units(). Each Configurable Unit is written into its own subfolder under a shared root.

from fsp_config_foundation.export_tool import ExportTool

tool = ExportTool()
result = tool.export_config_units(
    [daemon, user_app, diagnostics_manager],
    "./cfg",
)

# result is a dict: subfolder name -> ExportedFiles
for folder_name, files in result.items():
    print(f"{folder_name}: {list(files.keys())}")

Output layout for a batch export:

cfg/
    my_comdaemon/
        ApiSchemaClassName.json
        RuntimeSchemaClassName.json
    my_userapp/
        ApiSchemaClassName.json
    my_diagnostics_manager/
        ImplementationSchemaClassName.json
        RuntimeSchemaClassName.json

Subfolder names are derived from the Configurable Unit name set when calling <Facade>.create(name). When names are not unique within a single call, suffixes are appended automatically (name, name_1, name_2, …​).

Reuse one ExportTool instance when exporting many Configurable Units in the same script. Keep Configurable Unit names stable so the subfolder names remain predictable across runs.

Error Handling

All export methods raise RuntimeError for filesystem failures (for example, insufficient permissions or a full disk). They raise ValueError for invalid arguments such as an empty output path.

A minimal error-handling wrapper:

try:
    daemon.export("./cfg/my_comdaemon")
except ValueError as e:
    print(f"Invalid export arguments: {e}")
except RuntimeError as e:
    print(f"Export failed: {e}")