Parameters#
Type-safe parameter processing with automatic style detection and conversion.
Supports QMARK (?), NAMED (:name), NUMERIC ($1), and FORMAT (%s) styles.
ParameterProcessor#
- class sqlspec.core.parameters.ParameterProcessor[source]#
Bases:
objectParameter processing engine coordinating conversion phases.
- __init__(*, converter=None, validator=None, cache_max_size=None, validator_cache_max_size=None)[source]#
- process_for_execution(sql, parameters, config, dialect=None, is_many=False, wrap_types=True, parsed_expression=None, param_fingerprint=None)[source]#
Process parameters for execution without parse normalization.
- Parameters:
parameters¶ (sqlspec.core.parameters.ParameterPayload) -- Parameter payload.
config¶ (
ParameterStyleConfig) -- Parameter style configuration.wrap_types¶ (
bool) -- Whether to wrap parameters with type metadata.parsed_expression¶ (
Any) -- Pre-parsed SQLGlot expression to preserve through pipeline.param_fingerprint¶ (
Any|None) -- Pre-computed parameter fingerprint for cache key.
- Return type:
- Returns:
ParameterProcessingResult with execution SQL and parameters.
- transform_cached_parameters(parameters, cached_profile, config, *, input_named_parameters, is_many, apply_wrap_types)[source]#
Apply parameter transformations for a cache hit.
Uses cached metadata to efficiently transform parameters without re-parsing SQL. This ensures new parameter values undergo the same transformations as the original cached request (type wrapping, coercion, named-to-positional mapping).
- Parameters:
parameters¶ (sqlspec.core.parameters.ParameterPayload) -- New parameter payload to transform.
cached_profile¶ (
ParameterProfile) -- Cached ParameterProfile with execution parameter metadata.config¶ (
ParameterStyleConfig) -- Parameter style configuration.input_named_parameters¶ (
tuple[str,...]) -- Cached input named parameter order.apply_wrap_types¶ (
bool) -- Whether to wrap parameters with type metadata.
- Return type:
dict[str, typing.Any] |list[typing.Any] |tuple[typing.Any,...] |object|None- Returns:
Transformed parameters matching the cached SQL's placeholder format.
ParameterConverter#
ParameterValidator#
- class sqlspec.core.parameters.ParameterValidator[source]#
Bases:
objectExtracts placeholder metadata and dialect compatibility information.
- set_cache_max_size(cache_max_size)[source]#
Update the maximum cache size for parameter metadata.
- Return type:
Types and Profiles#
- class sqlspec.core.parameters.ParameterStyle[source]#
-
Enumeration of supported SQL parameter placeholder styles.
- __new__(value)#
- class sqlspec.core.parameters.ParameterStyleConfig[source]#
Bases:
objectConfiguration describing parameter behaviour for a statement.
- __init__(default_parameter_style, supported_parameter_styles=None, supported_execution_parameter_styles=None, default_execution_parameter_style=None, type_coercion_map=None, has_native_list_expansion=False, needs_static_script_compilation=False, allow_mixed_parameter_styles=False, preserve_parameter_format=True, preserve_original_params_for_many=False, output_transformer=None, ast_transformer=None, json_serializer=None, json_deserializer=None, strict_named_parameters=True)[source]#
- class sqlspec.core.parameters.TypedParameter[source]#
Bases:
objectWrapper that preserves original parameter type information.
- class sqlspec.core.parameters.ParameterInfo[source]#
Bases:
objectMetadata describing a single detected SQL parameter.
- class sqlspec.core.parameters.DriverParameterProfile[source]#
Bases:
objectImmutable adapter profile describing parameter defaults.
- __init__(name, default_style, supported_styles, default_execution_style, supported_execution_styles, has_native_list_expansion, preserve_parameter_format, needs_static_script_compilation, allow_mixed_parameter_styles, preserve_original_params_for_many, json_serializer_strategy, custom_type_coercions=None, default_output_transformer=None, default_ast_transformer=None, extras=None, default_dialect=None, statement_kwargs=None, strict_named_parameters=True)[source]#
- class sqlspec.core.parameters.ParameterProfile[source]#
Bases:
objectAggregate metadata describing detected parameters.
Profile Management#
- sqlspec.core.parameters.get_driver_profile(adapter_key)[source]#
Return the registered parameter profile for the specified adapter.
- Parameters:
adapter_key¶ (
str) -- Adapter identifier (case-insensitive).- Return type:
- Returns:
Registered
DriverParameterProfileinstance.- Raises:
ImproperConfigurationError -- If the adapter does not have a profile.
- sqlspec.core.parameters.register_driver_profile(adapter_key, profile, *, allow_override=False)[source]#
Register a driver profile under the canonical adapter key.
- Parameters:
- Raises:
ImproperConfigurationError -- If attempting to register a duplicate profile.
- Return type:
- sqlspec.core.parameters.build_statement_config_from_profile(profile, *, parameter_overrides=None, statement_overrides=None, json_serializer=None, json_deserializer=None)[source]#
Construct a
StatementConfigseeded from a driver profile.- Parameters:
profile¶ (
DriverParameterProfile) -- Driver profile providing default parameter behaviour.parameter_overrides¶ (
dict[str, typing.Any] |None) -- Optional overrides for parameter config fields.statement_overrides¶ (
dict[str, typing.Any] |None) -- Optional overrides for resulting statement config.json_serializer¶ (typing.Callable[[MyTypeAliasForwardRef('typing.Any')],
str] |None) -- Optional JSON serializer supplied by the adapter.json_deserializer¶ (typing.Callable[[<class 'str'>], typing.Any] |
None) -- Optional JSON deserializer supplied by the adapter.
- Return type:
- Returns:
New
StatementConfiginstance with merged configuration.
Parameter Helpers#
- sqlspec.core.parameters.validate_parameter_alignment(parameter_profile, parameters, *, is_many=False)[source]#
Ensure provided parameters align with detected placeholders.
- Parameters:
- Raises:
SQLSpecError -- If counts or identifiers differ between placeholders and payload.
- Return type:
- sqlspec.core.parameters.normalize_parameter_key(key)[source]#
Normalize a parameter key into an
(kind, value)tuple.
- sqlspec.core.parameters.is_iterable_parameters(obj)[source]#
Return True when the object behaves like an iterable parameter payload.
- Return type:
- sqlspec.core.parameters.wrap_with_type(value, semantic_name=None)[source]#
Wrap value with
TypedParameterif it benefits downstream processing.- Return type:
- sqlspec.core.parameters.register_param_type(name, py_type)[source]#
Register or override a declared-type-string matcher.
- sqlspec.core.parameters.resolve_param_type(type_str)[source]#
Resolve a declared type string to a matcher, or
Noneif unknown.Unknown type strings are documentation-only and skipped during validation. The declared string is looked up, never evaluated. Parameterized containers (
list[int]) resolve to their origin type (list).