Skip to content

Best practices

Best Practices

  1. Logical Grouping: Group related configuration settings into their own configuration classes
  2. Depth Control: While you can nest configurations deeply, try to keep the structure as flat as possible for maintainability
  3. Documentation: Use help text to document the purpose of each configuration field
  4. Defaults: Provide sensible defaults where possible, especially for nested configurations
  5. Validation: Use required=True for mandatory fields in nested configurations

Feature Flags

class FeatureFlags(Configuration):
    beta_features = FieldBool(default=False)
    experimental = FieldBool(default=False)
    maintenance_mode = FieldBool(default=False)

class AppConfig(Configuration):
    features = FeatureFlags

6. Error Handling

When working with nested configurations, be aware of these common issues:

  1. Missing Values: Some fields might be unset if no default value is provided
  2. Type Mismatches: Ensure provided values match the expected types in nested structures
  3. Invalid Paths: When accessing nested values, verify the path exists to avoid errors
try:
    config = AppConfig(values={'invalid_nested_path': {'key': 'value'}})
except Exception as e:
    print(f"Configuration error: {e}")