Skip to main content

Loading and extracting Supabase data from Python with ArpePGSQL

François Pacull
François Pacull, ARPE.IO Developer
2026-11-26 · 9 min · ADBC
TL;DR

We load 1,000,000 rows of TPC-H lineitem from a Parquet file into a Supabase Free plan database with ArpePGSQL, and read them back as Arrow, in Python. Everything goes through the Supabase shared pooler, in session and in transaction mode, and the data comes back identical. The best of three runs is about 6 s for the write and 8 s for the read, over Wi-Fi; some runs take two to three times as long. The post covers the connection, TLS, the 2-minute statement timeout, the pooling modes and the limits of the Free plan.

A Supabase project comes with a PostgreSQL database, which any PostgreSQL client can write to and read from. We load an Apache Arrow table of 1,000,000 rows into a Supabase database from Python, and extract it back, with ArpePGSQL, our ADBC driver for PostgreSQL. The data goes in with a binary COPY and comes back as Arrow, without a conversion to Python objects on the way.

Outline

Setup​

ArpePGSQL is installed and registered with the ADBC driver manager by a one-line script, as described in the documentation. The script takes the path of a licence file; you can get a free 30-day trial licence for ArpePGSQL from the trial page, which also gives the install command.

curl -fsSL https://raw.githubusercontent.com/arpe-io/adbc-drivers/main/install.sh \
| sh -s -- arpepgsql --license /path/to/your.lic
pip install adbc-driver-manager pyarrow polars

System and package versions​

PythonPython 3.14.2, Linux
  • adbc_driver_manager 1.13.0
  • pyarrow 26.0.1
  • polars 2.1.0
Driver
  • ArpePGSQL 0.5.6
PostgreSQLSupabase
  • PostgreSQL 17.12
  • Free plan, Nano instance
  • eu-west-2

The data is the first 1,000,000 rows of the TPC-H lineitem table, read from a Parquet file with pyarrow: 16 columns (integers, decimals, strings and dates), 165 MiB in Arrow.

Connection​

The Connect dialog of the Supabase dashboard lists three endpoints:

EndpointHostPortUser
Directdb.<project-ref>.supabase.co5432postgres
Pooler, session modeaws-1-<region>.pooler.supabase.com5432postgres.<project-ref>
Pooler, transaction modesame host6543postgres.<project-ref>

The direct host only has an IPv6 address (IPv4 is a paid add-on), and so does the dedicated pooler of the paid plans. From our IPv4-only network, everything goes through the shared pooler, Supavisor, with the user name postgres.<project-ref>. The postgres role has full administrative rights; for a regular loading job, a role limited to the target schema would be more prudent.

import os
import adbc_driver_manager.dbapi as dbapi


def connect(port="5432"): # 6543 for transaction mode; ADBC options are strings
return dbapi.connect(driver="arpepgsql", db_kwargs={
"adbc.arpepgsql.server": os.environ["SUPABASE_HOST"],
"adbc.arpepgsql.port": port,
"adbc.arpepgsql.database": "postgres",
"adbc.arpepgsql.username": os.environ["SUPABASE_USER"],
"adbc.arpepgsql.password": os.environ["SUPABASE_PASSWORD"],
"adbc.arpepgsql.sslmode": "require",
})
TLS

With sslmode=require, used for all the timings below, the connection is encrypted but the server certificate is not checked. sslmode=verify-full also needs the CA certificate of the project, which is not in the operating system's bundle: prod-ca-2021.crt, in Database Settings, SSL Configuration, passed with the adbc.arpepgsql.ssl_root_cert option. The same page has an "Enforce SSL on incoming connections" option; our project, without it, also accepted unencrypted connections.

Load​

The code blocks run in order, in the same Python session. pyarrow.dataset reads only the first 1,000,000 rows of the Parquet file, and adbc_ingest creates the table from the Arrow schema and streams the rows with COPY ... FROM STDIN (FORMAT binary):

import pyarrow.dataset as ds

data = ds.dataset("lineitem_sf1.parquet").head(1_000_000)

with connect() as conn, conn.cursor() as cur:
cur.execute("CREATE SCHEMA IF NOT EXISTS supatest")
cur.execute("SET LOCAL statement_timeout = 0")
n = cur.adbc_ingest("lineitem", data, mode="replace", db_schema_name="supatest")
conn.commit()

print(n) # 1000000

Following PEP 249, autocommit is off and leaving the with block closes the connection without committing, unlike with conn: in sqlite3 or psycopg2: the commit is explicit. The project applies a global statement_timeout of 2 minutes, which would cancel a longer COPY. SET LOCAL lifts it for this transaction only, and has no effect with autocommit on; a lasting change is ALTER ROLE ... SET statement_timeout (documentation).

Why not public

The table goes to its own schema, supatest: the Data API exposes public, where a table without Row Level Security can be read and written by anyone holding the public anon key of the project.

The created table has bigint, numeric(15,2), text and date columns, all NOT NULL as in the Parquet file, and no primary key. The Table Editor of the dashboard does not edit rows without one; it can be added after the load:

ALTER TABLE supatest.lineitem ADD PRIMARY KEY (l_orderkey, l_linenumber);

Extract​

A query returns an Arrow table:

with connect() as conn, conn.cursor() as cur:
cur.execute("SET LOCAL statement_timeout = 0")
cur.execute("SELECT * FROM supatest.lineitem ORDER BY l_orderkey, l_linenumber")
back = cur.fetch_arrow_table()
conn.commit()

print(back.cast(data.schema).equals(data)) # True

The Parquet file is already sorted by l_orderkey, l_linenumber, so the two tables can be compared row by row. The cast aligns a few column types read back from PostgreSQL with those of the file; it raises an error rather than change a value, so it cannot hide a difference.

To get a Polars DataFrame:

import polars as pl

df = pl.from_arrow(back)

The decimal and date columns become Polars Decimal and Date columns. Polars can also run the query on the connection itself, with pl.read_database(query, connection=conn). A large result can be read batch by batch:

with connect() as conn, conn.cursor() as cur:
cur.execute("SELECT * FROM supatest.lineitem")
for batch in cur.fetch_record_batch():
print(batch.num_rows) # a pyarrow.RecordBatch
conn.commit()

Results​

We ran the load and the extract three times in each pooling mode, from a laptop on Wi-Fi, over a home internet connection. The table gives the best time of the three runs for each operation:

Pooler modeWriteReadIdentical
session (5432)6.45 s (155,021 rows/s)7.63 s (131,040 rows/s)yes
transaction (6543)6.08 s (164,432 rows/s)8.16 s (122,588 rows/s)yes
Run-to-run variation

This is not a benchmark, and the timings vary a lot: some runs took two to three times as long, up to 14.4 s for a write and 20.0 s for a read. We did not find the cause: the Wi-Fi, the network to the Supabase region, the shared pooler, or the Free plan instance. This instance (Nano) has a disk baseline of about 5 MB/s and 250 IOPS, and the smaller instances can only burst above it for a limited time; writing 144 MB and sorting 1,000,000 rows may be enough to reach it. The Database reports of the dashboard would tell during a slow run. About 3.9 s of each read is the server running the sorted query (EXPLAIN ANALYZE), before any row is sent.

Pooling modes​

In session mode (port 5432), a client keeps the same PostgreSQL server process for its whole connection. In transaction mode (port 6543), the pooler lends a server process for each transaction only, so what is attached to the process, such as a SET or a temporary table, may be missing in the next transaction. This is why the code uses SET LOCAL, which lasts until the commit, rather than SET.

Everything we tried worked in both modes: the calls of this post, bound parameters, executemany and the ADBC metadata calls. The documentation states that prepared statements are not supported in transaction mode; bound parameters probably work because ArpePGSQL sends them as unnamed statements, parsed and run in a single exchange. A SET and a temporary table even carried over between transactions in our runs, probably because a single client on an idle project gave the pooler no reason to change process: it seems safer not to rely on it.

Free plan​

Database size
  • 500 MB, then read-only
  • full lineitem (6 M rows, ~860 MB) does not fit
Egress
  • 5 GB per month
  • ~180 MB per full read of the table
Activity
  • paused after a week without activity

The full lineitem table does not fit, hence the 1,000,000 rows. Extracts count as egress: about 25 to 30 full extracts of this table per month. DROP SCHEMA supatest CASCADE; removes everything this post created.

Driver downloads are at github.com/arpe-io/adbc-drivers. The binaries download freely and run once a licence is present. A 30-day trial licence can be downloaded for free for ArpePGSQL; for a full licence, contact us at sales@arpe.io or see arpe.io.

Try ArpePGSQL Now

Free 30-day trial