Domain model for Service entities.
This module provides a Pydantic model representing a Service (external service)
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
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
This model uses composition with the auto-generated Pydantic model,
exposing a curated subset of fields with business methods.
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
from_attrs(attrs_service)
classmethod
Create a KatanaService from an attrs Service 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_service
(Service)
–
The attrs Service model from API response.
Returns:
-
KatanaService
–
A new KatanaService instance with business methods.
Example
from katana_public_api_client.api.service import get_service
from katana_public_api_client.utils import unwrap
response = await get_service.asyncio_detailed(client=client, id=123)
attrs_service = unwrap(response)
domain = KatanaService.from_attrs(attrs_service)
Source code in katana_public_api_client/domain/service.py
| @classmethod
def from_attrs(cls, attrs_service: AttrsService) -> KatanaService:
"""Create a KatanaService from an attrs Service model (API response).
This method leverages the generated Pydantic model's `from_attrs()` method
to handle UNSET sentinel conversion, then creates the domain model.
Args:
attrs_service: The attrs Service model from API response.
Returns:
A new KatanaService instance with business methods.
Example:
```python
from katana_public_api_client.api.service import get_service
from katana_public_api_client.utils import unwrap
response = await get_service.asyncio_detailed(client=client, id=123)
attrs_service = unwrap(response)
domain = KatanaService.from_attrs(attrs_service)
```
"""
from ..models_pydantic._generated.inventory import Service as GeneratedService
# Use generated model's from_attrs() to handle UNSET conversion
generated = GeneratedService.from_attrs(attrs_service)
return cls.from_generated(generated)
|
from_generated(generated)
classmethod
Create a KatanaService from a generated Pydantic Service model.
This method extracts the curated subset of fields from the generated model.
Parameters:
-
generated
(Service)
–
The auto-generated Pydantic Service model.
Returns:
-
KatanaService
–
A new KatanaService instance with business methods.
Example
from katana_public_api_client.models_pydantic import Service
# Convert from generated pydantic model
generated = Service.from_attrs(attrs_service)
domain = KatanaService.from_generated(generated)
Source code in katana_public_api_client/domain/service.py
| @classmethod
def from_generated(cls, generated: GeneratedService) -> KatanaService:
"""Create a KatanaService from a generated Pydantic Service model.
This method extracts the curated subset of fields from the generated model.
Args:
generated: The auto-generated Pydantic Service model.
Returns:
A new KatanaService instance with business methods.
Example:
```python
from katana_public_api_client.models_pydantic import Service
# Convert from generated pydantic model
generated = Service.from_attrs(attrs_service)
domain = KatanaService.from_generated(generated)
```
"""
# Count nested collections
variant_count = len(generated.variants) if generated.variants else 0
# Type is always "service" for Service entities
return cls(
id=generated.id,
name=generated.name,
type="service", # Always "service" - required field
uom=generated.uom,
category_name=generated.category_name,
is_sellable=generated.is_sellable,
additional_info=generated.additional_info,
custom_field_collection_id=generated.custom_field_collection_id,
archived_at=generated.archived_at,
variant_count=variant_count,
created_at=generated.created_at,
updated_at=generated.updated_at,
deleted_at=generated.deleted_at,
)
|
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}"
|
matches_search(query)
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_,
"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.isoformat() if self.archived_at else "",
"Deleted At": self.deleted_at.isoformat() if self.deleted_at else "",
}
|