Skip to content

katana_public_api_client.domain.service

katana_public_api_client.domain.service

Domain model for Service entities.

This module provides a Pydantic model representing a Service (external service) optimized for ETL, data processing, and business logic.

Classes

KatanaService

Bases: KatanaBaseModel

Domain model for a Service.

A Service represents an external service that can be used as part of manufacturing operations or business processes. 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
service = KatanaService(
    id=1,
    name="External Assembly Service",
    type="service",
    uom="pcs",
    category_name="Assembly",
    is_sellable=True,
)

# Business methods available
print(service.get_display_name())  # "External Assembly Service"

# ETL export
csv_row = service.to_csv_row()
schema = KatanaService.model_json_schema()
Functions
get_display_name()

Get formatted display name.

Returns:

  • str

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

Example
service = KatanaService(id=1, name="Assembly Service")
print(service.get_display_name())  # "Assembly Service"
Source code in katana_public_api_client/domain/service.py
def get_display_name(self) -> str:
    """Get formatted display name.

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

    Example:
        ```python
        service = KatanaService(id=1, name="Assembly Service")
        print(service.get_display_name())  # "Assembly Service"
        ```
    """
    return self.name or f"Unnamed Service {self.id}"

Check if service matches search query.

Searches across: - Service name - Category name

Parameters:

  • query (str) –

    Search query string (case-insensitive)

Returns:

  • bool

    True if service matches query

Example
service = KatanaService(
    id=1, name="Assembly Service", category_name="Manufacturing"
)
service.matches_search("assembly")  # True
service.matches_search("manufacturing")  # True
service.matches_search("packaging")  # False
Source code in katana_public_api_client/domain/service.py
def matches_search(self, query: str) -> bool:
    """Check if service matches search query.

    Searches across:
    - Service name
    - Category name

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

    Returns:
        True if service matches query

    Example:
        ```python
        service = KatanaService(
            id=1, name="Assembly Service", category_name="Manufacturing"
        )
        service.matches_search("assembly")  # True
        service.matches_search("manufacturing")  # True
        service.matches_search("packaging")  # 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
service = KatanaService(id=1, name="Test Service", is_sellable=True)
row = service.to_csv_row()
# {
#   "ID": 1,
#   "Name": "Test Service",
#   "Type": "service",
#   "Category": "",
#   ...
# }
Source code in katana_public_api_client/domain/service.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
        service = KatanaService(id=1, name="Test Service", is_sellable=True)
        row = service.to_csv_row()
        # {
        #   "ID": 1,
        #   "Name": "Test Service",
        #   "Type": "service",
        #   "Category": "",
        #   ...
        # }
        ```
    """
    return {
        "ID": self.id,
        "Name": self.get_display_name(),
        "Type": self.type_ or "service",
        "Category": self.category_name or "",
        "UOM": self.uom or "",
        "Is Sellable": self.is_sellable or False,
        "Variant Count": self.variant_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 "",
        "Deleted At": self.deleted_at or "",
    }