Skip to content

Utilities

Logger

pluginlake.utils.logger

Structured logging setup for pluginlake.

setup_logging(level=logging.INFO)

Configure the root pluginlake logger.

Call once at application startup. All child loggers (e.g., pluginlake.storage) inherit this configuration.

Parameters:

Name Type Description Default
level int

The log level to set.

INFO
Source code in src/pluginlake/utils/logger.py
def setup_logging(level: int = logging.INFO) -> None:
    """Configure the root ``pluginlake`` logger.

    Call once at application startup. All child loggers
    (e.g., ``pluginlake.storage``) inherit this configuration.

    Args:
        level: The log level to set.
    """
    root_logger = logging.getLogger("pluginlake")
    root_logger.handlers.clear()
    root_logger.setLevel(level)

    handler = logging.StreamHandler(sys.stderr)
    handler.setFormatter(logging.Formatter(fmt=_TEXT_FORMAT, datefmt=_TEXT_DATE_FORMAT))

    root_logger.addHandler(handler)
    root_logger.propagate = False

get_logger(name)

Get a namespaced logger for a pluginlake module.

Usage::

from pluginlake.utils.logger import get_logger

logger = get_logger(__name__)
logger.info("Processing started")

Parameters:

Name Type Description Default
name str

The module name, typically __name__.

required

Returns:

Type Description
Logger

A logger under the pluginlake namespace.

Source code in src/pluginlake/utils/logger.py
def get_logger(name: str) -> logging.Logger:
    """Get a namespaced logger for a pluginlake module.

    Usage::

        from pluginlake.utils.logger import get_logger

        logger = get_logger(__name__)
        logger.info("Processing started")

    Args:
        name: The module name, typically ``__name__``.

    Returns:
        A logger under the ``pluginlake`` namespace.
    """
    if not name.startswith("pluginlake"):
        name = f"pluginlake.{name}"
    return logging.getLogger(name)

Dev Environment

pluginlake.utils.devenv

Dev environment service checks for notebooks and local development.

ServiceStatus

Bases: NamedTuple

Result of a single service connectivity check.

Source code in src/pluginlake/utils/devenv.py
class ServiceStatus(NamedTuple):
    """Result of a single service connectivity check."""

    name: str
    url: str
    ok: bool
    detail: str

check_dev_services()

Check PostgreSQL, Dagster, and FastAPI connectivity for the local dev stack.

Source code in src/pluginlake/utils/devenv.py
def check_dev_services() -> list[ServiceStatus]:
    """Check PostgreSQL, Dagster, and FastAPI connectivity for the local dev stack."""
    return [
        _check_postgres(),
        _check_http("Dagster", "http://localhost:3000/server_info"),
        _check_http("FastAPI", "http://localhost:8000/health"),
    ]

Test Data

pluginlake.utils.testdata

Synthea test/demo data retrieval for notebooks and development.

For OMOP vocabulary provisioning (production), use :func:pluginlake.omop.provisioning.ensure_omop_vocabularies instead.

find_repo_root()

Walk up from this file to find the directory containing pyproject.toml.

Source code in src/pluginlake/utils/testdata.py
def find_repo_root() -> Path:
    """Walk up from this file to find the directory containing pyproject.toml."""
    current = Path(__file__).resolve().parent
    for parent in [current, *current.parents]:
        if (parent / "pyproject.toml").exists():
            return parent
    msg = "Could not find repo root (no pyproject.toml found)"
    raise FileNotFoundError(msg)

ensure_synthea1k(project_root=None)

Ensure Synthea 1K test data is available locally.

Source code in src/pluginlake/utils/testdata.py
def ensure_synthea1k(project_root: Path | None = None) -> Path:
    """Ensure Synthea 1K test data is available locally."""
    root = project_root or find_repo_root()
    return download_and_extract(_SYNTHEA1K_URL, root / _SYNTHEA1K_DEST)

ensure_synthea_fhir_ndjson(project_root=None)

Ensure Synthea FHIR NDJSON files are available locally.

Source code in src/pluginlake/utils/testdata.py
def ensure_synthea_fhir_ndjson(project_root: Path | None = None) -> Path:
    """Ensure Synthea FHIR NDJSON files are available locally."""
    root = project_root or find_repo_root()
    return download_and_extract(_SYNTHEA_FHIR_NDJSON_URL, root / _SYNTHEA_FHIR_NDJSON_DEST)