narwhals: Extremely lightweight compatibility layer between dataframe libraries · Pythie
Narwhals
Extremely lightweight and extensible compatibility layer between dataframe libraries!
Full API support : cuDF, Modin, pandas, Polars, PyArrow.
Lazy-only support : Dask, DuckDB, Ibis, PySpark, SQLFrame, Daft via the
narwhals-daft plugin, and Apache DataFusion via the
narwhals-datafusion plugin.
Seamlessly support all, without depending on any!
✅ Just use a subset of the Polars API , no need to learn anything new
✅ Zero dependencies , Narwhals only uses what
the user passes in so your library can stay lightweight
✅ Separate lazy and eager APIs, use expressions
✅ Support pandas' complicated type system and index, without
either getting in the way
✅ 100% branch coverage , tested against pandas and Polars nightly builds
✅ Negligible overhead , see
✅ Let your IDE help you thanks to full static typing , see typing ✅ Perfect backwards compatibility policy ,
see stable api for how to opt-in
Installation
Usage There are three steps to writing dataframe-agnostic code using Narwhals:
use narwhals.from_native to wrap a pandas/Polars/Modin/cuDF/PyArrow
DataFrame/LazyFrame in a Narwhals class
use the subset of the Polars API supported by Narwhals
use narwhals.to_native to return an object to the user in its original
dataframe flavour. For example:
if you started with pandas, you'll get pandas back
if you started with Polars, you'll get Polars back
if you started with Modin, you'll get Modin back (and compute will be distributed)
if you started with cuDF, you'll get cuDF back (and compute will happen on GPU)
if you started with PyArrow, you'll get PyArrow back
Example Narwhals allows you to define dataframe-agnostic functions. For example:
import narwhals as nw
from narwhals.typing import IntoDataFrameT, IntoLazyFrameT
def agnostic_function(
df_native: IntoDataFrameT | IntoLazyFrameT,
) -> IntoDataFrameT | IntoLazyFrameT:
return (
nw.from_native(df_native)
.with_columns(
category=nw.when(nw.col("animal").str.contains("whale"))
.then(nw.lit("whale"))
.otherwise(nw.lit("other"))
)
.to_native()
)
You can then pass pandas.DataFrame, polars.DataFrame, polars.LazyFrame, duckdb.DuckDBPyRelation,
pyspark.sql.DataFrame, pyarrow.Table, and more, to agnostic_function. In each case, no additional
dependencies will be required, and computation will stay native to the input library:
import duckdb
import polars as pl
import pandas as pd
data = {
"animal": ["blue whale", "orca", "dolphin", "humpback whale", "seal"],
"length_m": [30.0, 8, 2.5, 17, 2.2],
"weight_kg": [150000, 4000, 200, 30000, 85],
}
print("Polars result")
df_pl = pl.DataFrame(data)
print(agnostic_function(df_pl))
print("DuckDB result")
print(agnostic_function(duckdb.sql("select * from df_pl")))
print("pandas result")
df_pd = pd.DataFrame(data)
print(agnostic_function(df_pd))
Polars result
shape: (5, 4)
┌────────────────┬──────────┬───────────┬──────────┐
│ animal ┆ length_m ┆ weight_kg ┆ category │
│ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ f64 ┆ i64 ┆ str │
╞════════════════╪══════════╪═══════════╪══════════╡
│ blue whale ┆ 30.0 ┆ 150000 ┆ whale │
│ orca ┆ 8.0 ┆ 4000 ┆ other │
│ dolphin ┆ 2.5 ┆ 200 ┆ other │
│ humpback whale ┆ 17.0 ┆ 30000 ┆ whale │
│ seal ┆ 2.2 ┆ 85 ┆ other │
└────────────────┴──────────┴───────────┴──────────┘
DuckDB result
┌────────────────┬──────────┬───────────┬──────────┐
│ animal │ length_m │ weight_kg │ category │
│ varchar │ double │ int64 │ varchar │
├────────────────┼──────────┼───────────┼──────────┤
│ blue whale │ 30.0 │ 150000 │ whale │
│ orca │ 8.0 │ 4000 │ other │
│ dolphin │ 2.5 │ 200 │ other │
│ humpback whale │ 17.0 │ 30000 │ whale │
│ seal │ 2.2 │ 85 │ other │
└────────────────┴──────────┴───────────┴──────────┘
pandas result
animal length_m weight_kg category
0 blue whale 30.0 150000 whale
1 orca 8.0 4000 other
2 dolphin 2.5 200 other
3 humpback whale 17.0 30000 whale
4 seal 2.2 85 other
Scope
Do you maintain a dataframe-consuming library?
Do you have a specific Polars function in mind that you would like Narwhals to have in order to make your work easier?
If you said yes to both, we'd love to hear from you!
Roadmap
Used by Feel free to add your project to the list if it's missing, and/or
chat with us on Discord if you'd like any support.
Sponsors and institutional partners Narwhals is 100% independent, community-driven, and community-owned.
We are extremely grateful to the following organisations for having
provided some funding / development time:
If you contribute to Narwhals on your organization's time, please let us know. We'd be happy to add your employer
to this list!
Support If you'd like to say "thank you", please give us a ⭐ star ⭐.
Receive professional support (e.g., if you're using or would like to use Narwhals at your company).
Have any Narwhals fixes / features prioritised.
Commission any Narwhals plugins for new backends.
Appears on Narwhals has been featured in several talks, podcasts, and blog posts:
Inspiring Computing Podcast
The Rise of Narwhals in Open-Source
PyCon DE & PyData 2025
How Narwhals is silently bringing pandas, Polars, DuckDB, PyArrow, and more together
The Python Exchange March 2025
What Can Narwhals Do for You?
PyData London 2025
How Narwhals brings Polars, DuckDB, PyArrow, & pandas together
Talk Python to me Podcast
Ahoy, Narwhals are bridging the data science APIs
Python Bytes Podcast
Episode 402, topic #2
Super Data Science: ML & AI Podcast
Narwhals: For Pandas-to-Polars DataFrame Compatibility
Sample Space Podcast | probabl
How Narwhals has many end users ... that never use it directly. - Marco Gorelli
The Real Python Podcast
Narwhals: Expanding DataFrame Compatibility Between Libraries
Pycon Lithuania 2024
Marco Gorelli - DataFrame interoperatiblity - what's been achieved, and what comes next?
Pycon Italy 2024
How you can write a dataframe-agnostic library - Marco Gorelli
Polars Blog Post
Polars has a new lightweight plotting backend
Quansight Labs blog post (w/ Scikit-Lego)
How Narwhals and scikit-lego came together to achieve dataframe-agnosticism
Why "Narwhals"? Popularity
Downloads, last 7 days 41.7M+8%
Stars, last 7 days –
Direct dependents 247
All dependents 45.2K 86
Healthy
Maintenance, out of 100
Recent release
last release 11 days ago
Commit activity
26/26 weeks with commits
Release cadence
20 releases in 12 months
Issues & PRs handled
38% closed in the past year
Contributor spread
22 authors in last 100 commits
OpenSSF Scorecard
not evaluated
Commits, last 26 weeks 341
Releases
Latest 2.29.0
Released Nov 17, 2026
Releases, 12 months 20
First release Feb 20, 2024 Compatibility
Requires Python >=3.10
Tested on 3.10 · 3.11 · 3.12 · 3.13 · 3.14
License MIT (Permissive) Works well withUse together with narwhals: extensions, drivers, servers and companion tools.
pandas Pythie’s Index: 88Powerful data structures for data analysis, time series, and statistics 720.9M downloads/mo polars Blazingly fast DataFrame library
73.3M downloads/mo
pyspark Pythie’s Index: 84Apache Spark Python API 48.4M downloads/mo libcudf-cu12 Pythie’s Index: 89cuDF - GPU Dataframe (C++) 260.3K downloads/mo annsel Pythie’s Index: 51A Narwhals powered DataFrame-style selection, filtering and indexing operations on AnnData Objects. 80.8K downloads/mo