Skip to content

Commit b6e7ef8

Browse files
henryharbeckHenry Harbeck
and
Henry Harbeck
authored
docs(python): Add IO plugins to Python API reference (#21028)
Co-authored-by: Henry Harbeck <[email protected]>
1 parent 3c497e3 commit b6e7ef8

File tree

5 files changed

+60
-16
lines changed

5 files changed

+60
-16
lines changed

Diff for: docs/source/user-guide/plugins/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Plugins
22

3-
Polars allows you to extend it's functionality with either Expression plugins or IO plugins.
3+
Polars allows you to extend its functionality with either Expression plugins or IO plugins.
44

55
- [Expression plugins](./expr_plugins.md)
66
- [IO plugins](./io_plugins.md)

Diff for: docs/source/user-guide/plugins/io_plugins.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# IO Plugins
22

3-
Besides [expression plugins](./index.md), we also support IO plugins. These allow you to register
4-
different file formats as sources to the Polars engines. Because sources can move data zero copy via
5-
Arrow FFI and sources can produce large chunks of data before returning, we've decided to interface
6-
to IO plugins via Python for now, as we don't think the short time the GIL is needed should lead to
7-
any contention.
3+
Besides [expression plugins](./expr_plugins.md), we also support IO plugins. These allow you to
4+
register different file formats as sources to the Polars engines. Because sources can move data zero
5+
copy via Arrow FFI and sources can produce large chunks of data before returning, we've decided to
6+
interface to IO plugins via Python for now, as we don't think the short time the GIL is needed
7+
should lead to any contention.
88

99
E.g. an IO source can read their dataframe's in rust and only at the rendez-vous move the data
1010
zero-copy having only a short time the GIL is needed.

Diff for: py-polars/docs/source/reference/plugins.rst

+40-8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,45 @@ Plugins
33
=======
44
.. currentmodule:: polars
55

6-
Plugins allow for extending Polars' functionality. See the
7-
`user guide <https://docs.pola.rs/user-guide/plugins/>`_ for more information
8-
and resources.
6+
Polars allows you to extend its functionality with either Expression plugins or IO plugins.
7+
See the `user guide <https://docs.pola.rs/user-guide/plugins/>`_ for more information and resources.
98

10-
Available plugin utility functions are:
9+
Expression plugins
10+
------------------
1111

12-
.. automodule:: polars.plugins
13-
:members:
14-
:autosummary:
15-
:autosummary-no-titles:
12+
Expression plugins are the preferred way to create user defined functions. They allow you to compile
13+
a Rust function and register that as an expression into the Polars library. The Polars engine will
14+
dynamically link your function at runtime and your expression will run almost as fast as native
15+
expressions. Note that this works without any interference of Python and thus no GIL contention.
16+
17+
See the `expression plugins section of the user guide <https://docs.pola.rs/user-guide/plugins/expr_plugins/>`_
18+
for more information.
19+
20+
.. autosummary::
21+
:toctree: api/
22+
23+
plugins.register_plugin_function
24+
25+
26+
IO plugins
27+
------------------
28+
29+
IO plugins allow you to register different file formats as sources to the Polars engines.
30+
31+
See the `IO plugins section of the user guide <https://docs.pola.rs/user-guide/plugins/io_plugins/>`_
32+
for more information.
33+
34+
.. note::
35+
36+
The ``io.plugins`` module is not imported by default in order to optimise import speed of
37+
the primary ``polars`` module. Either import ``polars.io.plugins`` and *then* use that
38+
namespace, or import ``register_io_source`` from the full module path, e.g.:
39+
40+
.. code-block:: python
41+
42+
from polars.io.plugins import register_io_source
43+
44+
.. autosummary::
45+
:toctree: api/
46+
47+
io.plugins.register_io_source

Diff for: py-polars/polars/io/plugins.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ def register_io_source(
2626
"""
2727
Register your IO plugin and initialize a LazyFrame.
2828
29+
See the `user guide <https://docs.pola.rs/user-guide/plugins/io_plugins>`_
30+
for more information about plugins.
31+
32+
.. warning::
33+
This functionality is considered **unstable**. It may be changed
34+
at any point without it being considered a breaking change.
35+
36+
2937
Parameters
3038
----------
3139
callable
@@ -36,17 +44,21 @@ def register_io_source(
3644
predicate
3745
Polars expression. The reader must filter
3846
their rows accordingly.
39-
n_rows:
47+
n_rows
4048
Materialize only n rows from the source.
4149
The reader can stop when `n_rows` are read.
4250
batch_size
4351
A hint of the ideal batch size the reader's
4452
generator must produce.
53+
4554
The function should return a DataFrame batch
4655
(an iterator over individual DataFrames).
4756
schema
4857
Schema that the reader will produce before projection pushdown.
4958
59+
Returns
60+
-------
61+
LazyFrame
5062
"""
5163

5264
def wrap(

Diff for: py-polars/polars/plugins.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def register_plugin_function(
3636
"""
3737
Register a plugin function.
3838
39-
See the `user guide <https://docs.pola.rs/user-guide/plugins/>`_
39+
See the `user guide <https://docs.pola.rs/user-guide/plugins/expr_plugins>`_
4040
for more information about plugins.
4141
4242
Parameters

0 commit comments

Comments
 (0)