Skip to content

statuspro_public_api_client.domain

statuspro_public_api_client.domain

Pydantic domain models for StatusPro entities.

Hand-written domain models representing business entities from the StatusPro API, separate from the generated attrs API request/response models. Use these for business logic, validation, and ergonomic access to API data.

Example
from statuspro_public_api_client import StatusProClient
from statuspro_public_api_client.domain import Order

async with StatusProClient() as client:
    orders = await client.orders.list(per_page=50)
    for order in orders:
        print(f"{order.name}: {order.status.name}")

Classes

Customer

Bases: _Frozen

Customer details attached to an order.

Order

Bases: _Frozen

An order as returned by /orders list pages or /orders/{id}.

OrderStatus

Bases: _Frozen

The status currently set on an order (nested Status schema).

Distinct from :class:Status, which is a top-level status definition returned by /statuses and includes color instead of transition metadata.

PageMeta

Bases: _Frozen

Pagination envelope returned alongside list endpoints.

Matches the StatusPro OrderListMeta schema. current_page and last_page are used by the transport layer to auto-walk pages.

Status

Bases: BaseModel

A top-level status definition from the account's status catalog.

StatusProBaseModel

Bases: BaseModel

Base class for all Pydantic domain models.

Provides: - Immutability by default (frozen=True) - Automatic validation - JSON schema generation - Easy serialization for ETL - Common timestamp fields

Example
class OrderDomain(StatusProBaseModel):
    id: int
    name: str
    order_number: str | None = None

    @computed_field
    @property
    def display_name(self) -> str:
        return f"Order {self.name} (#{self.order_number})"
Functions
model_dump_for_etl()

Export to ETL-friendly format.

Removes None values and uses field aliases for cleaner output.

Returns:

  • dict[str, Any]

    Dictionary with all non-None fields

Example
order = Order(id=123, name="#1188", order_number="1188")
data = order.model_dump_for_etl()
# {"id": 123, "name": "#1188", "order_number": "1188"}
Source code in statuspro_public_api_client/domain/base.py
def model_dump_for_etl(self) -> dict[str, Any]:
    """Export to ETL-friendly format.

    Removes None values and uses field aliases for cleaner output.

    Returns:
        Dictionary with all non-None fields

    Example:
        ```python
        order = Order(id=123, name="#1188", order_number="1188")
        data = order.model_dump_for_etl()
        # {"id": 123, "name": "#1188", "order_number": "1188"}
        ```
    """
    return self.model_dump(exclude_none=True, by_alias=True)
to_dict_with_computed()

Export including computed fields.

Unlike model_dump(), this includes @computed_field properties.

Returns:

  • dict[str, Any]

    Dictionary with all fields including computed ones

Source code in statuspro_public_api_client/domain/base.py
def to_dict_with_computed(self) -> dict[str, Any]:
    """Export including computed fields.

    Unlike model_dump(), this includes @computed_field properties.

    Returns:
        Dictionary with all fields including computed ones
    """
    # Pydantic v2 automatically includes computed fields in model_dump
    return self.model_dump(mode="python", exclude_none=True)
to_warehouse_json()

Export as JSON for data warehouse.

Returns:

  • str

    JSON string with all non-None fields

Example
order = Order(id=123, name="#1188")
json_str = order.to_warehouse_json()
# '{"id":123,"name":"#1188"}'
Source code in statuspro_public_api_client/domain/base.py
def to_warehouse_json(self) -> str:
    """Export as JSON for data warehouse.

    Returns:
        JSON string with all non-None fields

    Example:
        ```python
        order = Order(id=123, name="#1188")
        json_str = order.to_warehouse_json()
        # '{"id":123,"name":"#1188"}'
        ```
    """
    return self.model_dump_json(exclude_none=True, by_alias=True)

Functions

to_unset(value)

Convert None to UNSET sentinel value.

Useful when building attrs API request models from optional Pydantic fields, where None means "not provided" and should be sent as UNSET to avoid overwriting existing values.

Parameters:

  • value (T | None) –

    Value that might be None

Returns:

  • T | Unset

    The value unchanged if not None, or UNSET if None

Example
from statuspro_public_api_client.domain.converters import to_unset

to_unset(42)  # 42
to_unset(None)  # UNSET
to_unset("USD")  # "USD"
Source code in statuspro_public_api_client/domain/converters.py
def to_unset[T](value: T | None) -> T | Unset:
    """Convert None to UNSET sentinel value.

    Useful when building attrs API request models from optional Pydantic fields,
    where None means "not provided" and should be sent as UNSET to avoid
    overwriting existing values.

    Args:
        value: Value that might be None

    Returns:
        The value unchanged if not None, or UNSET if None

    Example:
        ```python
        from statuspro_public_api_client.domain.converters import to_unset

        to_unset(42)  # 42
        to_unset(None)  # UNSET
        to_unset("USD")  # "USD"
        ```
    """
    return UNSET if value is None else value

unwrap_unset(value, default=None)

unwrap_unset(value: T | Unset | None) -> T | None
unwrap_unset(value: T | Unset | None, default: T) -> T

Unwrap an Unset or None sentinel value.

Parameters:

  • value (T | Unset | None) –

    Value that might be Unset or None

  • default (T | None, default: None ) –

    Default value to return if Unset or None

Returns:

  • T | None

    The unwrapped value, or default if value is Unset or None. When a

  • T | None

    non-None default is provided, the return type is narrowed to T

  • T | None

    (never None).

Example
from statuspro_public_api_client.client_types import UNSET

unwrap_unset(42)  # 42
unwrap_unset(UNSET)  # None
unwrap_unset(UNSET, 0)  # 0
unwrap_unset(None, 0)  # 0
Source code in statuspro_public_api_client/domain/converters.py
def unwrap_unset[T](value: T | Unset | None, default: T | None = None) -> T | None:
    """Unwrap an Unset or None sentinel value.

    Args:
        value: Value that might be Unset or None
        default: Default value to return if Unset or None

    Returns:
        The unwrapped value, or default if value is Unset or None. When a
        non-None default is provided, the return type is narrowed to ``T``
        (never None).

    Example:
        ```python
        from statuspro_public_api_client.client_types import UNSET

        unwrap_unset(42)  # 42
        unwrap_unset(UNSET)  # None
        unwrap_unset(UNSET, 0)  # 0
        unwrap_unset(None, 0)  # 0
        ```
    """
    if value is None or isinstance(value, Unset):
        return default
    return value