polars README

The project's README from github.com/pola-rs/polars. As one markdown file: README.md.

Polars logo

crates.io Latest Release PyPi Latest Release NPM Latest Release R-multiverse Latest Release DOI Latest Release

Documentation: Python - Rust - Node.js - R | Agents: Skill - MCP | User guide | Discord

Polars: Extremely fast Query Engine for DataFrames

Polars is an analytical query engine for DataFrames, written in Rust. It is designed to be fast, easy to use and expressive. Key features are:

To learn more, read the user guide.

Polars in action

Queries are composed from expressions. This lazy query gets optimized out of the box and runs in parallel across all available cores:

import polars as pl

df = (
    pl.scan_parquet("orders.parquet")
    .filter(pl.col("status") == "shipped")
    .group_by("customer_id")
    .agg(
        pl.col("amount").sum().alias("total"),
        pl.len().alias("n_orders"),
    )
    .sort("total", descending=True)
    .collect()
)

Performance

Polars is very fast. In fact, it is one of the best performing Dataframe solutions available. See the PDS-H benchmarks results.

Handles larger-than-RAM data

If you have data that does not fit into memory, Polars' query engine is able to process your query (or parts of your query) in a streaming fashion. This drastically reduces memory requirements, so you might be able to process your 250GB dataset on your laptop. Collect with collect(engine='streaming') to run the query streaming.

Installation

Python

Install the latest Polars version with:

pip install polars

See the User Guide for more details on optional dependencies

Compile Polars from source

If you want a bleeding edge release you should compile Polars from source. Advanced users can also compile for maximum performance for their architecture.

This can be done by going through the following steps in sequence:

  1. Install the latest Rust compiler
  2. Install maturin: pip install maturin
  3. cd py-polars and choose one of the following:
    • make build, slow binary with debug assertions and limited symbols, fast compile times
    • make build-debug, same as make build, but with all symbols, produces large binaries
    • make build-release, fast binary without debug assertions, minimal debug symbols, long compile times
    • make build-nodebug-release, same as build-release but without any debug symbols, slightly faster to compile
    • make build-debug-release, same as build-release but with full debug symbols, slightly slower to compile
    • make build-dist-release, fastest binary, extreme compile times

By default the binary is compiled with optimizations turned on for a modern CPU. Specify LTS_CPU=1 with the command if your CPU is older and does not support e.g. AVX2.

Note that the Rust crate implementing the Python bindings is called py-polars to distinguish from the wrapped Rust crate polars itself. However, both the Python package and the Python module are named polars, so you can pip install polars and import polars.

Check the Installation guide for more advanced installations. For example when you expect more than 2^32 (~4.2 billion) rows, run on an old CPU (e.g. dating from before 2011), or on an x86-64 build of Python on Apple Silicon under Rosetta.

Contributing

Want to contribute? Read our contributing guide and check the issue tracker for accepted issues.

Contributors new to the codebase can look for the good first issue label to get familiar with the project.

You can join the Polars Discord server for any help along the way.

Distributed Polars

Running into hardware limitations executing your queries? Read how you can horizontally scale your Polars query on a cluster.

License

Polars is licensed under the MIT License (SPDX: MIT).

polars (pola-rs/polars)

Searching Database…

40.1K ·GitHub
这是什么东西?Polars 是一个速度极快的数据分析查询引擎,用于处理 DataFrame,用 Rust 编写,追求速度快、易用、表达力强。
这是我要导入的库,还是我运行的软件?它是导入的库,不是运行的服务:用 pip install polars 安装后在 Python 里调用,或者用 Rust 原生 crate。它还提供 Node.js、R 和 SQL 的接口。
安装之前有什么要注意的坑吗?默认构建面向较新的 CPU——如果你的 CPU 不支持 AVX2,需要用 LTSCPU=1 来编译。超过约 42 亿行的表格、2011 年以前的 CPU,以及 Apple Silicon 上基于 Rosetta 的 Python,也都需要专门的构建版本。
能用我的显卡吗?可以,这是可选功能——Polars 能在 NVIDIA 显卡上加速查询。
这里的懒执行和急执行是什么意思?你可以像普通的 DataFrame 库那样立即执行查询,也可以用懒模式先构建查询——等你真正取结果时,Polars 会自动优化整个查询,并在所有 CPU 核心上并行运行。
我能用自己写的代码扩展 Polars 吗?可以。它可以通过 I/O 插件和 Expression 插件进行原生扩展,让自定义逻辑直接在引擎内部运行,而不是在引擎外面绕一圈。
What are similar projects?modin, arrow, pandas, spark, xgboost, taskflow, xsv, rayon
Creator
pola-rs
Size
228.1 MB
Stars
40.1K
Age
6y
Commits · 90 Days