RepositoryPython
narwhals-dev

narwhals-dev/narwhals

Lightweight and extensible compatibility layer between dataframe libraries!

1.8kstars
296forks
198issues
2views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: cudf

#1 Repository of the week

1
TINIX TRENDING·Topic: polars

#1 Repository of the week

1
TINIX TRENDING·Topic: ibis

#1 Repository of the week

Narwhals

narwhals_small

PyPI version Downloads Trusted publishing PYPI - Types LFX Health Score OpenSSF Scorecard

Extremely lightweight and extensible compatibility layer between dataframe libraries!

  • Full API support: cuDF, Modin, pandas, Polars, PyArrow.
  • Lazy-only support: Daft, Dask, DuckDB, Ibis, PySpark, SQLFrame.

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 overhead
  • ✅ Let your IDE help you thanks to full static typing, see typing
  • ✅ Perfect backwards compatibility policy, see stable api for how to opt-in

Get started!

Table of contents

Installation

  • pip (recommended, as it's the most up-to-date)
    pip install narwhals
    
  • conda-forge (also fine, but the latest version may take longer to appear)
    conda install -c conda-forge narwhals
    

Usage

There are three steps to writing dataframe-agnostic code using Narwhals:

  1. use narwhals.from_native to wrap a pandas/Polars/Modin/cuDF/PyArrow DataFrame/LazyFrame in a Narwhals class

  2. use the subset of the Polars API supported by Narwhals

  3. 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

narwhals_gif

Example

Narwhals allows you to define dataframe-agnostic functions. For example:

import narwhals as nw
from narwhals.typing import IntoFrameT


def agnostic_function(df_native: IntoFrameT) -> IntoFrameT:
    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

See the tutorial for several examples!

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

See roadmap discussion on GitHub for an up-to-date plan of future work.

Used by

Join the party!

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 ⭐.

Please contact hello_narwhals@proton.me if you would like to:

  • 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:

Why "Narwhals"?

Coz they are so awesome.

Thanks to Olha Urdeichuk for the illustration!

Similar Projects

Discover other similar projects and AI models.

RepositoryC++
NVIDIA/cudf

cuDF - GPU DataFrame Library

9.8k
Dec 1, 2026
RepositoryPython
dask/dask

Parallel computing with task scheduling

14.0k
Nov 25, 2026
RepositoryPython
shy3130/tick-stock-panel

TSP自托管、零运维的 A 股「自建策略 + 监控 + 回测」量化工作台引擎 | LLM能力驱使策略定制+个股分析+复盘 | 自由接入第三方数据源与个性化扩展数据 | 能力插件化可自由扩展开发

8.5k
Dec 1, 2026
RepositoryPython
pydata/xarray

N-D labeled arrays and datasets in Python

4.2k
Nov 26, 2026
RepositoryPython
uber/petastorm

Petastorm library enables single machine or distributed training and evaluation of deep learning models from datasets in Apache Parquet format. It supports ML frameworks such as Tensorflow, Pytorch, and PySpark and can be used from pure Python code.

1.9k
Jan 2, 2026
Dataset
yatin-superintelligence/Edge-Agent-Reasoning-WebSearch-260K

Edge Agent Reasoning WebSearch 260K Abstract The Edge-Agent-Reasoning-WebSearch-260K dataset is a massive, synthetically expert-engineered corpus of over 700 Million tokens, designed to train small, local models (SLMs) and edge-deployed agents in advanced problem deconstruction and self-aware reasoning. Rather than training a model to execute instructions directly—which often leads to hallucinations when context is missing—this dataset trains a model to act as a… See the full description on the dataset page: https://huggingface.co/datasets/yatin-superintelligence/Edge-Agent-Reasoning-WebSearch-260K.

♥0
6.3k
Mar 13, 2026
RepositoryRust
wheretrue/biobear

Work with bioinformatic files using Arrow, Polars, and/or DuckDB

199
Mar 10, 2025
Dataset
yatin-superintelligence/Creative-Professionals-Agentic-Tasks-1M

Creative Professionals Agentic Tasks (1M) Abstract A massive-scale, high-fidelity synthetic task dataset comprising 1,070,917 agentic command operations across 36 creative, technical, and engineering software environments. This dataset is engineered exclusively to stress-test, evaluate, and fine-tune multimodal AI agents designed for Agent Environment operation, complex software interaction, and multi-step reasoning within deep software infrastructures.… See the full description on the dataset page: https://huggingface.co/datasets/yatin-superintelligence/Creative-Professionals-Agentic-Tasks-1M.

♥0
447
Mar 13, 2026
RepositoryVue
hi-primus/bumblebee

🚕 A spreadsheet-like data preparation web app that works over Optimus (Pandas, Dask, cuDF, Dask-cuDF, Spark and Vaex)

141
Jul 15, 2023