Repository: fabric-core
fabric-core
Section titled “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.
Purpose
Section titled “Purpose”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
Architecture
Section titled “Architecture”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.pyModule responsibilities:
exceptions: library-wide base exceptions and typed failuresspark: deterministic Spark profile configuration and validationio: OneLake path building and convention validationdelta: reusable merge/upsert condition builders and Delta service contractsschema: declarative schema field modeling and builder utilitiestransformations: stateless transformation helpersvalidations: validation result model and summarizationlogging: structured logger setup with contextual metadataobservability: pluggable metric event model and sink protocol
Installation
Section titled “Installation”Local development install
Section titled “Local development install”cd fabric-corepython -m pip install -e .[dev]Standard install
Section titled “Standard install”cd fabric-corepython -m pip install .Spark session configuration
Section titled “Spark session configuration”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)OneLake ABFSS path generation
Section titled “OneLake ABFSS path generation”from fabric_core.io.paths import OneLakePath
table_path = OneLakePath.build_table_path( workspace="Fabric", lakehouse="lh_business", table="fact_meter_readings",)Retryable HTTP I/O client
Section titled “Retryable HTTP I/O client”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)Delta merge condition creation
Section titled “Delta merge condition creation”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")Schema building
Section titled “Schema building”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()Transformations and validations
Section titled “Transformations and validations”from fabric_core.transformations.core import TransformationOpsfrom 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)Logging and observability
Section titled “Logging and observability”from fabric_core.logging.factory import create_loggerfrom 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))Test-Driven Development Workflow
Section titled “Test-Driven Development Workflow”Development follows red-green-refactor:
- Add or update unit tests first.
- Run tests and confirm failure (red).
- Implement minimal code to satisfy behavior (green).
- Refactor while keeping tests green.
Run tests:
cd fabric-corepython -m pytest -qExtend and Further Develop
Section titled “Extend and Further Develop”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
Contribution Guidelines and Conventions
Section titled “Contribution Guidelines and Conventions”Coding conventions
Section titled “Coding conventions”- 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.
Naming conventions
Section titled “Naming conventions”- Modules:
snake_case - Classes:
PascalCase - Functions and methods:
snake_case - Constants:
UPPER_SNAKE_CASE
Quality gates
Section titled “Quality gates”- 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.
Pull request checklist
Section titled “Pull request checklist”- Tests added before implementation updates.
python -m pytest -qpasses.- Public API and behavior documented.
- Backward compatibility considered for exported symbols.
Current Scope Note
Section titled “Current Scope Note”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.