Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9b75371
try a mock API
NickCrews Mar 27, 2026
e1f7e11
overhaul and improve the API
NickCrews Mar 28, 2026
b1a00a8
tweak API example more
NickCrews Mar 28, 2026
fd43d5a
try separate steps of creation, resolving, and compilation
NickCrews Mar 28, 2026
bfd7207
fix parse_strings_and_params bug
NickCrews Mar 28, 2026
090f084
use dataclass, not dict
NickCrews Mar 28, 2026
785d5e3
remove conversion from ParamInterpretation
NickCrews Mar 28, 2026
c8bee8d
fixup
NickCrews Mar 28, 2026
abce78c
adjust implementation
NickCrews Mar 28, 2026
d5e6f96
ovehaul api more
NickCrews Mar 28, 2026
a8c7e17
fixup
NickCrews Mar 28, 2026
df86ad9
add comment explaining param incrementing, remove IntoTemplate
NickCrews Mar 28, 2026
19bd765
adjust implementation and tests
NickCrews Mar 29, 2026
ad668fc
move template.py into actual package
NickCrews Mar 29, 2026
5194d89
Improve CompiledSql ergonomics and docstrings
NickCrews Mar 29, 2026
1fbc172
fixup how parts are expanded
NickCrews Mar 29, 2026
ec71f69
fixup: template(*mylist), not template(mylist)
NickCrews Mar 29, 2026
5ed4d00
fix a few tests
NickCrews Mar 29, 2026
410f0fe
fixup
NickCrews Mar 29, 2026
747c864
fixup typecheck error
NickCrews Mar 29, 2026
1c06b0f
improve test style
NickCrews Mar 29, 2026
ff6dc19
move protocol tests to be together
NickCrews Mar 29, 2026
8e75ec6
improve test style
NickCrews Mar 29, 2026
9782568
fixup test
NickCrews Mar 29, 2026
c1ca3f9
improve style of tests and get passing
NickCrews Mar 29, 2026
c62c1c4
reduce verbosity of param construction in tests
NickCrews Mar 29, 2026
421c4d0
rename test to make room for test file that does actually execute code
NickCrews Mar 29, 2026
53a3ba4
add e2e tests
NickCrews Mar 29, 2026
f1141c6
implement at the cpp level
NickCrews Mar 29, 2026
bd29724
chore: get mypy to pass
NickCrews Jul 13, 2026
e1d766c
fix: add missing catalog.hpp include broken by submodule bump
NickCrews Jul 13, 2026
bc1cf94
feat: expose template API at top level
NickCrews Jul 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions _duckdb-stubs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if typing.TYPE_CHECKING:
ArrowUDF,
)
from ._enums import ExplainTypeLiteral, RenderModeLiteral
from duckdb import sqltypes, func
from duckdb import sqltypes, func, _template

__all__: lst[str] = [
"BinderException",
Expand Down Expand Up @@ -243,8 +243,12 @@ class DuckDBPyConnection:
def dtype(self, type_str: StrIntoPyType) -> sqltypes.DuckDBPyType: ...
def duplicate(self) -> DuckDBPyConnection: ...
def enum_type(self, name: str, type: sqltypes.DuckDBPyType, values: lst[typing.Any]) -> sqltypes.DuckDBPyType: ...
def execute(self, query: Statement | str, parameters: object = None) -> DuckDBPyConnection: ...
def executemany(self, query: Statement | str, parameters: object = None) -> DuckDBPyConnection: ...
def execute(
self, query: Statement | str | _template.SqlTemplate | _template.CompiledSql, parameters: object = None
) -> DuckDBPyConnection: ...
def executemany(
self, query: Statement | str | _template.SqlTemplate | _template.CompiledSql, parameters: object = None
) -> DuckDBPyConnection: ...
def extract_statements(self, query: str) -> lst[Statement]: ...
def fetch_arrow_table(self, rows_per_batch: typing.SupportsInt = 1000000) -> pyarrow.lib.Table:
"""Deprecated: use to_arrow_table() instead."""
Expand Down Expand Up @@ -326,7 +330,9 @@ class DuckDBPyConnection:
union_by_name: bool = False,
compression: ParquetCompression | None = None,
) -> DuckDBPyRelation: ...
def from_query(self, query: str, *, alias: str = "", params: object = None) -> DuckDBPyRelation: ...
def from_query(
self, query: str | _template.SqlTemplate | _template.CompiledSql, *, alias: str = "", params: object = None
) -> DuckDBPyRelation: ...
def get_table_names(self, query: str, *, qualified: bool = False) -> set[str]: ...
def install_extension(
self,
Expand Down Expand Up @@ -355,7 +361,9 @@ class DuckDBPyConnection:
def pl(
self, rows_per_batch: typing.SupportsInt = 1000000, *, lazy: bool = False
) -> polars.DataFrame | polars.LazyFrame: ...
def query(self, query: str, *, alias: str = "", params: object = None) -> DuckDBPyRelation: ...
def query(
self, query: str | _template.SqlTemplate | _template.CompiledSql, *, alias: str = "", params: object = None
) -> DuckDBPyRelation: ...
def query_progress(self) -> float: ...
def read_csv(
self,
Expand Down Expand Up @@ -448,7 +456,13 @@ class DuckDBPyConnection:
def remove_function(self, name: str) -> DuckDBPyConnection: ...
def rollback(self) -> DuckDBPyConnection: ...
def row_type(self, fields: IntoFields) -> sqltypes.DuckDBPyType: ...
def sql(self, query: Statement | str, *, alias: str = "", params: object = None) -> DuckDBPyRelation: ...
def sql(
self,
query: Statement | str | _template.SqlTemplate | _template.CompiledSql,
*,
alias: str = "",
params: object = None,
) -> DuckDBPyRelation: ...
def sqltype(self, type_str: str) -> sqltypes.DuckDBPyType: ...
def string_type(self, collation: str = "") -> sqltypes.DuckDBPyType: ...
def struct_type(self, fields: IntoFields) -> sqltypes.DuckDBPyType: ...
Expand Down Expand Up @@ -952,7 +966,7 @@ def enum_type(
connection: DuckDBPyConnection | None = None,
) -> sqltypes.DuckDBPyType: ...
def execute(
query: Statement | str,
query: Statement | str | _template.SqlTemplate | _template.CompiledSql,
parameters: object = None,
*,
connection: DuckDBPyConnection | None = None,
Expand Down Expand Up @@ -1067,7 +1081,7 @@ def from_parquet(
connection: DuckDBPyConnection | None = None,
) -> DuckDBPyRelation: ...
def from_query(
query: Statement | str,
query: Statement | str | _template.SqlTemplate | _template.CompiledSql,
*,
alias: str = "",
params: object = None,
Expand Down Expand Up @@ -1132,7 +1146,7 @@ def project(
df: pandas.DataFrame, *args: IntoExpr, groups: str = "", connection: DuckDBPyConnection | None = None
) -> DuckDBPyRelation: ...
def query(
query: Statement | str,
query: Statement | str | _template.SqlTemplate | _template.CompiledSql,
*,
alias: str = "",
params: object = None,
Expand Down Expand Up @@ -1245,7 +1259,7 @@ def row_type(fields: IntoFields, *, connection: DuckDBPyConnection | None = None
def rowcount(*, connection: DuckDBPyConnection | None = None) -> int: ...
def set_default_connection(connection: DuckDBPyConnection) -> None: ...
def sql(
query: Statement | str,
query: Statement | str | _template.SqlTemplate | _template.CompiledSql,
*,
alias: str = "",
params: object = None,
Expand Down
20 changes: 20 additions & 0 deletions duckdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@
STRING,
DBAPITypeObject,
)
from duckdb._template import (
CompiledSql,
IntoInterpolation,
Param,
ResolvedSqlTemplate,
SqlTemplate,
SupportsDuckdbTemplate,
compile,
param,
template,
)
from duckdb._version import (
__duckdb_version__,
__version__,
Expand Down Expand Up @@ -217,6 +228,7 @@
"CatalogException",
"CoalesceOperator",
"ColumnExpression",
"CompiledSql",
"ConnectionException",
"ConstantExpression",
"ConstraintException",
Expand Down Expand Up @@ -246,6 +258,7 @@
"InternalException",
"InterruptException",
"IntervalValue",
"IntoInterpolation",
"InvalidInputException",
"InvalidTypeException",
"LambdaExpression",
Expand All @@ -258,20 +271,24 @@
"OperationalError",
"OutOfMemoryException",
"OutOfRangeException",
"Param",
"ParserException",
"PermissionException",
"ProgrammingError",
"PythonExceptionHandling",
"RenderMode",
"ResolvedSqlTemplate",
"SQLExpression",
"SequenceException",
"SerializationException",
"ShortValue",
"SqlTemplate",
"StarExpression",
"Statement",
"StatementType",
"StringValue",
"StructValue",
"SupportsDuckdbTemplate",
"SyntaxException",
"TimeTimeZoneValue",
"TimeValue",
Expand Down Expand Up @@ -308,6 +325,7 @@
"checkpoint",
"close",
"commit",
"compile",
"connect",
"create_function",
"cursor",
Expand Down Expand Up @@ -350,6 +368,7 @@
"load_extension",
"map_type",
"order",
"param",
"paramstyle",
"paramstyle",
"pl",
Expand All @@ -373,6 +392,7 @@
"struct_type",
"table",
"table_function",
"template",
"tf",
"threadsafety",
"threadsafety",
Expand Down
Loading
Loading