narwhals-dev/narwhals

Lightweight and extensible compatibility layer between dataframe libraries!

What it solves

When you build a Python library that works with dataframes, you have to pick a favorite (pandas, Polars, etc.) or write separate support for each. Narwhals removes that burden by giving you one common, Polars-style API that works across many dataframe libraries, so your code runs unchanged on pandas, Polars, cuDF, Modin, PyArrow, DuckDB, PySpark, and more.

How it works

You wrap a native dataframe with narwhals.from_native, write your logic using a supported subset of the Polars API (expressions, lazy/eager operations), then convert back with narwhals.to_native. Narwhals has zero dependencies—it only uses what you pass in—and keeps computation native to the original library (e.g., GPU for cuDF, distributed for Modin). It also provides full static typing and a stable backward-compatibility policy.

Who it’s for

Developers who maintain dataframe-consuming libraries and want to support multiple backends without a lot of extra work. The README explicitly asks: "Do you maintain a dataframe-consuming library?" and lists many projects like scikit-learn, Altair, Bokeh, LightGBM, Plotly, and more that already use it.

Highlights

  • Zero dependencies—stays lightweight
  • Uses a subset of the Polars API so there's nothing new to learn
  • Separate lazy and eager APIs with expressions
  • Handles pandas' complex type system and index cleanly
  • 100% branch coverage, tested against nightly builds of pandas and Polars
  • Negligible overhead
  • Full static typing for IDE support
  • Perfect backward compatibility policy
  • Used by many popular libraries (scikit-learn, Altair, Bokeh, etc.)

Related

  • Project
  • Project
  • Project
  • Project
  • Project