Run your PySpark DataFrame code on Hardcharger™, with no Spark cluster.
⚡ What is it?
The Hardcharger™ backend for SQLFrame, which implements the PySpark DataFrame API on SQL engines. Hardcharger is GizmoData™'s DuckDB 2.0 server; this package turns PySpark-style transformations into DuckDB SQL and runs them there, so Spark and Databricks jobs move over by swapping the session builder, not by rewriting them.
- The PySpark API:
SparkSession, DataFrames,functions,Window, the catalog, andactivate()so that unchangedfrom pyspark.sql import ...code runs on Hardcharger. - Bulk loading:
session.ingest()streams Arrow tables, record batch readers and pandas DataFrames in through ADBC bulk ingest, as one transaction. - Client-local files:
spark.read.json()/.csv()/.parquet()on files on your machine parse them client-side (Spark-style schema inference for JSON) and bulk-load them into temporary tables; the server needs no access to your file system. - Connections:
adbc-driver-hardcharger, withhardcharger://URIs (TLS on by default, port 31337), password, access token, client certificate (mutual TLS) and browser (OAuth/SSO) sign-in, and OpenTelemetry traces of every statement.
📦 Install
pip install sqlframe-hardcharger
Python 3.11 or later. It installs SQLFrame, pyarrow and the driver,
adbc-driver-hardcharger 2.7.2 or newer, from PyPI.
🚀 Quick start
from sqlframe_hardcharger import HardchargerSession
spark = (
HardchargerSession.builder.config("hardcharger.uri", "hardcharger://localhost")
.config("hardcharger.username", "hardcharger")
.config("hardcharger.password", "change-me")
.getOrCreate()
)
people = spark.createDataFrame(
data=[(1, "Alice", 34), (2, "Bob", 27), (3, "Carol", 41)],
schema=["id", "name", "age"],
)
people.filter(people.age > 30).select("name", "age").orderBy("age").show()
+-------+-----+
| name | age |
+-------+-----+
| Alice | 34 |
| Carol | 41 |
+-------+-----+
hardcharger://host[:port] is HTTPS on port 31337 unless the URI names another; the server's
certificate is verified. For a development server on plain HTTP, add ?tls=false.
🐍 PySpark code, unchanged
activate() points the pyspark imports at Hardcharger, so existing PySpark code runs as is:
from sqlframe_hardcharger import activate
activate(uri="hardcharger://localhost", username="hardcharger", password="change-me")
from pyspark.sql import SparkSession
from pyspark.sql import functions as F
from pyspark.sql.window import Window
spark = SparkSession.builder.getOrCreate()
sales = spark.createDataFrame(
data=[("east", "2026-10-01", 120.0), ("east", "2026-10-02", 80.0), ("west", "2026-10-01", 200.0)],
schema=["region", "day", "amount"],
)
by_region = sales.groupBy("region").agg(F.sum("amount").alias("total"), F.count("*").alias("days"))
by_region.orderBy("region").show()
running = Window.partitionBy("region").orderBy("day")
sales.withColumn("running_total", F.sum("amount").over(running)).orderBy("region", "day").show()
SparkSession here is a HardchargerSession, so everything below (spark.ingest(),
the client-local readers) works through it too.
🔐 Connecting
Every setting is a hardcharger.<name> config key on the builder, or the same name as a keyword
argument of activate(). They are the keyword arguments of
adbc_driver_hardcharger.dbapi.connect():
| Key | Meaning |
|---|---|
hardcharger.uri |
hardcharger://host[:port] (HTTPS, port 31337); ?tls=false for plain HTTP |
hardcharger.username, hardcharger.password |
Password sign-in |
hardcharger.access_token |
An access token issued elsewhere, used as is |
hardcharger.auth_type |
password (default), client_certificate (mutual TLS, no password), or external (the server's browser sign-in, OAuth/SSO) |
hardcharger.tls_root_certs |
CA certificates to trust (PEM text or a file path) instead of the system's |
hardcharger.tls_skip_verify |
Don't verify the server's certificate (development only) |
hardcharger.tls_client_cert, hardcharger.tls_client_key |
Client certificate and key, for mutual TLS |
hardcharger.oauth_timeout, hardcharger.open_browser |
Browser sign-in: how long to wait, how to open the browser |
hardcharger.session_tag, hardcharger.query_tag |
JSON objects the server records with the session and its statements |
hardcharger.settings |
hardcharger.* session settings, e.g. {"query_timeout": 60} |
hardcharger.catalog, hardcharger.db_schema |
The session's current catalog and schema |
hardcharger.db_kwargs, hardcharger.conn_kwargs |
Any other ADBC option, by the driver's own option names (hardcharger.retry.max_attempts, hardcharger.ipc.compression, adbc.telemetry.*, ...; the DatabaseOptions and ConnectionOptions of adbc_driver_hardcharger). These are not the builder's keys: the builder's hardcharger.auth_type is connect()'s auth_type argument, while the driver option hardcharger.auth.type goes only in db_kwargs |
A token from your identity platform:
import os
from sqlframe_hardcharger import HardchargerSession
spark = (
HardchargerSession.builder.config("hardcharger.uri", "hardcharger://localhost")
.config("hardcharger.access_token", os.environ["HARDCHARGER_TOKEN"])
.getOrCreate()
)
spark.sql("SELECT HARDCHARGER_USER() AS signed_in_as").show()
A client certificate, on a server started with --mtls-ca-cert and --mtls-certificate-sign-in
(the token the server issues is bound to the certificate):
from sqlframe_hardcharger import HardchargerSession
spark = (
HardchargerSession.builder.config("hardcharger.uri", "hardcharger://localhost")
.config("hardcharger.auth_type", "client_certificate")
.config("hardcharger.tls_client_cert", "client.pem")
.config("hardcharger.tls_client_key", "client-key.pem")
.getOrCreate()
)
spark.sql("SELECT HARDCHARGER_USER() AS signed_in_as").show()
Browser sign-in (hardcharger.auth_type = external) opens the server's sign-in page (a server
started with --oauth-client-id; the sign-in runs on the server's own port) and waits for you to
finish there.
A session is a process-wide singleton, as in SQLFrame: once one exists, getOrCreate() returns it
until you call spark.stop().
📥 Bulk loading with ingest()
createDataFrame() sends rows as a SQL VALUES list, which is fine for a few thousand rows.
For anything bigger, ingest() streams Arrow data in through ADBC bulk ingest and returns a
DataFrame over the table:
import pyarrow as pa
from sqlframe_hardcharger import HardchargerSession
spark = (
HardchargerSession.builder.config("hardcharger.uri", "hardcharger://localhost")
.config("hardcharger.username", "hardcharger")
.config("hardcharger.password", "change-me")
.getOrCreate()
)
events = pa.table(data={"event_id": list(range(1_000_000)), "kind": ["click", "view"] * 500_000})
df = spark.ingest(table_name="events", data=events, mode="replace")
df.groupBy("kind").count().orderBy("kind").show()
data: apyarrow.Table,RecordBatchorRecordBatchReader, or apandas.DataFrame.mode:create(the default; fails if the table exists),append,create_appendorreplace.temporary=Truemakes a temporary table, visible to this session only.- An ingest is one transaction: if it fails part-way, none of its rows remain.
- The driver sends an upload of several batches over up to 8 connections at once, so its rows
land in no particular order;
ingest_parts=1sends one ordered stream.
📂 Reading files on your machine
spark.read.json(), .csv(), .parquet() and .load() notice when the path (a file, a glob
or a directory) exists on the client, parse it there, and bulk-load it into a temporary
table. The server never needs to see your files:
from sqlframe_hardcharger import HardchargerSession
spark = (
HardchargerSession.builder.config("hardcharger.uri", "hardcharger://localhost")
.config("hardcharger.username", "hardcharger")
.config("hardcharger.password", "change-me")
.getOrCreate()
)
with open("orders.jsonl", "w") as f:
f.write('{"id": 1, "customer": {"name": "Alice", "tier": "gold"}, "items": [{"sku": "A1", "qty": 2}]}\n')
f.write('{"id": 2, "customer": {"name": "Bob"}, "items": [], "note": "gift"}\n')
orders = spark.read.json("orders.jsonl")
orders.printSchema()
orders.select("id", orders["customer"]["name"].alias("customer")).orderBy("id").show()
with open("people.csv", "w") as f:
f.write("id,name\n1,Alice\n2,Bob\n")
spark.read.csv("people.csv", header=True, inferSchema=True).show()
- JSON schemas are inferred the way Spark does it: one column per top-level key, objects as
structs, arrays as arrays, fields sorted by name, and a field seen with conflicting types
falling back to
string(its JSON text). Inference streams the files, one record at a time, while they upload. - Objects keyed by ids become MAPs. An object whose keys are data rather than field names
(ids or dates as keys, a different set in every document, as in many MongoDB exports) is
inferred as
map<string, ...>, by DuckDB's rule forread_json: more thanmapInferenceThreshold(default 200) distinct keys under it, and either each key appears on average in fewer than 10% of the (non-empty) objects seen there, or the values all merge into one type and the keys appear in fewer than half of the objects (or the object was seen once). Spark would make one struct field per key ever seen, which grows with every document and makes inference quadratic. A wide record, whose keys are in nearly every object, stays a struct as in Spark (DuckDB would make one whose fields share a type a MAP); empty objects change nothing, and the top level always gives one column per key. The under-10% part is decided as documents are read, so an unusual order (many sparse objects first) can still give a MAP. To pin a column's type in a pipeline, pass a schema..option("mapInferenceThreshold", None)turns MAPs off, and then the schema is Spark's (checked against PySpark 4.3 on a differential fuzz, empty strings and{}included:""infers as a null, a field that is only ever{}is dropped), except that an object whose keys differ only in case (aandA) stays JSON text, since a DuckDB struct can't hold both. Take a MAP apart withF.size(),F.map_keys(),F.map_values(),F.map_entries()andF.explode()of those, or look a key up withdf["m"]["key"](example below). - Another deliberate difference from Spark: a nested subtree with more than
maxNestedFieldsfields (default 1000, counted recursively) stays oneJSONcolumn rather than an enormous struct; query it withget_json_object()..option("maxNestedFields", None)expands everything. .option("jsonDocument", True)skips parsing: each document lands as text in a singleJSONcolumn, for data whose shape is too unstable to type.- A schema skips inference:
spark.read.schema(schema).json(path)orjson(path, schema=...), with aStructType(also from Spark's JSON form:StructType.fromJson(json.load(f)), for a schema kept in a file) or a DDL string such as"id STRING, attribute MAP<STRING, STRING>". - Also honored:
schema,header,sep/delimiter,multiLine,samplingRatio,filename,encoding. Other options are ignored, with a warning; use.option("serverSideRead", True)to have the server read the path with DuckDB's ownread_json()/read_csv()/read_parquet()(and all their options) instead. - Rows keep the files' order (one ordered upload);
.option("ingestParts", 8)uploads in parallel instead. - A path the client can't see goes to the server as before (
read_csv(...)on the server's file system), as dos3://and other remote URLs.
Data keyed by ids, read into a MAP and taken apart into rows:
import json
from sqlframe_hardcharger import HardchargerSession
from sqlframe_hardcharger import functions as F
spark = (
HardchargerSession.builder.config("hardcharger.uri", "hardcharger://localhost")
.config("hardcharger.username", "hardcharger")
.config("hardcharger.password", "change-me")
.getOrCreate()
)
with open("forms.jsonl", "w") as f:
for n in range(20):
fields = {f"form{n}_field_{i}": {"name": f"field_{i % 4}", "value": str(i * n)} for i in range(40)}
f.write(json.dumps({"id": f"form{n}", "fields": fields}) + "\n")
forms = spark.read.json("forms.jsonl")
forms.printSchema()
forms.select("id", F.size("fields").alias("fields")).orderBy("id").show(3)
values = forms.select(F.explode(F.map_values("fields")).alias("v"))
values.select(values["v"]["name"].alias("name")).groupBy("name").count().orderBy("name").show()
root
|-- fields: map<string, struct<`name`: string, `value`: string>> (nullable = true)
| |-- key: string (nullable = true)
| |-- value: struct<`name`: string, `value`: string> (nullable = true)
| | |-- name: string (nullable = true)
| | |-- value: string (nullable = true)
|-- id: string (nullable = true)
+--------+--------+
| id | fields |
+--------+--------+
| form0 | 40 |
| form1 | 40 |
| form10 | 40 |
+--------+--------+
+---------+-------+
| name | count |
+---------+-------+
| field_0 | 200 |
| field_1 | 200 |
| field_2 | 200 |
| field_3 | 200 |
+---------+-------+
💾 Writing Parquet on your machine
df.write.parquet(path) has the server write the file, on the server's file system, as
DuckDB's COPY ... TO. With .option("clientSideWrite", True) the client streams the result down
and writes it to your file system instead, laid out as Spark lays it out: a folder of
part-00000-<id>-c000.snappy.parquet files and an empty _SUCCESS.
import pyarrow.parquet as pq
from sqlframe_hardcharger import HardchargerSession
spark = (
HardchargerSession.builder.config("hardcharger.uri", "hardcharger://localhost")
.config("hardcharger.username", "hardcharger")
.config("hardcharger.password", "change-me")
.getOrCreate()
)
sales = spark.createDataFrame(
data=[("east", 120.0), ("west", 200.0), ("east", 80.0)], schema=["region", "amount"]
)
sales.write.option("clientSideWrite", True).mode("overwrite").parquet("sales_parquet")
print(pq.read_table("sales_parquet").num_rows)
3
- Client memory stays bounded whatever the result's size: the server keeps the result as a temporary table and adds up each row's size (as text), and the client fetches row ranges of about 128 MB of that, in order (lists of numbers take up to a few times more as Arrow than as text). A single row larger than that comes on its own.
- Everything is checked before anything runs. The files are written to a hidden folder and moved into place at the end: an overwrite sets the old folder aside and puts it back if anything fails, Ctrl-C included; an append moves all of its files in or none.
- Modes as in Spark:
error(the default; alsoerrorifexists,default),ignore,overwriteandappend(more part files in the folder).overwritereplaces only a folder of Parquet part files (.DS_Store,_metadataand the like are fine); it refuses a symbolic link (give the folder it points to), a plain file, a sub-folder or any other file. - Options:
compression(snappyby default,zstd,gzip,lz4,brotli,none) andmaxRecordsPerFile(start a new part file after that many rows). Parquet only;partitionByisn't supported client-side.~is your home folder andfile://...a local path; other URLs (s3://...,dbfs:/...) are refused (leave the option off and the server writes them). - Columns of types Parquet can't hold (
INTERVAL,UNION) can't be written client-side; cast them first. saveAsTable()with a path writes the files too, as Spark does:df.write.format("parquet").option("path", p).saveAsTable(t)saves tableton the server and writes the data top, on the client withclientSideWrite, else on the server. The file write is checked before the table changes, the DataFrame is evaluated once (table and files hold the same rows), the files are written before the table changes and moved into place after it, andmode("ignore")with an existing table writes nothing. (SQLFrame used to ignore the format and path there and write no files.)
🔭 OpenTelemetry
The driver traces every statement (Database.Open, Statement.ExecuteQuery,
Statement.ExecuteUpdate) with OpenTelemetry. Turn it on with the standard OTEL_* environment
variables, or per session with the ADBC telemetry options:
from sqlframe_hardcharger import HardchargerSession
spark = (
HardchargerSession.builder.config("hardcharger.uri", "hardcharger://localhost")
.config("hardcharger.username", "hardcharger")
.config("hardcharger.password", "change-me")
.config(
"hardcharger.db_kwargs",
{"adbc.telemetry.traces_exporter": "adbcfile", "adbc.telemetry.traces_folder_path": "traces"},
)
.getOrCreate()
)
spark.sql("SELECT 42 AS answer").show()
adbcfile writes the spans to files in traces/; otlp sends them to an OpenTelemetry
collector (OTEL_EXPORTER_OTLP_ENDPOINT).
🧭 Good to know
- Column names written in
spark.sql()come back lowercased, even in backticks (SELECT 1 AS formIDgivesformid), as in every SQLFrame backend; Spark keeps their case. Names given through the DataFrame API (createDataFrame(),alias(),withColumn()) and columns read from files or ingested keep theirs. - Python UDFs (
spark.udf.register) can't run: the server would have to call back into your Python process. Usepyspark.sql.functionsor SQL. - In
spark.sql(), identifiers are quoted with backticks (the input dialect is Spark SQL, where double quotes are string literals). - Hardcharger runs DuckDB 2.0. Lambdas (
F.transform,F.filter, ...) are written in itsLAMBDA x : ...syntax; the arrow form older DuckDB took is refused there.
Coming from sqlframe-gizmosql
| sqlframe-gizmosql | sqlframe-hardcharger |
|---|---|
GizmoSQLSession, GizmoSQLDataFrame, ... |
HardchargerSession, HardchargerDataFrame, ... |
gizmosql.uri = grpc+tls://host:31337 or gizmosql://host |
hardcharger.uri = hardcharger://host |
gizmosql.username, .password, .tls_skip_verify, .auth_type |
the same names under hardcharger., plus access_token, tls_root_certs, client certificates and every other connect() argument |
gizmosql.max_msg_size |
gone: Chargewire streams uploads over HTTP, with no message-size limit |
ingest() appends staged through a temporary table |
an ingest is one transaction; ingest_parts controls parallel upload |
🛠️ Development
python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]" # plus adbc-driver-hardcharger from PyPI, or built from its repository
ruff check . && ruff format --check . && mypy
pytest tests/unit
SQLFRAME_HARDCHARGER_TEST_SERVER_BINARY=/path/to/hardcharger-server pytest -n 4
The live tests (everything outside tests/unit) start their own hardcharger-server
processes on free 127.0.0.1 ports, from the binary in SQLFRAME_HARDCHARGER_TEST_SERVER_BINARY;
without it they fail rather than skip. CI takes that binary from the
ghcr.io/gizmodata/hardcharger:main image. They are this package's own tests
(tests/integration) and SQLFrame's engine suite (tests/sqlframe_suite, vendored from
SQLFrame's release by scripts/vendor_sqlframe_suite.py and run against Hardcharger as SQLFrame
runs it against DuckDB). Every Python block in this README runs against a live server in CI
(scripts/run_readme_examples.py).
📦 Releasing
Semantic versioning and CHANGELOG.md. Pushing a vX.Y.Z
tag runs the full CI on the tagged commit, then builds the wheel and sdist and makes a GitHub
Release with the tag's CHANGELOG section.
📄 License
Apache License 2.0; see LICENSE. SQLFrame's engine tests in
tests/sqlframe_suite/upstream are MIT-licensed (see the LICENSE file there).
Built by GizmoData™
Hardcharger™ and GizmoData™ are trademarks of GizmoData LLC.
Metadata
Release files for sqlframe-hardcharger 2.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sqlframe_hardcharger-2.4.0.tar.gz | 63.9 kB | With provenance | Details for sqlframe_hardcharger-2.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sqlframe_hardcharger-2.4.0-py3-none-any.whl | Python 3 | none | any | Details for sqlframe_hardcharger-2.4.0-py3-none-any.whl |
Total release size: 127.3 kB
Release files / sqlframe_hardcharger-2.4.0.tar.gz
| Download URL | sqlframe_hardcharger-2.4.0.tar.gz |
|---|---|
| Size | 63.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6fa5bb9bf084d445c51d8a8b9e0e61bbb40b476cd9785f5c2f7558dc965b580f
|
|
BLAKE2b-256 checksum How to use checksums |
8bb0b8d8f74056fe0bb8b5f2db0b4fd8a02949a4c32cd1218da69959d1c7e67e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logRelease files / sqlframe_hardcharger-2.4.0-py3-none-any.whl
| Download URL | sqlframe_hardcharger-2.4.0-py3-none-any.whl |
|---|---|
| Size | 63.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fa80eae33103ab4767197e3742e139deb0044d77e8e639d84b650d61e5199663
|
|
BLAKE2b-256 checksum How to use checksums |
49f278475f9d4f710b1596395ab4031590d4073b755a699b4712c5285354c31a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logSecurity for sqlframe-hardcharger 2.4.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for sqlframe_hardcharger-2.4.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logA 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.