Python API Reference¶
Preql¶
-
class
preql.
Preql
(db_uri: str = 'sqlite://:memory:', print_sql: bool = False, auto_create: bool = False, autocommit: bool = False)¶ Provides an API to run Preql code from Python
Example
>>> import preql >>> p = preql.Preql() >>> p('[1, 2]{item+1}') [2, 3]
-
__init__
(db_uri: str = 'sqlite://:memory:', print_sql: bool = False, auto_create: bool = False, autocommit: bool = False)¶ Initialize a new Preql instance
Parameters: - db_uri (str, optional) – URI of database. Defaults to using a non-persistent memory database.
- print_sql (bool, optional) – Whether or not to print every SQL query that is executed (default defined in settings)
-
load
(filename, rel_to=None)¶ Load a Preql script
Parameters: - filename (str) – Name of script to run
- rel_to (Optional[str]) – Path to which
filename
is relative.
-
start_repl
(*args)¶ Run the interactive prompt
-
import_pandas
(**dfs)¶ Import pandas.DataFrame instances into SQL tables
Example
>>> pql.import_pandas(a=df_a, b=df_b)
-
-
class
preql.api.
TablePromise
(interp, inst)¶ Returned by Preql whenever the result is a table
Fetching values creates queries to database engine
-
to_json
()¶ Returns table as a list of rows, i.e.
[{col1: value, col2: value, ...}, ...]
-
to_pandas
()¶ Returns table as a Pandas dataframe (requires pandas installed)
-
__eq__
(other)¶ Compare the table to a JSON representation of it as list of objects
Essentially:
return self.to_json() == other
-
__len__
()¶ Run a count query on table
-
__getitem__
(index)¶ Run a slice query on table
-