Skip to content

Reference

The public Python API. The SGL language itself is documented in the Get started guide.

Entry point

sglduck.db_get_plot

The db_get_plot entry point (ported from rsgl's dbGetPlot.R).

db_get_plot takes a DuckDB connection and a SGL statement and returns the corresponding plot. Building the plot parses the statement, runs each layer's SQL, reconciles column casing, and validates the statement's semantics; the returned SglPlot renders lazily.

db_get_plot(con, sgl_stmt)

Return the SglPlot defined by a SGL statement.

Parameters:

Name Type Description Default
con

A DuckDB connection holding the tables the statement queries.

required
sgl_stmt str

A SGL statement (see the Get started guide for the language).

required

Returns:

Type Description
SglPlot

An SglPlot that renders the corresponding plot.

The plot object

sglduck.SglPlot

show()

Open the plot in the default browser.

save(filename, **kwargs)

Save the plot to filename (delegates to lets_plot.export.ggsave).

to_svg()

to_html()

Type classifications

sglduck.type_classifications(con, table_name)

Get SGL type classifications for columns in a table.

type_classifications takes a database connection and a table name and returns the SGL type classifications (numerical, categorical, or temporal) of the table's columns.

Classification is driven by each column's polars dtype, which DuckDB supplies from the table schema regardless of row count.

Parameters:

Name Type Description Default
con

A DuckDB connection.

required
table_name str

The name of a table.

required

Returns:

Type Description

A dataframe listing the SGL type classification of each column.

Datasets

sglduck.data.cars()

The cars dataset: 406 cars by horsepower, miles per gallon, and origin.

Columns: car_id, horsepower, miles_per_gallon, origin, year. Derived from the vega-datasets cars.json — the kept fields Horsepower, Miles_per_Gallon, and Origin (renamed), year from the original Year date, and car_id a row id.

sglduck.data.trees()

The trees dataset: the growth of five orange trees over time.

Columns: tree_id, age (days since 1968-12-31), circumference (mm). Derived from R's datasets::Orange, with its Tree column renamed to tree_id.

Errors

sglduck.SglError

Bases: Exception

Raised when a SGL statement fails semantic validation.

Parser errors (invalid tokens, syntax errors) surface as exceptions from the compiled _sgl bridge instead.