IPython & Jupyter Magic API

IPython/Jupyter magic for pyprql.


A single function is defined herein. It should not be used directly by the user. Rather, any users should load the magic using the IPython line magic, like below:

In [1]: %load_ext pyprql.magic

pyprql.magic.load_ipython_extension(ipython: InteractiveShell) None

Load the pyprql.magic extension.

This function is called automatically by IPython when the magic is loaded using %load_ext.


ipython (InteractiveShell) – The current IPython instance.

A magic class for parsing PRQL in IPython or Jupyter.

class pyprql.magic.prql.PrqlMagic(**kwargs: Any)

Perform PRQL magics.

This is a thin wrapper around sql.SqlMagic, the class that provides the %%sql magic. For full documentation on usage and features, please see their docs.

We override their defaults in two cases:

1. autopandas is set to True. 1. displaycon is set to False.

Additionally, to work around some quirky behaviour, we also provide an autoview option to indicate whether results should be printed to the window.


shell (InteractiveShell) – The current IPython shell instance. Since instantiation is handled by IPython, the user should never need to create this clas manually.


Return Pandas DataFrames instead of regular result sets


Return Polars DataFrames instead of regular result sets


Display results


Show connection string after execute


Only print the compiled SQL


Print number of rows affected by DML

prql(line: str = '', cell: str = '', local_ns: dict | None = None) None
%prql [-l] [-x CLOSE] [-c CREATOR] [-s SECTION] [-p] [-n] [--append]
          [line ...]

Create the PRQL magic.

Return type:


positional arguments:

line prql

-l, --connections

list active connections

-x CLOSE, --close CLOSE

close a session by name

-c CREATOR, --creator CREATOR

specify creator function for new connection

-s SECTION, --section SECTION

section of dsn_file to be used for generating a connection string

-p, --persist

create a table name in the database from the named DataFrame

-n, --no-index

Do not store Data Frame index when persisting


create, or append to, a table name in the database from the named DataFrame


specify dictionary of connection arguments to pass to SQL driver

-f FILE, --file FILE

Run PRQL from file at this path


Compile target of prql-compiler