bearsql package

Submodules

bearsql.bearsql module

Main module.

class bearsql.bearsql.SqlContext(table: Optional[str] = None, view: Optional[str] = None, database: Optional[str] = None)[source]

Bases: object

close()[source]

Method to close database connection

register_table(df: pandas.core.frame.DataFrame, table: Optional[str] = None)None[source]

This method creates a table in the database with pandas dataframe as the input. To create a table, a view must be created. If there is no view name specified in this class, a new random view name will be generated

Parameters
  • df (DataFrame) – pandas input dataframe

  • table (Optional[str]; default None) – table name; the dataframe will sit in the database and can be referenced using this table name

register_view(df: pandas.core.frame.DataFrame, view: Optional[str] = None)None[source]

This method creates a view in the database with pandas dataframe as the input. If there is no view name is passed and not specified in this class, an exception will be thrown

Parameters
  • df (DataFrame) – pandas input dataframe

  • view (Optional[str]; default None) – table name; the dataframe will sit in the database and can be referenced using this table name

relation(df: pandas.core.frame.DataFrame, table: Optional[str] = None)[source]

Create a relational table on top of pandas dataframe. If tagged with a table name, this name can be used to run sql queries.

Parameters
  • df (DataFrame) – pandas input dataframe

  • table (Optional[str]; default None) – name of the table

returns: duckdb relation :rtype: duckdb

sql(query: Union[str, list], output: str = 'df')Generator[source]

Method to run sql queries on pandas dataframe.

Parameters
  • query (Union[str, list]) – sql query to execute on pandas dataframe. It can be one single query or a list of multiple queries

  • output (str; default df) – Output format of the query results. This can either be df, arrow or any

returns: Generator object containing all the query results :rtype: Generator

property table

Table property of the class. This will give the name of the table that is currently in use

property view

View property of the class. This will give the name of the view that is currently in use

bearsql.cli module

Console script for bearsql.

bearsql.cli.main()[source]

Console script for bearsql.

bearsql.log_source module

class bearsql.log_source.Logging(log_level)[source]

Bases: object

get_logger()[source]

Module contents

Top-level package for bearsql.