Skip to content

Repository: fabric-core

Foundational and reusable Python library for Microsoft Fabric data engineering workloads.

The goal of this package is to centralize stable, cross-domain engineering patterns that are repeatedly used in notebooks and pipelines, without coupling implementation to one specific business solution.

fabric-core provides global, reusable classes and helpers for:

  • Delta Lake operations
  • I/O and OneLake ABFSS path handling
  • Structured logging
  • Exception taxonomy
  • Observability hooks
  • Schema building
  • Spark session creation
  • Transformations
  • Validations

Design principles:

  • General-purpose and domain-agnostic APIs
  • Stable contracts for long-lived reuse
  • Test-first development (TDD)
  • Typed interfaces and explicit error handling
  • Runtime-friendly defaults for Microsoft Fabric and Spark

The package uses a src-layout and separated module boundaries:

fabric-core/
src/fabric_core/
delta/
operations.py
io/
paths.py
logging/
factory.py
observability/
metrics.py
schema/
builders.py
spark/
session.py
transformations/
core.py
validations/
results.py
exceptions.py

Module responsibilities:

  • exceptions: library-wide base exceptions and typed failures
  • spark: deterministic Spark profile configuration and validation
  • io: OneLake path building and convention validation
  • delta: reusable merge/upsert condition builders and Delta service contracts
  • schema: declarative schema field modeling and builder utilities
  • transformations: stateless transformation helpers
  • validations: validation result model and summarization
  • logging: structured logger setup with contextual metadata
  • observability: pluggable metric event model and sink protocol
Terminal window
cd fabric-core
python -m pip install -e .[dev]
Terminal window
cd fabric-core
python -m pip install .
from fabric_core.spark.session import SparkSessionConfig, SparkSessionFactory
config = SparkSessionConfig(
app_name="daily-ingest",
profile="delta",
overrides={"spark.sql.shuffle.partitions": "64"},
)
spark_options = SparkSessionFactory.merged_options(config)
from fabric_core.io.paths import OneLakePath
table_path = OneLakePath.build_table_path(
workspace="Fabric",
lakehouse="lh_business",
table="fact_meter_readings",
)
from fabric_core.io.http import RetryHttpClient
client = RetryHttpClient(timeout_seconds=30, total_retries=5, backoff_factor=0.3)
session = client.create_session()
response = session.get("https://example.com/api/resource", timeout=client.timeout_seconds)
from fabric_core.delta.operations import DeltaMergeSpec, DeltaTableService
spec = DeltaMergeSpec(keys=["id", "measurement_time"])
condition = DeltaTableService.build_merge_condition(spec, source_alias="s", target_alias="t")
from fabric_core.schema.builders import SchemaBuilder, SchemaField
schema = SchemaBuilder(
fields=[
SchemaField(name="id", data_type="string", nullable=False),
SchemaField(name="value", data_type="double"),
]
)
as_dict = schema.to_dict_schema()
from fabric_core.transformations.core import TransformationOps
from fabric_core.validations.results import ValidationResult, summarize
normalized = TransformationOps.normalize_record_keys({"Measurement Time": "2026-01-01"})
results = [
ValidationResult(rule="required_id", passed=True),
ValidationResult(rule="positive_amount", passed=False, message="negative value"),
]
summary = summarize(results)
from fabric_core.logging.factory import create_logger
from fabric_core.observability.metrics import MetricEvent, NoOpMetricSink
logger = create_logger("fabric.pipeline", context={"pipeline": "daily-ingest"})
logger.info("pipeline started")
sink = NoOpMetricSink()
sink.emit(MetricEvent(name="rows_written", value=42))

Development follows red-green-refactor:

  1. Add or update unit tests first.
  2. Run tests and confirm failure (red).
  3. Implement minimal code to satisfy behavior (green).
  4. Refactor while keeping tests green.

Run tests:

Terminal window
cd fabric-core
python -m pytest -q

Recommended extension strategy:

  • Add features by module boundary, not by domain notebook.
  • Keep public API contracts explicit and stable.
  • Add optional integrations behind interfaces (for example external metric sinks).
  • Keep transformations stateless and deterministic.
  • Introduce new Delta helpers as composable specs or services.

Planned growth areas:

  • Spark DataFrame-native transformation operators
  • Delta merge execution adapters with operation metrics extraction
  • Validation rule registry and severity model
  • OpenTelemetry-compatible observability adapters
  • Python 3.10+ with type hints for public interfaces.
  • Use docstrings for public modules, classes, and methods.
  • Keep comments conventional and explanatory, not inline noise.
  • Prefer immutable dataclasses for configuration and contracts.
  • Modules: snake_case
  • Classes: PascalCase
  • Functions and methods: snake_case
  • Constants: UPPER_SNAKE_CASE
  • New functionality must include tests.
  • Changes should not break existing tests.
  • Keep APIs general-purpose and not business-domain specific.
  • Avoid introducing notebook-runtime assumptions in core modules.
  1. Tests added before implementation updates.
  2. python -m pytest -q passes.
  3. Public API and behavior documented.
  4. Backward compatibility considered for exported symbols.

This implementation does not modify any existing production notebooks. Notebook migration to consume fabric-core is intentionally out of scope for this phase and can be handled as future work.