It’s been a long time since I last wrote about the relative performance between the Polars and DuckDB libraries. Back then, Polars was at version 0.18.4, and DuckDB was at version 0.9.1.
My conclusion at the end of the article was that, aside from an issue reading Postgres data that Polars had trouble with, they were pretty much equal in performance, give or take a few seconds here or there.
Now, almost 3 years later, with both having recently released version 2 of their libraries, I thought it would be useful to revisit the subject and see whether either has pulled ahead.
In their own tests, the folks at DuckDB found that version 2.0 was 6 times faster than their current 1.56 release when processing the TPC-H SF300 dataset. For their part, Polars found it was faster than DuckDB versions 1.56 and 2.0 in all but one of their benchmarks.
So it will be interesting to see how they perform in my series of real-world data-processing tasks.
DuckDB and Polars are blazingly fast tools for processing data in Python, but they come from different backgrounds.
DuckDB began in 2018, created by Hannes Mühleisen and Mark Raasveldt in the Netherlands. It is an embedded analytical database: you run SQL queries directly inside your application, without setting up a separate database server.
Polars followed in 2020, created by Ritchie Vink. Written in Rust, it takes a DataFrame approach, letting you express transformations through operations on rows and columns. Its design relies heavily on parallel processing and query optimisation.
Both are built for analytical workloads. The main distinction is how you work with them: DuckDB centres on SQL, while Polars centres on DataFrame expressions. To be fair to Polars, it is now also trying to position itself as a SQL tool, with version 2.0 being the first to treat SQL as a first-class citizen in the Polars ecosystem.
Testing methodology
All tests were carried out using Windows. The tests are as follows.
Read data from a local Postgres table
Write data to a local Postgres table
Read and process text data on my local PC
Read Parquet data from AWS S3
Save the text data (from step 3 above) to Parquet data on AWS S3
Note that I ran all tests on my local PC via a Python Jupyter notebook. My PC spec is as follows:
CPU: Intel Core i9–13900K (13th generation)
Physical cores: 24
Logical processors / threads: 32
RAM: 64 GB installed (63.7 GB usable)
I ran each library test in a Jupyter Notebook. After each run, the notebook was completely closed down before being reopened for the next test run.
Prerequisites
You’ll need a local copy of a Postgres database that lets you create tables and read and write to them. You’ll also need read and write access to an AWS S3 bucket. My Postgres examples prompt for a database password, and my AWS examples assume you have an existing AWS credentials file on your local system.
Library installations
Please note that I have no association or affiliation (commercial or otherwise) with either library being tested.
I used Python 3.13.16, and I installed the following Python libraries via pip.
import polars as plimport duckdb as dbprint(f"Polars version: {pl.__version__}")print(f"DuckDB version: {db.__version__}")
You should get something like the following output
Polars version: 2.0.0DuckDB version: 2.0.0
If your DuckDB is still showing an older release version, try typing this into a Jupyter cell, run it, then restart the kernel.
%pip install --upgrade --pre duckdb
Test 1 – Reading from a Postgres table
I created a test table called sales_data_100 containing 100 million synthetic sales-related data. I ran the following code in my DBeaver client to create and populate the table. There were no indexes or keys on the table
DO $import$BEGIN CREATE TABLE public.sales_data_100m ( order_id bigint, order_date date, customer_id bigint, customer_name text, product_id bigint, product_names text, categories text, quantity integer, price numeric, total numeric ); COPY public.sales_data_100m FROM 'D:/sales_data/sales_data_100m.csv' WITH (FORMAT csv, HEADER MATCH, ENCODING 'UTF8');END$import$;
Polars doesn’t manage database connections and data transfer on its own. Instead, external libraries (known as engines) handle this. At present, Polars can use two engines to read from databases: one called ConnectorX and the other called ADBC. We used the latter.
from datetime import datetimefrom time import perf_counterimport duckdb as dbsource = "D:/sales_data/sales_data_100m.csv"destination = ( "s3://my-bucket/duckdb/sales_data_100m.parquet")region = "eu-west-1"# Prepare DuckDB outside the timed section.con = db.connect(database=":memory:")con.execute("INSTALL httpfs")con.execute("LOAD httpfs")con.execute("INSTALL aws")con.execute("LOAD aws")print(f"DuckDB version: {db.__version__}")print("DuckDB Timing — CSV to Parquet on S3")print("===================================")print(f"Destination: {destination}")print(f"Start time: {datetime.now():%H:%M:%S}")start = perf_counter()region_sql = region.replace("'", "''")source_sql = source.replace("'", "''")destination_sql = destination.replace("'", "''")con.execute(f""" CREATE OR REPLACE SECRET s3_credentials ( TYPE s3, PROVIDER credential_chain, CHAIN 'config', PROFILE 'default', REGION '{region_sql}' )""")# Read, compress and upload without first creating a full local table.con.execute(f""" COPY ( SELECT * FROM read_csv( '{source_sql}', header = true, types = {{ 'order_id': 'BIGINT', 'order_date': 'DATE', 'customer_id': 'BIGINT', 'customer_name': 'VARCHAR', 'product_id': 'BIGINT', 'product_names': 'VARCHAR', 'categories': 'VARCHAR', 'quantity': 'BIGINT', 'price': 'DOUBLE', 'total': 'DOUBLE' }} ) ) TO '{destination_sql}' ( FORMAT PARQUET, COMPRESSION ZSTD, COMPRESSION_LEVEL 3, ROW_GROUP_SIZE 100000 )""")elapsed = perf_counter() - startprint(f"End time: {datetime.now():%H:%M:%S}")print(f"Total elapsed time: {elapsed:.3f} seconds")print(f"Total elapsed time: {elapsed / 60:.2f} minutes")# Verify the output row count outside the timed section.records_written = con.execute(f""" SELECT COUNT(*) FROM read_parquet('{destination_sql}')""").fetchone()[0]print(f"Records verified on S3: {records_written:,}")con.close()
The results show that, once again, there is little difference in performance between the two libraries. Both output Parquet files were also of a similar size, with the DuckDB version coming in at 1.3 GB and the Polars version at 1.4 GB
Results
Polars version: 2.0.0Polars Timing — CSV to Parquet on S3===================================Destination: s3://taupirho-sales-data/polars/sales_data_100m.parquetStart time: 11:43:47End time: 11:45:44Total elapsed time: 116.484 secondsTotal elapsed time: 1.94 minutesRecords verified on S3: 100,000,000DuckDB version: 2.0.0DuckDB Timing — CSV to Parquet on S3===================================Destination: s3://taupirho-sales-data/duckdb/sales_data_100m.parquetStart time: 11:48:52End time: 11:50:46Total elapsed time: 113.570 secondsTotal elapsed time: 1.89 minutesRecords verified on S3: 100,000,000
Summary
Once again, except for the first test reading from a Postgres table, where DuckDB had a clear performance lead, my conclusion is similar to the one I came to almost 3 years ago.
Both are fast, equally capable data-processing libraries. If you’re comfortable with SQL, I’d use DuckDB. Operations on database tables are often easier to code and understand than the equivalent Polars (or Pandas) dataframe operations. However, Polars is pushing SQL into more of its operations, and we’ll have to see how that develops in upcoming releases.
If you’re already familiar with a DataFrame-based library like Pandas and want a significant performance boost, Polars is worth considering.
One distinct advantage Polars currently has over DuckDB is that it can run on a cluster of distributed servers via its Polars Cloud product. This lets Polars process terabyte-scale datasets.
The closest equivalent for DuckDB is a product called MotherDuck, which is built around DuckDB but is a separate entity and not involved in Amazon Web Services’ recent takeover of DuckDB. I would be amazed if, given this acquisition and DuckDB’s recent announcement of their new quack networking protocol, AWS don’t deliver a similar cloud-based service for DuckDB very soon.