nexusLIMS.config#
Centralized environment variable management for NexusLIMS.
This module uses pydantic-settings to define, validate, and access
application settings from environment variables and .env files.
It provides a single source of truth for configuration, ensuring
type safety and simplifying access throughout the application.
The settings object can be imported and used throughout the application. In tests, use refresh_settings() to reload settings after modifying environment variables.
Module Contents#
Classes#
Configuration for a single NEMO harvester instance. |
|
Config for email notifications from the nexuslims build-records script. |
|
Manage application settings loaded from environment variables and |
Functions#
Refresh the settings singleton from current environment variables. |
|
Clear the settings cache without immediately creating a new instance. |
|
Read LabArchives settings without triggering full Settings validation. |
Data#
API#
- nexusLIMS.config.TEST_MODE#
- class nexusLIMS.config.NemoHarvesterConfig(/, **data: Any)[source]#
Bases:
pydantic.BaseModelConfiguration for a single NEMO harvester instance.
- address#
Type: nexusLIMS.config.TestAwareHttpUrl
- token#
Type: str
- strftime_fmt#
Type: str
- strptime_fmt#
Type: str
- tz#
Type: str | None
- classmethod validate_trailing_slash(v: str | AnyHttpUrl) str | AnyHttpUrl[source]#
Ensure the API address has a trailing slash.
- class nexusLIMS.config.EmailConfig(/, **data: Any)[source]#
Bases:
pydantic.BaseModelConfig for email notifications from the nexuslims build-records script.
- smtp_host#
Type: str
- smtp_port#
Type: int
- smtp_username#
Type: str | None
- smtp_password#
Type: str | None
- use_tls#
Type: bool
- sender#
Type: nexusLIMS.config.TestAwareEmailStr
- recipients#
Type: list[nexusLIMS.config.TestAwareEmailStr]
- class nexusLIMS.config.Settings(_case_sensitive: bool | None = None, _nested_model_default_partial_update: bool | None = None, _env_prefix: str | None = None, _env_file: pydantic_settings.sources.DotenvType | None = ENV_FILE_SENTINEL, _env_file_encoding: str | None = None, _env_ignore_empty: bool | None = None, _env_nested_delimiter: str | None = None, _env_nested_max_split: int | 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_flag_prefix_char: str | None = None, _cli_implicit_flags: bool | None = None, _cli_ignore_unknown_args: bool | None = None, _cli_kebab_case: bool | Literal[all, no_enums] | None = None, _cli_shortcuts: Mapping[str, str | list[str]] | None = None, _secrets_dir: pydantic_settings.sources.PathType | None = None, **values: Any)[source]#
Bases:
pydantic_settings.BaseSettingsManage application settings loaded from environment variables and
.envfiles.This class utilizes
pydantic-settingsto provide a robust and type-safe way to define, validate, and access all application configurations. It ensures that settings are loaded with proper types and provides descriptions for each.- model_config#
‘SettingsConfigDict(…)’
- NX_FILE_STRATEGY#
Type: typing.Literal[exclusive, inclusive]
- NX_IGNORE_PATTERNS#
Type: list[str]
- NX_INSTRUMENT_DATA_PATH#
Type: nexusLIMS.config.TestAwareDirectoryPath
- NX_DATA_PATH#
Type: nexusLIMS.config.TestAwareDirectoryPath
- NX_DB_PATH#
Type: nexusLIMS.config.TestAwareFilePath
- NX_CDCS_TOKEN#
Type: str
- NX_CDCS_URL#
Type: nexusLIMS.config.TestAwareHttpUrl
- NX_LABARCHIVES_ACCESS_KEY_ID#
Type: str | None
- NX_LABARCHIVES_ACCESS_PASSWORD#
Type: str | None
- NX_LABARCHIVES_USER_ID#
Type: str | None
- NX_LABARCHIVES_URL#
Type: nexusLIMS.config.TestAwareHttpUrl | None
- NX_LABARCHIVES_NOTEBOOK_ID#
Type: str | None
- NX_EXPORT_STRATEGY#
Type: typing.Literal[all, first_success, best_effort]
- NX_CERT_BUNDLE_FILE#
Type: nexusLIMS.config.TestAwareFilePath | None
- NX_CERT_BUNDLE#
Type: str | None
- NX_DISABLE_SSL_VERIFY#
Type: bool
- NX_FILE_DELAY_DAYS#
Type: float
- NX_CLUSTERING_SENSITIVITY#
Type: float
- NX_LOG_PATH#
Type: nexusLIMS.config.TestAwareDirectoryPath | None
- NX_RECORDS_PATH#
Type: nexusLIMS.config.TestAwareDirectoryPath | None
- NX_LOCAL_PROFILES_PATH#
Type: nexusLIMS.config.TestAwareDirectoryPath | None
- NX_ELABFTW_API_KEY#
Type: str | None
- NX_ELABFTW_URL#
Type: nexusLIMS.config.TestAwareHttpUrl | None
- NX_ELABFTW_EXPERIMENT_CATEGORY#
Type: int | None
- NX_ELABFTW_EXPERIMENT_STATUS#
Type: int | None
- nemo_harvesters() dict[int, NemoHarvesterConfig][source]#
Dynamically discover and parse all NEMO harvester configurations.
Searches environment variables for NX_NEMO_ADDRESS_N patterns and constructs NemoHarvesterConfig objects for each numbered harvester.
- Returns:
Dictionary mapping harvester number (1, 2, 3, …) to configuration objects. Empty dict if no harvesters are configured.
- Return type:
Examples:
With environment variables:
NX_NEMO_ADDRESS_1=https://nemo1.com/api/ NX_NEMO_TOKEN_1=token123 NX_NEMO_ADDRESS_2=https://nemo2.com/api/ NX_NEMO_TOKEN_2=token456 NX_NEMO_TZ_2=America/New_York
The resulting output will be of the following format:
{ 1: NemoHarvesterConfig( address='https://nemo1.com/api/', token='token123', ... ), 2: NemoHarvesterConfig( address='https://nemo2.com/api/', token='token456', tz='America/New_York', ... ) }
- email_config() EmailConfig | None[source]#
Load email configuration from environment variables if available.
This method is cached per Settings instance for performance.
- Returns:
Email configuration object if all required settings are present, None otherwise (email notifications will be disabled).
- Return type:
EmailConfig | None
Examples:
With environment variables:
NX_EMAIL_SMTP_HOST=smtp.gmail.com NX_EMAIL_SENDER=nexuslims@example.com NX_EMAIL_RECIPIENTS=admin@example.com,team@example.com
Optional variables:
NX_EMAIL_SMTP_PORT=587 NX_EMAIL_SMTP_USERNAME=user@example.com NX_EMAIL_SMTP_PASSWORD=secret NX_EMAIL_USE_TLS=true
- nexusLIMS.config.refresh_settings() Settings[source]#
Refresh the settings singleton from current environment variables.
This forces a reload of all settings from the environment. Primarily useful for testing.
- Returns:
The newly created settings instance
- Return type:
Examples:
>>> from nexusLIMS.config import settings, refresh_settings >>> import os >>> >>> os.environ["NX_FILE_STRATEGY"] = "inclusive" >>> refresh_settings() >>> >>> assert settings.NX_FILE_STRATEGY == "inclusive"
- nexusLIMS.config.clear_settings() None[source]#
Clear the settings cache without immediately creating a new instance.
The next import or access to settings will create a fresh instance. Useful in test teardown to ensure clean state.
- nexusLIMS.config.settings#
‘_SettingsProxy(…)’
The settings “singleton” - accessed like a normal object in the application
- nexusLIMS.config.read_labarchives_env(env_path: str | Path = '.env') dict[str, str | None][source]#
Read LabArchives settings without triggering full Settings validation.
Merges values from the given
.envfile and the process environment (environment variables take precedence), returning only the fiveNX_LABARCHIVES_*keys. No other configuration is read or validated.This is intended for CLI helper commands (e.g.
labarchives-get-uid) that need only LabArchives credentials and must not fail due to missing core NexusLIMS settings (NX_INSTRUMENT_DATA_PATHetc.).