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.

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_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

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 : Optional[Literal['nextech intellechartpro r4', 'smarthealthit r4', 'epic r4', 'modmed r4', 'generic r4']]
  • 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_file_counting : bool
  • static background_recovery_enabled : bool
  • static background_recovery_poll_interval : int
  • static background_recovery_unproductive_attempt_limit : int
  • static cache_encryption_enabled : bool
  • static cancel_abort_timeout : int
  • static config_reload_file_poll_interval_seconds : float | None
  • static config_reload_hub_poll_interval_seconds : float | None
  • 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_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_staleness_tolerance : int
  • static enable_batch_resilience : bool
  • static enable_data_cache : bool
  • static enable_ehr_call_metrics : bool
  • static enable_execution_time_metrics : bool
  • static enable_optic_disc_cube : bool
  • static enable_skipped_file_metadata_collection : bool
  • static enable_skipped_file_telemetry : bool
  • static enable_telemetry : bool
  • static enable_zstd_model_compression : bool
  • static exclude_files_created_after_task_start : bool
  • static file_metadata_persist_chunk_size : int
  • static file_multiprocessing_enabled : bool
  • static follow_symlinks_in_scantree : bool
  • 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_many_retries : int
  • static message_service_retries : int
  • static metadata_flow_timeout_seconds : int | None
  • static model_config : ClassVar[pydantic_settings.main.SettingsConfigDict]
  • 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 : Optional[Literal['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG']]
  • static patient_api_server_port : int
  • 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 proxy_support : bool
  • static skip_accessibility_check : bool
  • 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