Plugins#

Polars allows you to extend its functionality with either Expression plugins or IO plugins. See the user guide for more information and resources.

Expression plugins#

Expression plugins are the preferred way to create user defined functions. They allow you to compile a Rust function and register that as an expression into the Polars library. The Polars engine will dynamically link your function at runtime and your expression will run almost as fast as native expressions. Note that this works without any interference of Python and thus no GIL contention.

See the expression plugins section of the user guide for more information.

plugins.register_plugin_function(*, ...[, ...])

Register a plugin function.

IO plugins#

IO plugins allow you to register different file formats as sources to the Polars engines.

See the IO plugins section of the user guide for more information.

File readers#

Warning

This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.

A FileReaderBuilder creates one FileReader per source, and scan_external_reader() turns a builder and a list of sources into a LazyFrame.

scan_external_reader(reader_builder, *, ...)

Scan an external reader.

FileReaderBuilder()

File reader builder.

FileReaderBuilder.build_file_reader(source, ...)

Build a file reader for the given source.

FileReaderBuilder.reader_capabilities()

Get the capabilities of the reader.

FileReaderBuilder.explain_properties()

Properties to display in IR explain.

FileReader()

File reader implementation.

FileReader.schema()

Get the schema of the columns contained in the file.

FileReader.n_rows_in_file([limit])

Return the number of rows in the file.

FileReader.fetch_metadata()

Fetch file metadata.

FileReader.initialize_serial()

Initializer called serially, in order for each reader when reading from a files list.

FileReader.collect_batches(*, columns, ...)

Create an iterator that yields DataFrame chunks of the file with the requested parameters.

FileReader.on_drop()

Called when this reader is dropped.

ReaderCapabilities([row_index, pre_slice, ...])

Reader capabilities.

LazyFrame resolvers#

Warning

This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.

A LazyFrameResolver defers resolving the paths to scan until a query runs. The resolver sees the columns, row limit and filters that the query requests, and returns the LazyFrame to scan.

LazyFrameResolver()

LazyFrame resolver.

LazyFrameResolver.lazy()

Create a LazyFrame with this resolver.

LazyFrameResolver.schema()

Fetch the schema of the table.

LazyFrameResolver.resolve_lazyframe(*, ...)

Resolve to a LazyFrame with the provided limit, filters and projection.

LazyFrameResolver.cse_eq(other)

Equality evaluation of self with other for common subplan elimination.

FilterExpr(*, expr, pyarrow_str, _pyarrow_expr)

Filter expression.

FilterExpr.pyarrow_expr

The filter expression converted to a pyarrow expression.

ResolvedLazyFrameProps(*[, version_key, ...])

Additional properties for a resolved LazyFrame.

Generator-based IO sources#

A generator-based IO source provides one generator of DataFrames for the whole source.

Note

The io.plugins module is not imported by default in order to optimise import speed of the primary polars module. Either import polars.io.plugins and then use that namespace, or import register_io_source from the full module path, e.g.:

from polars.io.plugins import register_io_source

io.plugins.register_io_source(io_source, *, ...)

Register your IO plugin and initialize a LazyFrame.

io.plugins.IOSourceScanFunction(*args, **kwargs)

The callable Polars invokes for a source registered with register_io_source.

io.plugins.IOSourceScanFunction.io_source

The source that was passed to register_io_source().