Skip to content
Configuration options

Configuration options

Every option the plugin accepts, set under options: in the plugin’s codegen block. See Configuration for where this block lives in sqlc.yaml.

Options

package, sql_driver, and emit_init_file are required; everything else is optional.

OptionTypeDefaultDescription
packagestringrequiredName of the generated package.
sql_driverstringrequiredOne of asyncpg, psycopg_async, aiosqlite, sqlite3. Must match the engine (the postgres drivers -> postgresql; the sqlite drivers -> sqlite).
emit_init_fileboolrequiredWhether to emit an __init__.py in the package. Must be set explicitly. Set false only if the package already has one.
model_typestringdataclassOne of dataclass, attrs, msgspec, pydantic. See Model types.
initialismslist[string]["id"]Identifier segments to upper-case, e.g. app_id -> AppID.
emit_exact_table_namesboolfalseIf true, model names mirror table names; otherwise plural table names are singularized.
emit_classesboolfalseIf true, each query file’s functions become methods on a class named after that file (queries_field_namings.sql -> QueriesFieldNamings). See Writing queries.
inflection_exclude_table_nameslist[string][]Table names to leave un-singularized (only used when emit_exact_table_names is false).
omit_unused_modelsboolfalseIf true, tables not referenced by any query are not turned into models.
omit_typechecking_blockboolfalseIf true, non-builtin types are imported at module level instead of inside a typing.TYPE_CHECKING block.
docstringsstringnoneOne of none, google, numpy, pep257. See Docstrings.
docstrings_emit_sqlbooltrueInclude each query’s SQL in its docstring. Ignored when docstrings is none.
query_parameter_limitintunsetWhen set to a non-negative value, queries with more parameters than the limit bundle them into a single params argument. Unset or negative never bundles (except :copyfrom, which always uses a params class).
omit_kwargs_limitint0Queries with this many parameters or fewer do not require keyword arguments. 0 makes every parameter keyword-only. Must not be negative.
speedupsboolfalseUse faster third-party libraries for type conversion. Currently affects sqlite3/aiosqlite only (uses ciso8601). See SQLite type conversion.
overrideslist[Override][]Replace the Python type of matching columns. See Type overrides.
converterslist[Converter][]Named encode/decode function pairs referenced by an override. See Converters.
indent_charstring" " (space)Character used for one indent step.
chars_per_indent_levelint4Number of indent_chars per indent level.
debugboolfalseEmit a log.txt debug log during sqlc generate.

Object schemas

Some options take structured objects rather than scalars.

py_type

Describes a Python type and how to import it. Used by an override and by a converter.

FieldTypeDescription
typestringrequired - the type expression used in annotations, e.g. UserString or collections.UserString.
importstringModule to import, e.g. collections.
packagestringName to import from import (from <import> import <package>). If empty, emits import <import>.

override

An entry in overrides. Matches columns either by SQL type or by column name; specifying both, or neither, is an error.

FieldTypeDescription
db_typestringMatch a SQL type exactly (case-insensitive), e.g. text, pg_catalog.int4. Mutually exclusive with column.
columnstringMatch [catalog.][schema.]table.column; wildcards are supported. Mutually exclusive with db_type.
py_typepy_typeReplacement type. Required unless converter is set.
converterstringName of a converters entry, which supplies the type and its encode/decode functions instead of py_type.

When both a column and a db_type override could match, the column match wins.

converter

An entry in converters. See Converters.

FieldTypeDescription
namestringrequired - unique name, referenced by an override’s converter.
py_typepy_typerequired - the Python type the converter produces and accepts.
to_dbstringrequired - dotted path to a function that turns the Python value into the column’s wire type.
from_dbstringrequired - dotted path to a function that turns the wire value into the Python type.