Skip to main content
The Session class is the main entry point for all Fenic DataFrame operations. It manages configuration, execution backends, and resource lifecycle. Similar to PySpark’s SparkSession.

Creating a Session

get_or_create

Session.get_or_create(config: SessionConfig) -> Session
Gets an existing Session or creates a new one with the configured settings.
config
SessionConfig
required
Configuration object specifying session settings including:
  • app_name: Name of the application
  • cloud: Whether to use cloud execution backend
  • api_key: API key for cloud execution (required when cloud=True)
Session
Session
A Session instance configured with the provided settings
session = Session.get_or_create(
    SessionConfig(app_name="my_app")
)
Direct construction using Session() is not allowed. Always use Session.get_or_create().

Properties

read

session.read -> DataFrameReader
Returns a DataFrameReader that can be used to read data as a DataFrame.
DataFrameReader
DataFrameReader
A reader interface to read data into DataFrame from various sources (CSV, Parquet, JSON, etc.)
# Read a CSV file
df = session.read.csv("data.csv")

# Read a Parquet file
df = session.read.parquet("data.parquet")

catalog

session.catalog -> Catalog
Interface for catalog operations on the Session, including listing tables, views, and managing temporary tables.
Catalog
Catalog
Catalog interface for managing tables and views
# List all tables
tables = session.catalog.list_tables()

# Check if table exists
exists = session.catalog.table_exists("my_table")

Core Methods

create_dataframe

session.create_dataframe(data: DataLike) -> DataFrame
Create a DataFrame from a variety of Python-native data formats.
data
DataLike
required
Input data. Must be one of:
  • Polars DataFrame
  • Pandas DataFrame
  • dict of column_name → list of values
  • list of dicts (each dict representing a row)
  • pyarrow Table
DataFrame
DataFrame
A new DataFrame instance
df = session.create_dataframe({
    "col1": [1, 2, 3],
    "col2": ["a", "b", "c"]
})

table

session.table(table_name: str) -> DataFrame
Returns the specified table as a DataFrame.
table_name
str
required
Name of the table to load
DataFrame
DataFrame
Table as a DataFrame
# Load an existing table
df = session.table("my_table")
Raises ValueError if the table does not exist.

view

session.view(view_name: str) -> DataFrame
Returns the specified view as a DataFrame.
view_name
str
required
Name of the view to load
DataFrame
DataFrame
View as a DataFrame
# Load an existing view
df = session.view("my_view")
Raises CatalogError if the view does not exist.

sql

session.sql(query: str, /, **tables: DataFrame) -> DataFrame
Execute a read-only SQL query against one or more DataFrames using named placeholders.
query
str
required
A SQL query string with placeholders like {df}
tables
**DataFrame
required
Keyword arguments mapping placeholder names to DataFrames
DataFrame
DataFrame
A lazy DataFrame representing the result of the SQL query
df1 = session.create_dataframe({"id": [1, 2]})
df2 = session.create_dataframe({"id": [2, 3]})

result = session.sql(
    "SELECT * FROM {df1} JOIN {df2} USING (id)",
    df1=df1,
    df2=df2
)
For supported SQL syntax and functions, refer to the DuckDB SQL documentation.
Raises ValidationError if a placeholder is used in the query but not passed as a keyword argument.

stop

session.stop(skip_usage_summary: bool = False) -> None
Stops the session and closes all connections.
skip_usage_summary
bool
default:"False"
Whether to skip printing the usage summary
# Stop session with usage summary
session.stop()

# Stop without printing summary
session.stop(skip_usage_summary=True)
Unless skip_usage_summary is set, a summary of your session’s metrics will print when you stop your session.

Aliases

  • createDataFramecreate_dataframe
  • getOrCreateget_or_create

Build docs developers (and LLMs) love