whylogs_container.whylabs.container.server_config

Functions

Classes

CustomSettingsSource(settings_cls[, ...])

SecretsConfig([_case_sensitive, ...])

SecretsFile(*[, whylabs_api_key, ...])

ServerConfig([_case_sensitive, ...])

This class has all of the configuration options for the container.

class whylogs_container.whylabs.container.server_config.CustomSettingsSource(settings_cls: type[BaseSettings], case_sensitive: bool | None = None, env_prefix: str | None = None, env_nested_delimiter: str | None = None, env_ignore_empty: bool | None = None, env_parse_none_str: str | None = None, env_parse_enums: bool | None = None)

Bases: EnvSettingsSource

prepare_field_value(field_name: str, field: FieldInfo, value: Any, value_is_complex: bool) Any

Prepare value for the field.

  • Extract value for nested field.

  • Deserialize value to python object for complex field.

Args:

field: The field. field_name: The field name.

Returns:

A tuple contains prepared value for the field.

Raises:

ValuesError: When There is an error in deserializing value for complex field.

class whylogs_container.whylabs.container.server_config.SecretsConfig(_case_sensitive: bool | None = None, _nested_model_default_partial_update: bool | None = None, _env_prefix: str | None = None, _env_file: DotenvType | None = PosixPath('.'), _env_file_encoding: str | None = None, _env_ignore_empty: bool | None = None, _env_nested_delimiter: str | None = None, _env_parse_none_str: str | None = None, _env_parse_enums: bool | None = None, _cli_prog_name: str | None = None, _cli_parse_args: bool | list[str] | tuple[str, ...] | None = None, _cli_settings_source: CliSettingsSource[Any] | None = None, _cli_parse_none_str: str | None = None, _cli_hide_none_type: bool | None = None, _cli_avoid_json: bool | None = None, _cli_enforce_required: bool | None = None, _cli_use_class_docs_for_groups: bool | None = None, _cli_exit_on_error: bool | None = None, _cli_prefix: str | None = None, _cli_implicit_flags: bool | None = None, _secrets_dir: PathType | None = None, *, secrets_path_files: str = '/var/run/secrets/whylabs.ai/env', secrets_path_json: str = '/var/run/secrets/whylabs.ai/env/guardrails.json')

Bases: BaseSettings

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[SettingsConfigDict] = {'arbitrary_types_allowed': True, 'case_sensitive': False, 'cli_avoid_json': False, 'cli_enforce_required': False, 'cli_exit_on_error': True, 'cli_hide_none_type': False, 'cli_implicit_flags': False, 'cli_parse_args': None, 'cli_parse_none_str': None, 'cli_prefix': '', 'cli_prog_name': None, 'cli_settings_source': None, 'cli_use_class_docs_for_groups': False, 'env_file': None, 'env_file_encoding': None, 'env_ignore_empty': True, 'env_nested_delimiter': None, 'env_parse_enums': None, 'env_parse_none_str': None, 'env_prefix': '', 'extra': 'forbid', 'frozen': True, 'json_file': None, 'json_file_encoding': None, 'nested_model_default_partial_update': False, 'protected_namespaces': ('model_', 'settings_'), 'secrets_dir': None, 'toml_file': None, 'validate_default': True, 'yaml_file': None, 'yaml_file_encoding': None}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'secrets_path_files': FieldInfo(annotation=str, required=False, default='/var/run/secrets/whylabs.ai/env'), 'secrets_path_json': FieldInfo(annotation=str, required=False, default='/var/run/secrets/whylabs.ai/env/guardrails.json')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

secrets_path_files: str

This is the path to the root of the secret dir. This applies when using individual secret files rather than a single json file for all secrets. Non secrets can be loaded from this path as well.

secrets_path_json: str

The path to the secrets json file. This applies when using a single json file for all secrets. This file contains the secrets for the container where the following options can be loaded from:

  • WHYLABS_API_KEY

  • CONTAINER_PASSWORD

class whylogs_container.whylabs.container.server_config.SecretsFile(*, whylabs_api_key: str | None = None, container_password: str | None = None)

Bases: BaseModel

container_password: str | None
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'env_ignore_empty': True, 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'container_password': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'whylabs_api_key': FieldInfo(annotation=Union[str, NoneType], required=False, default=None)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

whylabs_api_key: str | None
class whylogs_container.whylabs.container.server_config.ServerConfig(_case_sensitive: bool | None = None, _nested_model_default_partial_update: bool | None = None, _env_prefix: str | None = None, _env_file: DotenvType | None = PosixPath('.'), _env_file_encoding: str | None = None, _env_ignore_empty: bool | None = None, _env_nested_delimiter: str | None = None, _env_parse_none_str: str | None = None, _env_parse_enums: bool | None = None, _cli_prog_name: str | None = None, _cli_parse_args: bool | list[str] | tuple[str, ...] | None = None, _cli_settings_source: CliSettingsSource[Any] | None = None, _cli_parse_none_str: str | None = None, _cli_hide_none_type: bool | None = None, _cli_avoid_json: bool | None = None, _cli_enforce_required: bool | None = None, _cli_use_class_docs_for_groups: bool | None = None, _cli_exit_on_error: bool | None = None, _cli_prefix: str | None = None, _cli_implicit_flags: bool | None = None, _secrets_dir: PathType | None = None, *, whylabs_api_key: str, whylabs_api_endpoint: str = 'https://api.whylabsapp.com', whylabs_api_cache_endpoint: str | None = None, container_password: str | None = None, disable_container_password: bool = False, default_whylabs_dataset_cadence: DatasetCadence = DatasetCadence.HOURLY, default_whylabs_upload_cadence: DatasetUploadCadenceGranularity = DatasetUploadCadenceGranularity.MINUTE, default_whylabs_upload_interval: int = 5, fail_startup_without_config: bool = False, fail_startup_without_policies: bool = False, llm_container: bool = False, disable_whylabs_policy_polling: bool = False, s3_config_sync: bool = False, s3_config_bucket_name: str = '', s3_config_prefix: str = '', s3_config_sync_interval: int = 15, s3_config_sync_cadence: DatasetUploadCadenceGranularity = DatasetUploadCadenceGranularity.MINUTE, config_sync_interval: int = 1, config_sync_cadence: DatasetUploadCadenceGranularity = DatasetUploadCadenceGranularity.MINUTE, log_level: int = 20, policy_base_dir: str = './whylogs_container/whylogs_config/', trace_endpoint: str = 'https://api.whylabsapp.com/v1/traces', disable_tracing: bool = False, disable_profiling: bool = False, auto_pull_whylabs_policy_model_ids: List[str] = [], aws_sqs_url: str | None = None, aws_sqs_dlq_url: str | None = None, max_request_batch_size: int = 50000, max_request_buffer_bytes: int = 1000000000, cache_assets_runtime: bool = False, pre_warm_cache: bool = True, mac_dev_mode: bool = False, debug_endpoint_enabled: bool = False, policy_editor_required: bool = False, tenancy_mode: Literal['SINGLE', 'MULTI'] = 'SINGLE', enforce_tenancy_mode: bool = True)

Bases: BaseSettings

This class has all of the configuration options for the container. Each of the fields of this class can be set via instantiating this class in Python or by setting an case insensitive environment variable with the same name.

after_validator() Self
assert_llm_endpoint() None
auth_disabled() bool
auto_pull_whylabs_policy_model_ids: List[str]

Optional. If set, the container will automatically pull policies from WhyLabs for the given model ids.

aws_sqs_dlq_url: str | None

Optional. The URL of the AWS SQS dead letter queue to send messages that can’t be processed.

aws_sqs_url: str | None

Optional. The URL of the AWS SQS queue to poll for messages.

classmethod before_validator(values: Dict[str, Any]) Dict[str, Any]
cache_assets_runtime: bool

Optional. If set to True, the container will attempt to download and cache missing assets at runtime. The default is False because the container build should be the place where this happens so no runtime downloads are required, but this can be set when building custom containers, running tests, etc.

config_sync_cadence: DatasetUploadCadenceGranularity

Optional. The cadence at which the container will sync remote policies. Can be H (hourly), M (minute), or D (daily). Defaults to MINUTE.

config_sync_interval: int

Optional. The interval at which the container will sync remote policies. This is the number of units of time (hours, minutes, or days) that the container will wait before syncing the remote policies. Defaults to 15.

container_password: str | None

Password for the container. The container looks for this password in a header for each request. This is the curl format for sending the header: -H “Authorization: Bearer my_password”

debug_endpoint_enabled: bool

If set to True, the container will expose a debug endpoint at /debug/evaluate that allows passing custom policies in requests. It’s convenient for prototyping policies but it has a large memory impact on the main process of the container.

default_whylabs_dataset_cadence: DatasetCadence

Can be DAILY (default) or HOURLY. This is used whenever the cadence is not specified in the dataset schema, or if you don’t specify a dataset schema. This determines how data is bucketed in the container. Data for each profile will be pooled by the hour, minute, or day.

default_whylabs_upload_cadence: DatasetUploadCadenceGranularity

Can be H (default), M, or D. This determines how often profiles are uploaded to WhyLabs.

default_whylabs_upload_interval: int

Default interval for WhyLabs uploads. This determines how many units of time (hours, minutes, or days)

disable_container_password: bool

If set to True, the container will not require a password for requests. Then you can omit the CONTAINER_PASSWORD environment variable.

disable_profiling: bool

Optional. If set to True, the container will not profile data or upload profiles to WhyLabs.

disable_tracing: bool

Optional. If set to True, the container will not send trace data to WhyLabs.

disable_whylabs_policy_polling: bool

Don’t poll the WhyLabs api to download policy files. This is useful for a totally offline deployment that uses local policies built into the container only.

enforce_tenancy_mode: bool

This option is here as a fail safe for unexpected use cases. By default, when running in multi-tenancy mode, the container will enforce that all requests have a valid API key for a child organization. If this is set to False, the container will not enforce this and will allow any request to pass through. That means that the profiles may fail to upload in the background later on if the wrong API key was used by mistake. Don’t disable this unless there is a good reason.

fail_startup_without_config: bool

If set to True, the container will fail to start if no custom configuration is found. This is a safeguard if you want to make sure you set up the container correctly and you’re using python to configure dataset schemas for whylogs.

fail_startup_without_policies: bool

Just like FAIL_STARTUP_WITHOUT_CONFIG but for yaml policies instead of custom python configuration.

static get_secrets_file(secrets_path: str) SecretsFile | None
get_values_safe() Dict[str, Any]
llm_container: bool

Env var to identify if the deployment is of the type LLM or not. Defaults to False, but set to True on LLM image build

log_level: int

Defaults to INFO. The log level for the container. Can be DEBUG, INFO, WARNING, ERROR, or CRITICAL.

mac_dev_mode: bool

Set this to true to develop from a Mac. This will avoid using dependencies that won’t work on a Mac at the cost of performance and some hackery.

max_request_batch_size: int

Optional. The maximum number of profiles that can be sent in a single request. Defaults to 50,000.

max_request_buffer_bytes: int

Optional. The maximum number of bytes that can be sent in a single request. Defaults to 1,000,000,000.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[SettingsConfigDict] = {'arbitrary_types_allowed': True, 'case_sensitive': False, 'cli_avoid_json': False, 'cli_enforce_required': False, 'cli_exit_on_error': True, 'cli_hide_none_type': False, 'cli_implicit_flags': False, 'cli_parse_args': None, 'cli_parse_none_str': None, 'cli_prefix': '', 'cli_prog_name': None, 'cli_settings_source': None, 'cli_use_class_docs_for_groups': False, 'env_file': None, 'env_file_encoding': None, 'env_ignore_empty': True, 'env_nested_delimiter': None, 'env_parse_enums': None, 'env_parse_none_str': None, 'env_prefix': '', 'extra': 'forbid', 'frozen': True, 'json_file': None, 'json_file_encoding': None, 'nested_model_default_partial_update': False, 'protected_namespaces': ('model_', 'settings_'), 'secrets_dir': '/var/run/secrets/whylabs.ai/env', 'str_strip_whitespace': True, 'toml_file': None, 'validate_default': True, 'yaml_file': None, 'yaml_file_encoding': None}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'auto_pull_whylabs_policy_model_ids': FieldInfo(annotation=List[str], required=False, default=[]), 'aws_sqs_dlq_url': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'aws_sqs_url': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'cache_assets_runtime': FieldInfo(annotation=bool, required=False, default=False), 'config_sync_cadence': FieldInfo(annotation=DatasetUploadCadenceGranularity, required=False, default=<DatasetUploadCadenceGranularity.MINUTE: 'M'>), 'config_sync_interval': FieldInfo(annotation=int, required=False, default=1), 'container_password': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, json_schema_extra={'safe_to_print': False}), 'debug_endpoint_enabled': FieldInfo(annotation=bool, required=False, default=False), 'default_whylabs_dataset_cadence': FieldInfo(annotation=DatasetCadence, required=False, default=<DatasetCadence.HOURLY: 'HOURLY'>), 'default_whylabs_upload_cadence': FieldInfo(annotation=DatasetUploadCadenceGranularity, required=False, default=<DatasetUploadCadenceGranularity.MINUTE: 'M'>), 'default_whylabs_upload_interval': FieldInfo(annotation=int, required=False, default=5), 'disable_container_password': FieldInfo(annotation=bool, required=False, default=False), 'disable_profiling': FieldInfo(annotation=bool, required=False, default=False), 'disable_tracing': FieldInfo(annotation=bool, required=False, default=False), 'disable_whylabs_policy_polling': FieldInfo(annotation=bool, required=False, default=False), 'enforce_tenancy_mode': FieldInfo(annotation=bool, required=False, default=True), 'fail_startup_without_config': FieldInfo(annotation=bool, required=False, default=False), 'fail_startup_without_policies': FieldInfo(annotation=bool, required=False, default=False), 'llm_container': FieldInfo(annotation=bool, required=False, default=False), 'log_level': FieldInfo(annotation=int, required=False, default=20), 'mac_dev_mode': FieldInfo(annotation=bool, required=False, default=False), 'max_request_batch_size': FieldInfo(annotation=int, required=False, default=50000), 'max_request_buffer_bytes': FieldInfo(annotation=int, required=False, default=1000000000), 'policy_base_dir': FieldInfo(annotation=str, required=False, default='./whylogs_container/whylogs_config/'), 'policy_editor_required': FieldInfo(annotation=bool, required=False, default=False), 'pre_warm_cache': FieldInfo(annotation=bool, required=False, default=True), 's3_config_bucket_name': FieldInfo(annotation=str, required=False, default=''), 's3_config_prefix': FieldInfo(annotation=str, required=False, default=''), 's3_config_sync': FieldInfo(annotation=bool, required=False, default=False), 's3_config_sync_cadence': FieldInfo(annotation=DatasetUploadCadenceGranularity, required=False, default=<DatasetUploadCadenceGranularity.MINUTE: 'M'>), 's3_config_sync_interval': FieldInfo(annotation=int, required=False, default=15), 'tenancy_mode': FieldInfo(annotation=Literal['SINGLE', 'MULTI'], required=False, default='SINGLE'), 'trace_endpoint': FieldInfo(annotation=str, required=False, default='https://api.whylabsapp.com/v1/traces'), 'whylabs_api_cache_endpoint': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'whylabs_api_endpoint': FieldInfo(annotation=str, required=False, default='https://api.whylabsapp.com'), 'whylabs_api_key': FieldInfo(annotation=str, required=True, json_schema_extra={'safe_to_print': False})}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

property org_id: str

Convenience function to gett the org id from the WhyLabs API key.

classmethod parse_log_level(v: str | int) int
policy_base_dir: str

Env var to identify the root directory for policy configs. Defaults to /whylogs_container/whylogs_config/

policy_editor_required: bool

If set to True then the container will fail if it can’t find the policy editor project to server in the LLM container version.

pre_warm_cache: bool

When True, the first thing the container does is execute a test workflow that forces the download of all missing assets and initializes any metrics that it will use, all before the health check.

s3_config_bucket_name: str

Optional. The name of the S3 bucket where the container will look for YAML files to keep in sync with.

s3_config_prefix: str

Optional. The prefix of the S3 bucket where the container will look for YAML files to keep in sync with. If not defined, it will look for files on the bucket’s root.

s3_config_sync: bool

Optional. If set to True, the container will sync S3 YAML config files with the container and parse them into schemas.

s3_config_sync_cadence: DatasetUploadCadenceGranularity

Optional. The cadence at which the container will sync the S3 bucket’s YAML files. Can be H (hourly), M (minute), or D (daily). Defaults to MINUTE.

s3_config_sync_interval: int

Optional. The interval at which the container will sync the S3 bucket’s YAML files. This is the number of units of time (hours, minutes, or days) that the container will wait before syncing the S3 bucket with container schemas. Defaults to 15.

classmethod settings_customise_sources(settings_cls, init_settings, env_settings, dotenv_settings, file_secret_settings)

Define the sources and their order for loading the settings values.

Args:

settings_cls: The Settings class. init_settings: The InitSettingsSource instance. env_settings: The EnvSettingsSource instance. dotenv_settings: The DotEnvSettingsSource instance. file_secret_settings: The SecretsSettingsSource instance.

Returns:

A tuple containing the sources and their order for loading the settings values.

tenancy_mode: Literal['SINGLE', 'MULTI']
trace_endpoint: str

Optional. The endpoint to send trace data to. If not set, traces are sent to WhyLabs production.

whylabs_api_cache_endpoint: str | None

An endpoint for WhyLabs API cache. If this is set then it will be used for certain WhyLabs requests. This is a part of a larger deployment strategy for the container and not intended to be a general customization.

whylabs_api_endpoint: str

The endpoint for WhyLabs API. Defaults to the production endpoint.

whylabs_api_key: str

Required. API key for WhyLabs.

whylogs_container.whylabs.container.server_config.get_server_config() ServerConfig
whylogs_container.whylabs.container.server_config.reset_server_config() None
whylogs_container.whylabs.container.server_config.set_server_config(config: ServerConfig) None