Skip to main content

config

Dealing with interactions with configuration and environment variables.

Module​

Functions​

_get_environment​

def _get_environment() ‑> str:

Returns bitfount environment to be used from BITFOUNT_ENVIRONMENT variable.

The result is cached to avoid multiple warning messages. This means that changes to the BITFOUNT_ENVIRONMENT environment variable will not be detected whilst the library is running.

Returns str: PRODUCTION_ENVIRONMENT, STAGING_ENVIRONMENT, DEVELOPMENT_ENVIRONMENT or SANDBOX_ENVIRONMENT

configuration_schema​

def configuration_schema() ‑> dict[str, typing.Any]:

Generate a JSON schema for visible configuration.

create_storage_dirs_in_background​

def create_storage_dirs_in_background() ‑> None:

Create the configured storage directories on a background thread.

Called at import time, so it must not block: a home directory on a network mount can make mkdir slow. Every consumer of these paths already creates what it needs with exist_ok=True, so a directory appearing slightly later is harmless.

datasource_env_dataset​

def datasource_env_dataset(name: str) ‑> str | None:

Return the dataset a datasource environment variable is for.

Arguments

  • name: An environment variable name.

Returns The dataset name, or None if name is not a datasource argument variable of the shape datasource_env_name gives.

datasource_env_name​

def datasource_env_name(datasource_name: str, arg: str) ‑> str:

Return the environment variable arg of datasource_name is read from.

Arguments

  • datasource_name: The dataset's name.
  • arg: The datasource argument, e.g. path.

Returns BITFOUNT_DATASOURCE__<datasource_name>__<arg>.

Raises

  • ValueError: If datasource_name contains an underscore, or arg is not a name of words joined by single underscores.

get_gpu_metadata​

def get_gpu_metadata() ‑> tuple[str | None, int]:

Retrieve details about GPUs if available.

Uses tools available in the appropriate backend, to find GPUs that are usable by the backend.

Returns: a tuple of GPU name and count.

load_datasource_secrets_settings​

def load_datasource_secrets_settings() ‑> DatasourceSecretsSettings:

Load datasource secrets settings from the current environment.

load_ehr_bootstrap_settings​

def load_ehr_bootstrap_settings() ‑> EHRBootstrapSettings:

Load EHR bootstrap settings from the current environment.

load_pod_bootstrap_settings​

def load_pod_bootstrap_settings() ‑> PodBootstrapSettings:

Load pod bootstrap settings from the current environment.

refresh_configuration​

def refresh_configuration() ‑> None:

Hot-reloads configuration values.

Lets us refresh settings at runtime Avoiding having to restart everything to load in environment variables https://docs.pydantic.dev/latest/concepts/pydantic_settings/#in-place-reloading

resolve_bootstrap_cluster_id​

def resolve_bootstrap_cluster_id() ‑> str | None:

Return bootstrap cluster_id for idle polling, respecting API key auth.

Classes​

DatasourceSecretsSettings​

class DatasourceSecretsSettings(**values: Any):

Environment-driven datasource constructor arguments, keyed by dataset name.

Lets credentials such as an InterMine token or a SQL connection_string be supplied without writing them into the pod config file or the hub's stored dataset configuration. Set via BITFOUNT_DATASOURCE__<dataset name>__<argument name>, e.g. BITFOUNT_DATASOURCE__humanmine__token. Values are merged into the dataset's datasource_args when the datasource is constructed, taking precedence over any value in the config.

Dataset names may contain hyphens, which a shell export rejects; set those through .env.local or the container environment instead.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Variables​

  • static datasource : dict[str, dict[str, pydantic.types.SecretStr]]
  • static model_config : ClassVar[pydantic_settings.main.SettingsConfigDict]

Methods​


args_for​

def args_for(self, datasource_name: str) ‑> dict[str, str]:

Return the unwrapped arguments configured for datasource_name.

EHRBootstrapSettings​

class EHRBootstrapSettings(**values: Any):

Environment-driven settings for configuring EHR access without a config file.

Populated from BITFOUNT_EHR_* environment variables. PodConfig falls back to these when its YAML config has no ehr_config block. Setting client_id (alongside base_url/provider) builds a working SMARTBackendEHRConfig: a self-contained client-credentials + signed-JWT flow that needs no browser or external process, so it's the only shape that's actually usable in a headless/containerized pod. It also accepts scopes and an optional inline signing key pair (when the key pair fields are left unset, the pod generates and persists its own key pair on first run instead).

Setting base_url/provider alone (no client_id) instead builds a SMARTStandaloneEHRConfig. A pod with only base_url/provider has no way to obtain a token: FHIR requests either fail with ValueError or, only if BITFOUNT_ALLOW_NO_EHR_SECRETS=true, go out unauthenticated. This fallback therefore only does anything useful against a fully open FHIR server.

list_resource_ids applies to both shapes: when set, patient enumeration is scoped to those pre-configured FHIR List resources instead of an unfiltered /Patient search, for EHRs (e.g. Epic) that reject the latter.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Variables​

  • static base_url : str | None
  • static client_id : str | None
  • static key_pair_alg : str | None
  • static key_pair_kid : str | None
  • static key_pair_private_key : str | None
  • static key_pair_public_key : str | None
  • static list_resource_ids : list[str]
  • static model_config : ClassVar[pydantic_settings.main.SettingsConfigDict]
  • static provider : Literal['nextech intellechartpro r4', 'smarthealthit r4', 'epic r4', 'modmed r4', 'generic r4', 'advancedmd r4'] | None
  • static scopes : list[str]

PodBootstrapSettings​

class PodBootstrapSettings(**values: Any):

Environment-driven settings for bootstrapping a pod without a config file.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Variables​

  • static cluster_id : str | None
  • static model_config : ClassVar[pydantic_settings.main.SettingsConfigDict]
  • static pod_name : str | None
  • static username : str | None

Static methods​


api_keys_configured​

def api_keys_configured() ‑> bool:

Return whether Bitfount API keys are available in the environment.

Methods​


missing_required_fields​

def missing_required_fields(self) ‑> list[str]:

Return env vars still required for env-only pod bootstrap.

resolved_cluster_id​

def resolved_cluster_id(self) ‑> str | None:

Return cluster_id, clearing it when API keys are also configured.

Settings​

class Settings(**values: Any):

All configurable settings.

Contains all of our configurable variables. Loads from .env.local or from environment variables.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Variables​

  • static allow_extra_zeiss_transfer_syntaxes : bool
  • static allow_no_ehr_secrets : bool
  • static background_dag_max_concurrent_runs : int
  • static background_dag_max_run_seconds : float
  • static background_dag_owed_resubmit_backoff : float
  • static background_dag_progress_interval : float
  • static background_dag_rerun_wave_budget : int
  • static background_dag_rerun_wave_size : int
  • static background_dag_setup_abandon_wait : float
  • static background_dag_setup_timeout : float
  • static background_dag_wave_retry_limit : int
  • static background_dag_wave_size : int
  • static background_dag_wave_timeout : float
  • static background_ehr_connection_concurrency : int
  • static background_file_counting : bool
  • static background_gpu_inference_concurrency : int
  • static background_growth_rerun_cooldown : int
  • static background_growth_rerun_enabled : bool
  • static background_growth_rerun_failure_limit : int | None
  • static background_lineage_lock_wait : float
  • static background_machine_slot_wait : float
  • static background_periodic_rerun_cron : str
  • static background_periodic_rerun_enabled : bool
  • static background_periodic_rerun_grace_period : int
  • static background_periodic_rerun_poll_interval : int
  • static background_periodic_rerun_startup_delay : int
  • static background_periodic_rerun_timezone : str | None
  • static background_recovery_poll_interval : int
  • static background_recovery_unproductive_attempt_limit : int | None
  • static background_rerun_concurrency : int
  • static background_rerun_slot_timeout : int
  • static background_run_breadcrumb_dir : pathlib.Path | None
  • static background_run_failure_limit : int
  • static background_step_resource_wait : float
  • static background_task_definition_check_interval : int
  • static background_wave_cache_enabled : bool
  • static background_wave_cache_max_bytes : int
  • static background_wave_cache_min_free_bytes : int
  • static cache_backup_enabled : bool
  • static cache_backup_interval_seconds : int
  • static cache_backup_retention : int
  • static cache_encryption_enabled : bool | None
  • static cache_encryption_key : pydantic.types.SecretStr | None
  • static cancel_abort_timeout : int
  • static config_reload_file_poll_interval_seconds : float | None
  • static config_reload_hub_poll_interval_seconds : float | None
  • static criteria_near_miss_min_patients : int
  • static data_cache_busy_timeout_ms : int
  • static dataset_cache_ttl : int
  • static datasource_health_check_interval : int
  • static dd_client_token : str | None
  • static dd_flush_interval_seconds : float
  • static dd_log_level : Literal['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG']
  • static dd_site : str | None
  • static default_batched_execution : bool
  • static default_torch_device : str | None
  • static discard_unsupported_cache : bool
  • static ehr_cache_ttl : int
  • static ehr_connectivity_check_interval : int
  • static ehr_patient_listing_concurrency : int
  • static ehr_patient_listing_max_age : int
  • static ehr_patient_listing_page_size : int
  • static ehr_patient_listing_retry_cooldown : int
  • static ehr_preflight_attempts : int
  • static ehr_preflight_enabled : bool
  • static ehr_preflight_initial_backoff : float
  • static ehr_preflight_max_backoff : float
  • static ehr_preflight_request_timeout : int
  • static ehr_staleness_tolerance : int
  • static enable_batch_resilience : bool
  • static enable_criteria_matching_telemetry : bool
  • static enable_criteria_near_miss_counts : bool
  • static enable_data_cache : bool
  • static enable_execution_time_metrics : bool
  • static enable_gpu_telemetry : bool
  • static enable_model_weights_reuse : bool
  • static enable_optic_disc_cube : bool
  • static enable_schema_generation : bool
  • static enable_skipped_file_metadata_collection : bool
  • static enable_skipped_file_telemetry : bool
  • static enable_telemetry : bool
  • static enable_trial_filter_telemetry : bool
  • static enable_zstd_model_compression : bool
  • static exclude_files_created_after_task_start : bool
  • static file_hashing_enabled : bool
  • static file_metadata_io_concurrency : int
  • static file_metadata_network_io_concurrency : int
  • static file_metadata_persist_chunk_size : int
  • static file_metadata_prune_grace_seconds : int
  • static file_multiprocessing_enabled : bool
  • static follow_symlinks_in_scantree : bool
  • static gil_free_path_resolve : bool
  • static gil_stall_dump_seconds : int
  • static handler_register_grace_period : int
  • static hub_signing_jwks_uri : str | None
  • static hub_trigger_freshness_seconds : int
  • static huggingface_user_access_token : str | None
  • static individual_file_retry_enabled : bool
  • static installation_uuid : str | None
  • static log_level : Literal['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG']
  • static logging : bitfount.config.LogSettings
  • static max_consecutive_batch_failures : int
  • static max_hash_file_size_bytes : int
  • static max_number_of_datasource_files : int
  • static max_number_of_prefect_workers : int
  • static max_safe_write_backup_files : int
  • static max_task_batch_size : int
  • static message_service_idle_poll_timeout : float
  • static message_service_many_retries : int
  • static message_service_retries : int
  • static metadata_flow_timeout_seconds : int | None
  • static metadata_lock_wait_seconds : float
  • static metadata_recovery_interval : float
  • static metadata_refresh_requires_configured_datasource : bool
  • static model_config : ClassVar[pydantic_settings.main.SettingsConfigDict]
  • static model_inference_progress_files : int
  • static model_inference_progress_interval : float
  • static model_inference_read_ahead_files : int
  • static model_inference_read_ahead_max_bytes : int
  • static model_inference_write_interval : float
  • static model_weights_cache_max_bytes : int
  • static model_weights_cache_min_free_bytes : int
  • static model_weights_shared_cache_enabled : bool
  • static network_drive_robustness : bool
  • static network_drive_robustness_assume_network_drive : bool
  • static network_drive_robustness_retries : int
  • static online_check_hard_limit : int
  • static online_check_soft_limit : int
  • static paths : bitfount.config.PathSettings
  • static patient_api_allowed_origins : list[str]
  • static patient_api_image_cache_size_mb : int
  • static patient_api_image_webp_quality : int
  • static patient_api_image_width : int
  • static patient_api_jwks_uri : str | None
  • static patient_api_jwt_audience : str | None
  • static patient_api_jwt_issuer : str | None
  • static patient_api_server_enabled : bool
  • static patient_api_server_log_level : Literal['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG'] | None
  • static patient_api_server_port : int
  • static patient_id_date_order : Literal['infer', 'month-first', 'day-first']
  • static pod_control_server_port : int
  • static pod_control_server_shutdown_timeout : int
  • static pod_heartbeat_shutdown_timeout : int
  • static private : bitfount.config.PrivateSettings
  • static progress_events_enabled : bool
  • static proxy_support : bool
  • static scan_metadata_io_concurrency : int
  • static skip_accessibility_check : bool
  • static skipped_file_telemetry_interval_seconds : float
  • static smart_on_fhir : bitfount.config.SMARTOnFHIRSettings
  • static task_batch_size : int
  • static test_run_number_of_files : int
  • static use_mps : bool
  • static web_max_retries : int