Skip to main content

SnowFrame

SnowFrame is a lightweight SQL workspace for Pandas DataFrames. It lets you register DataFrames as SQL tables, run warehouse-style SQL using DuckDB, and export final outputs back to Pandas.

Pandas DataFrames  →  SnowFrame tables  →  SQL operations  →  Pandas DataFrame

Installation

# Clone or download the repo, then install in editable mode
pip install -e .

# With Jupyter / notebook magic support
pip install -e ".[notebook]"

# With Excel export support
pip install -e ".[excel]"

# Full dev install (includes pytest, openpyxl, ipython)
pip install -e ".[dev]"

Quick start

import pandas as pd
from snowframe import SnowFrame

sales_df = pd.DataFrame({
    "customer_id": [1, 1, 2, 3],
    "amount":      [100, 2500, 700, 1800],
})

customers_df = pd.DataFrame({
    "customer_id": [1, 2, 3],
    "name":        ["Amit", "Riya", "Kabir"],
})

sf = SnowFrame()
sf.load({
    "sales":     sales_df,
    "customers": customers_df,
})

sf.sql("""
    CREATE TABLE final AS
    SELECT
        c.customer_id,
        c.name,
        SUM(s.amount) AS total_amount
    FROM sales s
    JOIN customers c
        ON s.customer_id = c.customer_id
    GROUP BY c.customer_id, c.name
""")

final_df = sf.to_df("final")
print(final_df)

API reference

SnowFrame()

Creates a new session backed by an in-memory DuckDB connection.

sf.load(data)

Register one or more DataFrames.

# Dict → named tables
sf.load({"sales": sales_df, "customers": customers_df})

# Tuple / list → auto-named table1, table2, …
sf.load((df1, df2, df3))

sf.register(name, df)

Register a single DataFrame as a named table.

sf.register("products", products_df)

sf.tables()

Return a Pandas DataFrame listing all registered table names.

sf.tables()
#    table_name
# 0   customers
# 1       sales

sf.sql(query)

Execute any DuckDB SQL statement. Returns self for chaining.

sf.sql("CREATE TABLE big AS SELECT * FROM sales WHERE amount > 1000")
sf.sql("DROP TABLE big")

sf.to_df(table_name)

Read a table back into a Pandas DataFrame.

final_df = sf.to_df("final")

sf.run_file(path)

Execute all SQL statements in a .sql file (split on ;).

sf.run_file("examples/analysis.sql")
final_df = sf.to_df("final")

sf.to_csv(table_name, path) / sf.to_excel(table_name, path)

Export a table to CSV or Excel.

sf.to_csv("final", "output/final.csv")
sf.to_excel("final", "output/final.xlsx")   # requires openpyxl

sf.auto()

Scan the calling scope and auto-register every Pandas DataFrame as a table.

sales     = pd.DataFrame(...)
customers = pd.DataFrame(...)

sf = SnowFrame()
sf.auto()          # registers 'sales' and 'customers' automatically

sf.query_df(sql_text)

Run a SELECT-style query and return a Pandas DataFrame directly.

df = sf.query_df("SELECT * FROM sales WHERE amount > 1000")

sf.show(table_name, limit=10)

Preview the first N rows of a table.

sf.show("sales")           # first 10 rows
sf.show("final", limit=5)  # first 5 rows

sf.describe(table_name)

Show column names and types (DuckDB DESCRIBE).

sf.describe("sales")

sf.close()

Close the underlying DuckDB connection.


SQL file usage

Write SQL in a dedicated file and run it against a live session:

-- examples/analysis.sql
CREATE OR REPLACE TABLE summary AS
SELECT
    c.name,
    COUNT(s.amount)         AS num_orders,
    SUM(s.amount)           AS total_amount,
    ROUND(AVG(s.amount), 2) AS avg_amount
FROM sales s
JOIN customers c ON s.customer_id = c.customer_id
GROUP BY c.name
ORDER BY total_amount DESC;

CREATE OR REPLACE TABLE high_value AS
SELECT * FROM summary WHERE total_amount > 1000;
sf = SnowFrame()
sf.load({"sales": sales_df, "customers": customers_df})
sf.run_file("examples/analysis.sql")

summary_df    = sf.to_df("summary")
high_value_df = sf.to_df("high_value")

Notebook / Databricks-style usage

Install

pip install -e ".[notebook]"
jupyter lab

Setup cell

%load_ext snowframe

import pandas as pd
from snowframe import SnowFrame, set_active_session

sales = pd.DataFrame({
    "customer_id": [1, 1, 2, 3, 3],
    "amount":      [100, 2500, 700, 1800, 300],
})
customers = pd.DataFrame({
    "customer_id": [1, 2, 3],
    "name":        ["Amit", "Riya", "Kabir"],
})

sf = SnowFrame()
sf.auto()              # auto-registers 'sales' and 'customers' from this scope
set_active_session(sf)
sf.tables()

DDL cell — creates a table, prints success + table list

%%sf

CREATE OR REPLACE TABLE final AS
SELECT
    c.name,
    SUM(s.amount) AS total_amount
FROM sales s
JOIN customers c
    ON s.customer_id = c.customer_id
GROUP BY c.name
ORDER BY total_amount DESC;

SELECT cell — displays result DataFrame inline

%%sf
SELECT * FROM final;

SHOW TABLES cell

%%sf
SHOW TABLES;

Back in Python

final_df = sf.to_df("final")

sf.show("final")          # first 10 rows
sf.describe("final")      # column names and types

Databricks users: The same pattern works in Databricks notebooks. Replace %%sf with a Python cell calling sf.query_df("SELECT …") or sf.sql("CREATE …") if cell magics are unavailable.


CLI

# Execute a SQL file (no pre-loaded DataFrames; useful for DuckDB file-based tables)
snowframe run examples/analysis.sql

Running the examples

pip install -e .
python examples/basic_usage.py

Running tests

pip install -e ".[dev]"
pytest tests/ -v

Limitations

  • In-memory only — all tables live in DuckDB's in-memory database. Nothing is persisted to disk unless you call to_csv / to_excel.
  • Single connection — each SnowFrame() instance has its own isolated DuckDB connection; tables are not shared between sessions.
  • SQL file parsing — run_file splits on ;. SQL comments that contain semicolons (-- note; ignore) may cause incorrect splits. Use -- comments without semicolons inside SQL files.
  • Table name safety — to_df(name) interpolates the table name directly into SQL. Use only valid SQL identifiers as table names.
  • Excel export — requires openpyxl: pip install openpyxl or pip install -e ".[excel]".
  • CLI — the snowframe run command has no mechanism to load Python DataFrames. It is useful for SQL that reads from DuckDB-native sources (e.g. READ_CSV, READ_PARQUET).

Metadata

Release files for snowframe 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for snowframe 0.1.0
File Size Uploaded Provenance Actions
snowframe-0.1.0.tar.gz 13.5 kB Without provenance Details for snowframe-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for snowframe 0.1.0
File Interpreter ABI Platform Actions
snowframe-0.1.0-py3-none-any.whl Python 3 none any Details for snowframe-0.1.0-py3-none-any.whl

Total release size: 24.8 kB

Release files / snowframe-0.1.0.tar.gz

Download URL snowframe-0.1.0.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
43b2e8810fc1de34d75496f2b7a79f8e575d4f76523b9d6192e3f2804fc641a6
BLAKE2b-256 checksum
How to use checksums
de96168f8d10290d9244f5e41d7cf79f0716545117ed861ae0362c81ad967e78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / snowframe-0.1.0-py3-none-any.whl

Download URL snowframe-0.1.0-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
95e65de38c8c4d9cbb1ca746248f4acd278ec1bfb0ca269350221fe8f1d659af
BLAKE2b-256 checksum
How to use checksums
006723b25a15cd1bb10cf80606cf4567ac0bf1bce1c6c2a3da437399f187cd95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Security for snowframe 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page