Skip to content

nidaqlib.config

nidaqlib.config

Process-wide configuration for :mod:nidaqlib.

Plain frozen dataclass, no validation library — keeps the core install free of optional deps. Env-var coercion lives in :func:config_from_env.

Design reference: docs/design.md §18.1.

NidaqConfig dataclass

NidaqConfig(
    *,
    default_timeout_s=10.0,
    default_sample_rate_hz=1000.0,
    default_buffer_size=16,
    default_chunk_size=1000,
    eager_tasks=False,
)

Process-wide default settings.

Anything that varies per task (channel ranges, trigger source, TDMS path) belongs on :class:~nidaqlib.tasks.TaskSpec, not here.

Attributes:

Name Type Description
default_timeout_s float

Fallback NI read/write timeout, in seconds. Used when the call site does not supply one explicitly.

default_sample_rate_hz float

Fallback Timing.rate_hz when the :class:~nidaqlib.tasks.Timing field is unset.

default_buffer_size int

AnyIO send-stream capacity for record(), measured in :class:~nidaqlib.tasks.DaqBlock slots.

default_chunk_size int

Samples per channel per emitted DaqBlock for record().

eager_tasks bool

Opt-in to asyncio.eager_task_factory. No-op on trio. See :func:nidaqlib._runtime.install_eager_task_factory.

replace

replace(**updates)

Return a copy of this config with updates applied.

Source code in src/nidaqlib/config.py
def replace(self, **updates: Any) -> Self:
    """Return a copy of this config with ``updates`` applied."""
    return replace(self, **updates)

config_from_env

config_from_env(prefix=DEFAULT_ENV_PREFIX)

Best-effort env loader.

Only reads well-known keys. Missing or unparseable values fall back to :class:NidaqConfig's defaults — this function never raises.

Recognised keys (with prefix="NIDAQLIB_"):

  • NIDAQLIB_DEFAULT_TIMEOUT_S — float seconds
  • NIDAQLIB_DEFAULT_SAMPLE_RATE_HZ — float Hz
  • NIDAQLIB_DEFAULT_BUFFER_SIZE — int slots
  • NIDAQLIB_DEFAULT_CHUNK_SIZE — int samples
  • NIDAQLIB_EAGER_TASKS"1" / "true" / "yes"

Parameters:

Name Type Description Default
prefix str

Prefix to prepend to each env key. Defaults to "NIDAQLIB_".

DEFAULT_ENV_PREFIX

Returns:

Name Type Description
A NidaqConfig

class:NidaqConfig populated from env where parseable.

Source code in src/nidaqlib/config.py
def config_from_env(prefix: str = DEFAULT_ENV_PREFIX) -> NidaqConfig:
    """Best-effort env loader.

    Only reads well-known keys. Missing or unparseable values fall back to
    :class:`NidaqConfig`'s defaults — this function never raises.

    Recognised keys (with ``prefix="NIDAQLIB_"``):

    - ``NIDAQLIB_DEFAULT_TIMEOUT_S`` — float seconds
    - ``NIDAQLIB_DEFAULT_SAMPLE_RATE_HZ`` — float Hz
    - ``NIDAQLIB_DEFAULT_BUFFER_SIZE`` — int slots
    - ``NIDAQLIB_DEFAULT_CHUNK_SIZE`` — int samples
    - ``NIDAQLIB_EAGER_TASKS`` — ``"1"`` / ``"true"`` / ``"yes"``

    Args:
        prefix: Prefix to prepend to each env key. Defaults to
            ``"NIDAQLIB_"``.

    Returns:
        A :class:`NidaqConfig` populated from env where parseable.
    """
    base = NidaqConfig()
    return NidaqConfig(
        default_timeout_s=_float_env(f"{prefix}DEFAULT_TIMEOUT_S", base.default_timeout_s),
        default_sample_rate_hz=_float_env(
            f"{prefix}DEFAULT_SAMPLE_RATE_HZ", base.default_sample_rate_hz
        ),
        default_buffer_size=_int_env(f"{prefix}DEFAULT_BUFFER_SIZE", base.default_buffer_size),
        default_chunk_size=_int_env(f"{prefix}DEFAULT_CHUNK_SIZE", base.default_chunk_size),
        eager_tasks=_bool_env(f"{prefix}EAGER_TASKS", base.eager_tasks),
    )