Skip to main content

Overview

The configuration module provides utilities for reading and writing TOML configuration files, particularly for managing Flower and Syft-Flwr project metadata.

Functions

load_flwr_pyproject

Load and validate a Flower project’s pyproject.toml file.
def load_flwr_pyproject(
    path: Path,
    check_module: bool = True
) -> dict

Parameters

path
Path
required
Path to the project directory or pyproject.toml file. If a directory is provided, it will automatically look for pyproject.toml inside.
check_module
bool
default:"True"
Whether to validate that the module references in the configuration exist. Set to False to skip module validation (useful during testing or parallel execution).

Returns

pyproject
dict
Parsed and validated pyproject.toml configuration as a dictionary.

Usage Example

From run.py:22-25:
from syft_flwr.config import load_flwr_pyproject
from pathlib import Path

flower_project_dir = Path("./fl-diabetes-prediction")
pyproject_conf = load_flwr_pyproject(flower_project_dir)

# Access configuration values
client_ref = pyproject_conf["tool"]["flwr"]["app"]["components"]["clientapp"]
server_ref = pyproject_conf["tool"]["flwr"]["app"]["components"]["serverapp"]
app_name = pyproject_conf["tool"]["syft_flwr"]["app_name"]
datasites = pyproject_conf["tool"]["syft_flwr"]["datasites"]
aggregator = pyproject_conf["tool"]["syft_flwr"]["aggregator"]

Exceptions

Exception
Raised if the configuration is invalid or module references cannot be found (when check_module=True).

load_toml

Load any TOML file into a dictionary.
def load_toml(path: str) -> dict

Parameters

path
str
required
Path to the TOML file to load.

Returns

config
dict
Parsed TOML file as a dictionary.

Usage Example

from syft_flwr.config import load_toml

config = load_toml("./config.toml")
print(config["section"]["key"])

write_toml

Write a dictionary to a TOML file.
def write_toml(path: str, val: dict) -> None

Parameters

path
str
required
Path to the TOML file to write.
val
dict
required
Dictionary to serialize and write to the TOML file.

Returns

None - The function writes to the file in place.

Usage Example

From bootstrap.py:83:
from syft_flwr.config import write_toml

pyproject_conf = {
    "tool": {
        "syft_flwr": {
            "app_name": "ds@example.com_my-project_1234567890",
            "datasites": ["do1@example.com", "do2@example.com"],
            "aggregator": "ds@example.com",
            "transport": "syftbox"
        }
    }
}

write_toml("./pyproject.toml", pyproject_conf)

Configuration Structure

After bootstrapping, your pyproject.toml will contain both Flower and Syft-Flwr configurations:

Flower Configuration

[tool.flwr.app.components]
serverapp = "your_project.server_app:app"
clientapp = "your_project.client_app:app"

[tool.flwr.app.config]
partition-id = 0
num-partitions = 1

Syft-Flwr Configuration

[tool.syft_flwr]
app_name = "ds@openmined.org_fl-diabetes-prediction_1753435643"
datasites = [
    "do1@openmined.org",
    "do2@openmined.org",
]
aggregator = "ds@openmined.org"
transport = "syftbox"  # or "p2p"

Project Dependencies

[project]
name = "fl-diabetes-prediction"
dependencies = [
    "flwr>=1.0.0",
    "syft_flwr==0.1.0",  # Added automatically by bootstrap
    # ... other dependencies
]

Transport Types

syftbox
string
Default for local/server environmentsUses local SyftBox file synchronization with RPC and end-to-end encryption. Best for:
  • Local development and testing
  • Server deployments with SyftBox installed
  • Maximum security with E2E encryption
p2p
string
Default for Google ColabUses peer-to-peer synchronization via cloud storage (Google Drive/OneDrive). Best for:
  • Google Colab environments
  • Remote collaboration without SyftBox
  • Cloud-based deployments

Validation

The load_flwr_pyproject function validates:
  1. File existence - pyproject.toml must exist
  2. Required sections - Must have [tool.flwr.app] configuration
  3. Component references - serverapp and clientapp must be valid Python module paths
  4. Module availability - Referenced modules must be importable (when check_module=True)

Notes

  • Configuration files are written in binary mode for proper TOML encoding
  • Validation warnings are logged but don’t prevent loading
  • Module checking can be disabled for faster loading during testing

Build docs developers (and LLMs) love