Skip to content

katana_public_api_client.domain.product

katana_public_api_client.domain.product

Domain model for Product entities.

This module provides a Pydantic model representing a Product (finished good or component) optimized for ETL, data processing, and business logic.

Classes

KatanaProduct

Bases: KatanaBaseModel

Domain model for a Product.

A Product represents a finished good or component that can be sold, manufactured, or purchased, with support for variants and configurations. This is a Pydantic model optimized for: - ETL and data processing - Business logic - Data validation - JSON schema generation

Unlike the generated attrs model, this model: - Has no Unset sentinel values - Provides ETL-friendly methods - Is immutable by default - Clean Optional types

Example
product = KatanaProduct(
    id=1,
    name="Standard-hilt lightsaber",
    type="product",
    uom="pcs",
    category_name="lightsaber",
    is_sellable=True,
    is_producible=True,
    is_purchasable=True,
)

# Business methods available
print(product.get_display_name())  # "Standard-hilt lightsaber"

# ETL export
csv_row = product.to_csv_row()
schema = KatanaProduct.model_json_schema()
Functions
get_display_name()

Get formatted display name.

Returns:

  • str

    Product name, or "Unnamed Product {id}" if no name

Example
product = KatanaProduct(id=1, name="Kitchen Knife")
print(product.get_display_name())  # "Kitchen Knife"
Source code in katana_public_api_client/domain/product.py
def get_display_name(self) -> str:
    """Get formatted display name.

    Returns:
        Product name, or "Unnamed Product {id}" if no name

    Example:
        ```python
        product = KatanaProduct(id=1, name="Kitchen Knife")
        print(product.get_display_name())  # "Kitchen Knife"
        ```
    """
    return self.name or f"Unnamed Product {self.id}"

Check if product matches search query.

Searches across: - Product name - Category name

Parameters:

  • query (str) –

    Search query string (case-insensitive)

Returns:

  • bool

    True if product matches query

Example
product = KatanaProduct(
    id=1, name="Kitchen Knife", category_name="Cutlery"
)
product.matches_search("knife")  # True
product.matches_search("cutlery")  # True
product.matches_search("fork")  # False
Source code in katana_public_api_client/domain/product.py
def matches_search(self, query: str) -> bool:
    """Check if product matches search query.

    Searches across:
    - Product name
    - Category name

    Args:
        query: Search query string (case-insensitive)

    Returns:
        True if product matches query

    Example:
        ```python
        product = KatanaProduct(
            id=1, name="Kitchen Knife", category_name="Cutlery"
        )
        product.matches_search("knife")  # True
        product.matches_search("cutlery")  # True
        product.matches_search("fork")  # False
        ```
    """
    query_lower = query.lower()

    # Check name
    if self.name and query_lower in self.name.lower():
        return True

    # Check category
    return bool(self.category_name and query_lower in self.category_name.lower())
to_csv_row()

Export as CSV-friendly row.

Returns:

  • dict[str, Any]

    Dictionary with flattened data suitable for CSV export

Example
product = KatanaProduct(id=1, name="Test Product", is_sellable=True)
row = product.to_csv_row()
# {
#   "ID": 1,
#   "Name": "Test Product",
#   "Type": "product",
#   "Category": "",
#   ...
# }
Source code in katana_public_api_client/domain/product.py
def to_csv_row(self) -> dict[str, Any]:
    """Export as CSV-friendly row.

    Returns:
        Dictionary with flattened data suitable for CSV export

    Example:
        ```python
        product = KatanaProduct(id=1, name="Test Product", is_sellable=True)
        row = product.to_csv_row()
        # {
        #   "ID": 1,
        #   "Name": "Test Product",
        #   "Type": "product",
        #   "Category": "",
        #   ...
        # }
        ```
    """
    return {
        "ID": self.id,
        "Name": self.get_display_name(),
        "Type": self.type_,
        "Category": self.category_name or "",
        "UOM": self.uom or "",
        "Is Sellable": self.is_sellable or False,
        "Is Producible": self.is_producible or False,
        "Is Purchasable": self.is_purchasable or False,
        "Batch Tracked": self.batch_tracked or False,
        "Serial Tracked": self.serial_tracked or False,
        "Lead Time (days)": self.lead_time or 0,
        "Min Order Qty": self.minimum_order_quantity or 0,
        "Variant Count": self.variant_count,
        "Config Count": self.config_count,
        "Created At": self.created_at.isoformat() if self.created_at else "",
        "Updated At": self.updated_at.isoformat() if self.updated_at else "",
        "Archived At": self.archived_at or "",
    }