katana_public_api_client.domain.variant¶
katana_public_api_client.domain.variant
¶
Domain model for Variant entities.
This module provides a Pydantic model representing a Variant (product, material, or service SKU) optimized for ETL, data processing, and business logic.
The domain model uses composition with the auto-generated Pydantic model from OpenAPI,
leveraging its from_attrs() conversion while adding business-specific methods.
Classes¶
KatanaVariant
¶
Bases: KatanaBaseModel
Domain model for a Product or Material Variant.
A Variant represents a specific SKU with unique pricing, configuration, and inventory tracking. This is a Pydantic model optimized for: - ETL and data processing - Business logic - Data validation - JSON schema generation
This model uses composition with the auto-generated Pydantic model, exposing a curated subset of fields with business methods.
Example
Functions¶
from_attrs(attrs_variant, product_or_material_name=None)
classmethod
¶
Create a KatanaVariant from an attrs Variant model (API response).
This method leverages the generated Pydantic model's from_attrs() method
to handle UNSET sentinel conversion, then creates the domain model.
Parameters:
-
attrs_variant(Variant) –The attrs Variant model from API response.
-
product_or_material_name(str | None, default:None) –Optional name of parent product/material (must be provided separately as it comes from extend query).
Returns:
-
KatanaVariant–A new KatanaVariant instance with business methods.
Example
Source code in katana_public_api_client/domain/variant.py
from_generated(generated, product_or_material_name=None)
classmethod
¶
Create a KatanaVariant from a generated Pydantic Variant model.
This method extracts the curated subset of fields from the generated model and converts nested objects (config_attributes, custom_fields) to simple dicts.
Parameters:
-
generated(Variant) –The auto-generated Pydantic Variant model.
-
product_or_material_name(str | None, default:None) –Optional name of parent product/material (must be provided separately as it comes from extend query).
Returns:
-
KatanaVariant–A new KatanaVariant instance with business methods.
Example
Source code in katana_public_api_client/domain/variant.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
get_config_value(config_name)
¶
Get value of a configuration attribute by name.
Parameters:
-
config_name(str) –Name of the configuration attribute
Returns:
-
str | None–Config value or None if not found
Example
Source code in katana_public_api_client/domain/variant.py
get_custom_field(field_name)
¶
Get value of a custom field by name.
Parameters:
-
field_name(str) –Name of the custom field
Returns:
-
str | None–Field value or None if not found
Example
Source code in katana_public_api_client/domain/variant.py
get_display_name()
¶
Get formatted display name matching Katana UI format.
Delegates to :func:build_variant_display_name so the formula
stays consistent across the domain class, the typed-cache
postprocess hook, and the MCP variant-details response.
Returns:
-
str–Formatted variant name, or SKU if no parent name available.
Example
Source code in katana_public_api_client/domain/variant.py
matches_search(query)
¶
Check if variant matches search query with tokenization and fuzzy matching.
Searches across SKU, product/material name, supplier codes, and config attributes. Supports multi-word queries (all tokens must match) and tolerates typos via fuzzy matching.
Parameters:
-
query(str) –Search query string (case-insensitive, multi-word supported)
Returns:
-
bool–True if variant matches query
Example
Source code in katana_public_api_client/domain/variant.py
to_csv_row()
¶
Export as CSV-friendly row.
Returns:
Example
Source code in katana_public_api_client/domain/variant.py
Functions¶
build_variant_display_name(parent_name, config_attributes, fallback_sku=None)
¶
Build a variant's display name in Katana UI format.
Format: "{parent_name} / {config_value_1} / {config_value_2} / ...".
Falls back to fallback_sku when parent_name is empty (a
defensive case — Katana always returns a non-empty parent name in
practice, but the legacy cache handled the empty case so we
preserve it).
Accepts config_attributes as an iterable of either dicts
(domain models, MCP response dicts) or attrs objects (raw API
objects via ?extend= responses). Both routes converge on a
config_value field — the helper reads via dict.get for the
former and getattr + unwrap_unset for the latter. This is
the single source of truth for the formula; consumers in the
KatanaVariant domain class, the typed-cache postprocess hook,
and the MCP variant-details response all delegate to this function
so the rendered name stays consistent across the codebase.
Parameters:
-
parent_name(str | None) –The parent Product or Material's
name.Noneor empty triggers the SKU fallback. -
config_attributes(Iterable[Any] | None) –Iterable of variant config attribute records (e.g.
{"config_name": "Size", "config_value": "Large"}). Empty orNoneis fine — yields just the parent name. -
fallback_sku(str | None, default:None) –Returned (or empty string) when
parent_nameis empty.
Returns:
Example
build_variant_display_name( ... "Kitchen Knife", ... [ ... {"config_name": "Size", "config_value": "8-inch"}, ... {"config_name": "Color", "config_value": "Black"}, ... ], ... ) 'Kitchen Knife / 8-inch / Black' build_variant_display_name(None, [], fallback_sku="KNF-001") 'KNF-001'