How to Use Polars in Excel With xlwings Lite
Polars runs inside Excel through the free xlwings Lite add-in, with no Python installed on the machine. Add polars to the add-in’s requirements, then write functions that take a range as a Polars DataFrame and return a table. Two examples follow: a revenue-by-region function and a script that builds a summary sheet with a chart.
What you need
You need Microsoft 365 or Excel 2021 or newer, on Windows, Mac or the web, and the free xlwings Lite add-in. Polars itself installs inside the add-in, so nothing is installed on your computer.
Polars is a fast DataFrame library for Python with a concise expression syntax for grouping, aggregating and sorting. If xlwings Lite is new to you, start with my xlwings Lite introduction.
Install xlwings Lite and Polars
xlwings Lite comes from the Excel add-in store, and Polars is one line in its requirements file. The add-in runs Python with Pyodide (Python compiled to WebAssembly) in a sandbox, so the package installs into the add-in, not onto your system.
-
Add xlwings Lite. In Excel go to Home > Add-ins, search for xlwings Lite and add it. The add-in pane usually opens right after the install.
-
Open requirements.txt in the add-in pane.
-
Add polars on its own line. The add-in installs it and reports the result in the console. Reload the add-in if it asks you to.

A Polars custom function
A function decorated with @func becomes a worksheet function. With the type hint pl.DataFrame, xlwings Lite hands the selected range to the function as a Polars DataFrame, with the first row as the column headers, and a returned DataFrame spills into the grid.
My function calculates revenue as units sold times unit price, groups by region, sums the revenue and sorts the result from highest to lowest. With columns named region, units_sold and unit_price it looks like this:
import polars as pl
from xlwings import func
@func
def revenue_by_region(df: pl.DataFrame):
return (
df.with_columns((pl.col("units_sold") * pl.col("unit_price")).alias("revenue"))
.group_by("region")
.agg(pl.col("revenue").sum())
.sort("revenue", descending=True)
)
In a cell, type =REVENUE_BY_REGION( and select the data including the header row. Change a value in the data and the result recalculates like any built-in function. I explain custom functions in more detail in creating custom Excel formulas with Python.

A summary sheet with a chart
For more than one result, a script is the better fit. A function decorated with @script runs from the add-in’s run button or a button on the sheet, and it can create sheets, write tables and insert images.
My script:
- reads the sales table from the Sales Data sheet into a Polars DataFrame,
- computes the revenue and totals it by product,
- creates a Summary sheet, or clears it if it exists,
- writes a title and the aggregated table,
- draws a bar chart with matplotlib and inserts it into the sheet as a picture.
The whole flow fits in a few dozen lines, because xlwings Lite converts ranges to Polars DataFrames and back for you.

Tips
Most problems come from a missing package or from dates. Both have a one-line fix.
- An import error for polars means the requirement is missing or not installed yet. Add it to requirements.txt and reload the add-in.
- Custom functions receive dates as Excel serial numbers (45658 and so on). Add @arg(“df”, pl.DataFrame, parse_dates=[“Date”]) under @func (import arg from xlwings as well) and the Date column arrives as real dates.
- Code you write in the add-in is saved in the workbook, so it travels with the file.
Limits
Python in the browser runs in a sandbox with the memory and CPU the browser allows. Very large datasets can hit those limits, and for heavy production workflows a local Python setup is still the better tool.
If you prefer pandas, the same pattern works with a pd.DataFrame type hint, and I show the pandas side of common Excel tasks in SUMIFS, COUNTIFS and AVERAGEIFS in pandas. My Excel Automation Course teaches Python with xlwings Lite from the first line, if you want a guided path.
