Public API
This page documents the stable import surface for Moltres users. It is the user-facing companion to the maintainer policy in RELEASE_PROCESS.md.
Contract tests in tests/api/test_public_imports.py enforce the exports listed here.
Top-level imports (moltres)
from moltres import (
connect,
async_connect,
col,
lit,
column,
MoltresConfig,
Database,
AsyncDatabase,
MoltresPydantableEngine,
SqlPlan,
SqlRootData,
register_performance_hook,
unregister_performance_hook,
__version__,
)
col vs column
Symbol |
Purpose |
|---|---|
|
Column expression for queries ( |
|
DDL helper for |
Optional interface wrappers
PandasDataFrame, PolarsDataFrame, AsyncPandasDataFrame, AsyncPolarsDataFrame,
and AsyncDatabase are loaded lazily. Accessing them without the required extra
raises ImportError with an install hint (they are never None).
# pip install moltres[pandas]
from moltres import PandasDataFrame
DataFrame (moltres.dataframe)
from moltres.dataframe import (
DataFrame,
AsyncDataFrame,
DataLoader,
DataFrameWriter,
ReadAccessor,
AsyncDataLoader,
AsyncReadAccessor,
AsyncDataFrameWriter,
# Interface wrappers (require extras)
PandasDataFrame,
PolarsDataFrame,
AsyncPandasDataFrame,
AsyncPolarsDataFrame,
# GroupBy
GroupedDataFrame,
AsyncGroupedDataFrame,
)
Use the PySpark-style API on DataFrame returned from db.table(...).select() or
db.load.* file readers.
Union semantics (PySpark difference)
Moltres |
PySpark equivalent |
|---|---|
|
|
|
|
When migrating PySpark df1.union(df2), use df1.unionAll(df2) in Moltres.
df.show() prints rows only by default. Pass count_total=True to include a full-table
row count (this runs an extra COUNT(*) query).
Expressions (moltres.expressions)
from moltres.expressions import col, lit, Column, sum, avg, when
from moltres.expressions import functions as F
Engine (moltres.engine)
Lower-level connection and execution helpers:
from moltres.engine import (
ConnectionManager,
QueryExecutor,
QueryResult,
DialectSpec,
get_dialect,
register_performance_hook,
unregister_performance_hook,
)
Records and CRUD (moltres.io.records)
from moltres.io.records import Records, AsyncRecords, LazyRecords, AsyncLazyRecords
Prefer factories and public keyword arguments:
Records.from_list([{"id": 1}], database=db).insert_into("users")
# or
Records(data=[{"id": 1}], database=db).insert_into("users")
Records(_data=...) and Records(_database=...) are deprecated (removed in 2.0).
Database CRUD (sync and async)
Sync:
db.insert("users", rows)
db.update("users", where=col("id") == 1, set={"name": "Alice"})
db.delete("users", where=col("id") == 1)
db.merge("users", rows, on=["id"], when_matched={"name": "Bob"})
Async (AsyncDatabase — same method signatures):
async def insert_users(db, rows):
return await db.insert("users", rows)
Reading data: choose the right API
Goal |
API |
Returns |
|---|---|---|
Query a SQL table |
|
|
Load a file for querying |
|
|
Load a file as row dicts |
|
|
Polars-style file scan |
|
|
Canonical paths
Lazy DataFrame from files:
db.load.csv()— preferredEager rows from files:
db.read.records.csv()db.read.csv()etc.: deprecated for DataFrame reads; usedb.load.*instead
Optional extras
Extra |
Install |
Enables |
|---|---|---|
|
|
|
|
|
|
|
|
Parquet file I/O via pyarrow |
|
|
FastAPI integration helpers |
|
|
DuckDB SQLAlchemy dialect |
|
|
|
|
|
SQLModel / Pydantic model integration |
|
|
Streamlit components |
|
|
Django middleware and template tags |
|
|
Airflow operators |
|
|
Prefect tasks |
|
|
dbt adapter helpers |
|
|
Async PostgreSQL ( |
|
|
Async MySQL ( |
|
|
pydantable engine integration |
Integrations (moltres.integrations)
Optional framework helpers (install the matching extra first):
from moltres.integrations import (
fastapi_integration,
pytest_integration,
dbt_integration,
django_integration,
sqlalchemy_integration,
)
See integration guides under Integrations in the docs sidebar.
API decision guide
Type |
Role |
CRUD? |
|---|---|---|
|
Connection + |
Yes |
|
|
No (query only) |
|
Lazy SQL transforms |
Via |
|
Eager row dicts from files or Python |
|
PySpark compatibility
Moltres targets a PySpark-like DataFrame API. Coverage varies by operation and dialect. See:
What is not public API
Modules under moltres.sql, moltres.logical, moltres.dataframe.managers, and
empty __init__.py packages are internal implementation details.