# eakmanrq/sqlframe architecture

> Architecture diagram of the GitHub repository eakmanrq/sqlframe, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/eakmanrq/sqlframe
- Repository: https://github.com/eakmanrq/sqlframe

## Overview

1. **What this repo is**
   SQLFrame is a Python library that recreates the PySpark DataFrame API while translating operations into SQL that can run on multiple backends. Its core architecture is an API compatibility layer plus engine-specific adapters.

2. **Primary layering**
   The codebase is organized into three major layers:
   - `sqlframe/base`: engine-agnostic DataFrame semantics and SQL construction
   - `sqlframe/<engine>`: backend adapters for execution and dialect differences
   - `sqlframe/standalone`: SQL generation without any live database connection

3. **Core abstraction layer**
   `sqlframe/base` contains the shared object model: `Session`, `DataFrame`, `Column`, `Group`, `Table`, `Catalog`, `ReaderWriter`, `Window`, `UDF`, `functions`, and supporting transforms/operations/types. This is where query plans are represented and where API methods are normalized before being rendered to SQL.

4. **How a transformation flows**
   A user constructs a DataFrame pipeline using Spark-like methods. Each method call updates the internal relational plan rather than executing immediately. When the user asks for SQL or triggers execution, the base layer composes the plan into a backend-specific SQL statement.

5. **Engine adapters**
   Each engine package (`bigquery`, `databricks`, `duckdb`, `postgres`, `redshift`, `snowflake`, `spark`) subclasses or specializes the base abstractions. These adapters encapsulate:
   - dialect-specific SQL rendering
   - engine-specific function behavior
   - session and catalog behavior
   - table/read/write integration
   - UDF and window function differences

6. **Dialect and function boundaries**
   The engine folders include their own `functions.py`, `column.py`, `dataframe.py`, `group.py`, `window.py`, `session.py`, `catalog.py`, `table.py`, `readwriter.py`, `types.py`, and `udf.py`. That structure indicates the repo isolates engine-specific SQL semantics at the boundary, while preserving a common user-facing API.

7. **Standalone mode**
   `sqlframe/standalone` is a special backend that does not connect to any engine. Its role is to produce SQL for inspection, debugging, or sharing. Architecturally, it is the pure compilation path: API objects in, SQL out, no execution backend.

8. **Activation and Spark compatibility**
   The top-level `sqlframe.activate` entry point lets SQLFrame replace or interpose on PySpark imports. That means the library supports two integration styles:
   - direct engine-specific sessions like `DuckDBSession`
   - compatibility mode where `pyspark.sql` imports resolve to SQLFrame behavior

9. **Execution and I/O boundary**
   Reading, writing, and table access are separated from transformation logic via session/readwriter/table/catelog modules. This keeps data source interaction at the edges while transformations remain engine-neutral until compilation/execution time.

10. **Testing strategy**
   The tests mirror the architecture:
   - unit tests for activation and engine-specific configuration
   - integration tests for shared DataFrame/session/catalog/table behavior
   - backend-specific integration suites per engine
   - fixture data in CSV, JSON, Parquet, Delta, and TPC-DS SQL files
   This suggests the project validates both API compatibility and cross-engine SQL correctness.

11. **External systems**
   The main external dependencies are the supported execution engines themselves: BigQuery, Databricks, DuckDB, Postgres, Redshift, Snowflake, and Spark. The repo also includes generated docs and GitHub Actions for CI/publishing, but those support the library rather than changing runtime architecture.

12. **What to draw in an architecture diagram**
   The most accurate diagram is:
   user code / PySpark-like API → SQLFrame base objects → engine adapter layer → backend SQL dialect / execution engine
   with a separate branch for `standalone` that stops at SQL generation, and a shared boundary for reading/writing/catalog/UDF/window behavior.

Main entry points: [`sqlframe/base/session.py`](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/session.py) (Session), [`sqlframe/testing/utils.py`](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/testing/utils.py) (Testing), [`sqlframe/base/dataframe.py`](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/dataframe.py) (DataFrame), [`sqlframe/__init__.py`](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/__init__.py) (Activate)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public API"]
  node_sqlframe_init["sqlframe<br/>package API<br/>[__init__.py]"]
  node_activate(("Activate<br/>compat hook<br/>[__init__.py]"))
end

subgraph group_core["Core Layer"]
  node_base_session["Session<br/>[session.py]"]
  node_base_dataframe["DataFrame<br/>relational plan<br/>[dataframe.py]"]
  node_base_column["Column<br/>expression model<br/>[column.py]"]
  node_base_functions["Functions<br/>builtins<br/>[functions.py]"]
  node_base_table["Table<br/>[table.py]"]
  node_base_io["Read/Write<br/>io boundary<br/>[readerwriter.py]"]
  node_base_catalog["Catalog<br/>metadata boundary<br/>[catalog.py]"]
  node_base_window["Window<br/>analytic ops<br/>[window.py]"]
  node_base_udf["UDFs<br/>extensibility<br/>[udf.py]"]
end

subgraph group_engines["Engine Adapters"]
  node_bigquery["BigQuery<br/>engine adapter<br/>[session.py]"]
  node_databricks["Databricks<br/>engine adapter<br/>[session.py]"]
  node_duckdb["DuckDB<br/>engine adapter<br/>[session.py]"]
  node_postgres["Postgres<br/>engine adapter<br/>[session.py]"]
  node_redshift["Redshift<br/>engine adapter<br/>[session.py]"]
  node_snowflake["Snowflake<br/>engine adapter<br/>[session.py]"]
  node_spark["Spark<br/>engine adapter<br/>[session.py]"]
end

subgraph group_standalone["Standalone"]
  node_standalone_session["Standalone<br/>sql compiler<br/>[session.py]"]
end

subgraph group_support["Support"]
  node_testing["Testing<br/>test support<br/>[utils.py]"]
end

node_sqlframe_init -->|"exports"| node_activate
node_activate -->|"routes to"| node_base_session
node_base_session -->|"creates"| node_base_dataframe
node_base_dataframe -->|"uses"| node_base_column
node_base_dataframe -->|"calls"| node_base_functions
node_base_dataframe -->|"uses"| node_base_window
node_base_dataframe -->|"extends"| node_base_udf
node_base_session -->|"consults"| node_base_catalog
node_base_session -->|"accesses"| node_base_table
node_base_session -->|"reads/writes"| node_base_io
node_base_session -->|"adapts"| node_bigquery
node_base_session -->|"adapts"| node_databricks
node_base_session -->|"adapts"| node_duckdb
node_base_session -->|"adapts"| node_postgres
node_base_session -->|"adapts"| node_redshift
node_base_session -->|"adapts"| node_snowflake
node_base_session -->|"adapts"| node_spark
node_base_session -->|"compiles"| node_standalone_session
node_testing -->|"verifies"| node_activate
node_testing -->|"verifies"| node_bigquery
node_testing -->|"verifies"| node_databricks
node_testing -->|"verifies"| node_duckdb
node_testing -->|"verifies"| node_postgres
node_testing -->|"verifies"| node_redshift
node_testing -->|"verifies"| node_snowflake
node_testing -->|"verifies"| node_spark
node_testing -->|"verifies"| node_standalone_session

click node_sqlframe_init "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/__init__.py"
click node_activate "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/__init__.py"
click node_base_session "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/session.py"
click node_base_dataframe "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/dataframe.py"
click node_base_column "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/column.py"
click node_base_functions "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/functions.py"
click node_base_table "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/table.py"
click node_base_io "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/readerwriter.py"
click node_base_catalog "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/catalog.py"
click node_base_window "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/window.py"
click node_base_udf "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/udf.py"
click node_bigquery "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/bigquery/session.py"
click node_databricks "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/databricks/session.py"
click node_duckdb "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/duckdb/session.py"
click node_postgres "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/postgres/session.py"
click node_redshift "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/redshift/session.py"
click node_snowflake "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/snowflake/session.py"
click node_spark "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/spark/session.py"
click node_standalone_session "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/standalone/session.py"
click node_testing "https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/testing/utils.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sqlframe_init,node_activate toneBlue
class node_base_session,node_base_dataframe,node_base_column,node_base_functions,node_base_table,node_base_io,node_base_catalog,node_base_window,node_base_udf toneAmber
class node_bigquery,node_databricks,node_duckdb,node_postgres,node_redshift,node_snowflake,node_spark toneMint
class node_standalone_session toneRose
class node_testing toneIndigo
```

## Components

### Public API

User-facing entry points and compatibility hooks

- [sqlframe](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/__init__.py): package API · Top-level package export surface · `sqlframe/__init__.py`
- [Activate](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/__init__.py): compat hook · Interposes on PySpark-style imports · `sqlframe/__init__.py`

### Core Layer

Engine-neutral DataFrame semantics and SQL plan construction

- [Session](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/session.py): core session · Coordinates frames, catalogs, readers, and SQL rendering · `sqlframe/base/session.py`
- [DataFrame](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/dataframe.py): relational plan · Spark-like transformation API backed by a query plan · `sqlframe/base/dataframe.py`
- [Column](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/column.py): expression model · Column expressions and SQL-ready operators · `sqlframe/base/column.py`
- [Functions](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/functions.py): builtins · Shared function catalog and normalized helpers · `sqlframe/base/functions.py`
- [Table](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/table.py): table boundary · Table access and schema-aware table operations · `sqlframe/base/table.py`
- [Read/Write](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/readerwriter.py): io boundary · Input and output adapters for external data sources · `sqlframe/base/readerwriter.py`
- [Catalog](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/catalog.py): metadata boundary · Database and schema lookup layer · `sqlframe/base/catalog.py`
- [Window](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/window.py): analytic ops · Window specification and analytic function support · `sqlframe/base/window.py`
- [UDFs](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/base/udf.py): extensibility · User-defined function normalization and SQL integration · `sqlframe/base/udf.py`

### Engine Adapters

Backend-specific SQL dialect and execution integrations

- [BigQuery](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/bigquery/session.py): engine adapter · BigQuery-specific session, dialect, and I/O behavior · `sqlframe/bigquery/session.py`
- [Databricks](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/databricks/session.py): engine adapter · Databricks-specific session, dialect, and I/O behavior · `sqlframe/databricks/session.py`
- [DuckDB](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/duckdb/session.py): engine adapter · DuckDB-specific session, dialect, and I/O behavior · `sqlframe/duckdb/session.py`
- [Postgres](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/postgres/session.py): engine adapter · PostgreSQL-specific session, dialect, and I/O behavior · `sqlframe/postgres/session.py`
- [Redshift](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/redshift/session.py): engine adapter · Redshift-specific session, dialect, and I/O behavior · `sqlframe/redshift/session.py`
- [Snowflake](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/snowflake/session.py): engine adapter · Snowflake-specific session, dialect, and I/O behavior · `sqlframe/snowflake/session.py`
- [Spark](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/spark/session.py): engine adapter · Spark-compatible session, dialect, and I/O behavior · `sqlframe/spark/session.py`

### Standalone

Pure SQL generation without a live backend

- [Standalone](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/standalone/session.py): sql compiler · SQL-only compilation path without database execution · `sqlframe/standalone/session.py`

### Support

Testing and shared helpers

- [Testing](https://github.com/eakmanrq/sqlframe/blob/main/sqlframe/testing/utils.py): test support · Shared testing utilities and engine verification helpers · `sqlframe/testing/utils.py`

## Connections

- sqlframe → Activate: exports · Package surface exposes compatibility activation
- Activate → Session: routes to · Compatibility mode resolves into SQLFrame sessions
- Session → DataFrame: creates · Sessions construct and manage dataframes
- DataFrame → Column: uses · Transformations are expressed with column objects
- DataFrame → Functions: calls · High-level API normalizes through shared functions
- DataFrame → Window: uses · Analytic operations flow through window specs
- DataFrame → UDFs: extends · DataFrame operations can reference UDFs
- Session → Catalog: consults · Session delegates metadata and schema lookup
- Session → Table: accesses · Session mediates table-level operations
- Session → Read/Write: reads/writes · Session coordinates external data access
- Session → BigQuery: adapts · Engine sessions specialize the shared base session
- Session → Databricks: adapts · Engine sessions specialize the shared base session
- Session → DuckDB: adapts · Engine sessions specialize the shared base session
- Session → Postgres: adapts · Engine sessions specialize the shared base session
- Session → Redshift: adapts · Engine sessions specialize the shared base session
- Session → Snowflake: adapts · Engine sessions specialize the shared base session
- Session → Spark: adapts · Engine sessions specialize the shared base session
- Session → Standalone: compiles · Standalone mode reuses core semantics for SQL generation only
- Testing → Activate: verifies · Tests cover compatibility activation behavior
- Testing → BigQuery: verifies · Tests cover engine-specific behavior
- Testing → Databricks: verifies · Tests cover engine-specific behavior
- Testing → DuckDB: verifies · Tests cover engine-specific behavior
- Testing → Postgres: verifies · Tests cover engine-specific behavior
- Testing → Redshift: verifies · Tests cover engine-specific behavior
- Testing → Snowflake: verifies · Tests cover engine-specific behavior
- Testing → Spark: verifies · Tests cover engine-specific behavior
- Testing → Standalone: verifies · Tests cover standalone SQL compilation
