Configuration & Settings
Relevant source files
The following files were used as context for generating this wiki page:
The FLEXT gRPC platform employs a type-safe, centralized configuration management system built on Pydantic and the FLEXT ecosystem patterns. It provides a multi-layered approach to settings, ranging from high-level convenience fields to granular nested configurations for network, security, performance, streaming, and monitoring. This system ensures that all gRPC components—servers, clients, and channels—operate within validated boundaries defined by environment variables or programmatic overrides.
The configuration architecture is primarily anchored in the FlextGrpcSettings class, which extends FlextSettingsBase. It serves as the single source of truth for the runtime environment, integrating with environment variables prefixed with FLEXT_GRPC_ and providing factory methods for environment-specific setups such as production or development.
Sources: src/flext_grpc/settings.py:17-31, src/flext_grpc/README.md:104-121, src/README.md:154-159
Configuration Architecture
The configuration system is structured into several specialized nested models, providing separation of concerns for different aspects of the gRPC infrastructure.
Component Structure
The diagram shows the hierarchical relationship between the main settings class and its specialized sub-configurations.
Sources: src/flext_grpc/settings.py:33-72, tests/unit/test_config.py:91-115
Key Configuration Categories
Network and General Settings
General settings provide flat convenience fields that sync with deeper nested configurations. These include standard network identifiers like host and port, as well as operational defaults.
| Option | Type | Default Value | Description |
|---|---|---|---|
host | str | c.Grpc.NETWORK_DEFAULT_HOST | The network address to bind or connect to. |
port | PortNumber | c.Grpc.NETWORK_DEFAULT_GRPC_PORT | The port for gRPC communication. |
max_workers | WorkerCount | c.Grpc.SERVICE_MAX_WORKERS | Number of worker threads for the server. |
timeout | PositiveTimeout | c.Grpc.NETWORK_DEFAULT_TIMEOUT | Default operation timeout in seconds. |
Sources: src/flext_grpc/settings.py:40-53, tests/unit/test_config.py:41-47
Security Configuration
The security layer manages TLS/SSL settings. It includes validation logic to ensure that advanced features, like client certificate requirements, are only enabled when the underlying TLS transport is active.
- TLS Enabled: Computed property reflecting
security.tls_enabled. - Validation:
validate_configuration()returns a failure ifclient_cert_requiredis True whiletls_enabledis False.
Sources: src/flext_grpc/settings.py:74-79, src/flext_grpc/settings.py:86-101, tests/unit/test_config.py:82-95
Performance and Streaming
Performance settings control the resource utilization of the gRPC server, including concurrency limits and message size constraints. Streaming settings manage the lifecycle and buffers for gRPC streams.
- Max Concurrent RPCs: Defaults to 1000.
- Max Receive Message Length: Defaults to 4 MB.
- Streaming Buffer Size: Defaults to 500 items.
- Max Stream Duration: Defaults to 300 seconds.
Sources: tests/unit/test_config.py:97-111, src/flext_grpc/settings.py:64-69
Environment Management
The system provides pre-configured factory methods to simplify setup for different deployment stages.
This flow illustrates how the platform differentiates between development and production setups through factory methods.
Factory Methods
create_production_config(): Returns a configuration with TLS enabled by default.create_development_config(): Returns a configuration targeting the loopback IP (127.0.0.1) without strict security requirements for ease of testing.
Sources: src/flext_grpc/settings.py:103-128, tests/unit/test_config.py:59-67
Usage Patterns
Configuration is typically instantiated through the FlextGrpc facade or by direct model validation of a dictionary (often loaded from environment variables).
# Example: Custom configuration initialization
custom_config = FlextGrpcSettings.model_validate({
"network": {"host": "example.com", "port": 9090},
"performance": {"max_workers": 20},
})
# Example: Accessing computed properties
is_secure = custom_config.tls_enabled
is_streaming = custom_config.streaming_enabled
Sources: examples/01_basic_usage.py:55-62, src/flext_grpc/settings.py:74-84
Validation Logic
The validate_configuration method ensures the internal consistency of settings before they are applied to runtime components.
The sequence demonstrates the guard logic used to prevent insecure configurations during initialization.
Sources: src/flext_grpc/settings.py:86-101, tests/unit/test_config.py:87-95
Conclusion
The Configuration & Settings module provides a robust, schema-driven foundation for the FLEXT gRPC platform. By leveraging Pydantic for validation and nested models for organization, it allows developers to manage complex gRPC parameters—from networking to deep security protocols—with type safety and clarity. The integration of environment-specific factories and comprehensive validation rules ensures that configurations are not only flexible but also inherently secure and operationally sound.