IPython & Jupyter Magic API
IPython/Jupyter magic for pyprql.
Examples
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
.- Parameters:
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 toFalse
.Additionally, to work around some quirky behaviour, we also provide an
autoview
option to indicate whether results should be printed to the window.- Parameters:
shell (InteractiveShell) – The current IPython shell instance. Since instantiation is handled by IPython, the user should never need to create this clas manually.
- autopandas
Return Pandas DataFrames instead of regular result sets
- autopolars
Return Polars DataFrames instead of regular result sets
- autoview
Display results
- displaycon
Show connection string after execute
- dryrun
Only print the compiled SQL
- feedback
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] [-a CONNECTION_ARGUMENTS] [-f FILE] [line ...]
Create the PRQL magic.
- Return type:
None
- positional arguments:
line prql
- options:
- -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
- --append
create, or append to, a table name in the database from the named DataFrame
- -a CONNECTION_ARGUMENTS, --connection_arguments CONNECTION_ARGUMENTS
specify dictionary of connection arguments to pass to SQL driver
- -f FILE, --file FILE
Run PRQL from file at this path
- target
Compile target of prql-compiler