Skip to content

stapi-pydantic

Pydantic models for the Satellite Tasking API (STAPI) specification.

Note

This package has no input/output (IO) functionality. For making requests to a STAPI API, use pystapi-client.

API

Order

Bases: _GeoJsonBase, Generic[T]

Source code in stapi-pydantic/src/stapi_pydantic/order.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
class Order(_GeoJsonBase, Generic[T]):
    # We need to enforce that orders have an id defined, as that is required to
    # retrieve them via the API
    id: StrictStr
    type: Literal["Feature"] = "Feature"
    stapi_type: Literal["Order"] = "Order"
    stapi_version: str = STAPI_VERSION

    geometry: Geometry = Field(...)
    properties: OrderProperties[T] = Field(...)

    links: list[Link] = Field(default_factory=list)

    __geojson_exclude_if_none__ = {"bbox", "id"}

    @field_validator("geometry", mode="before")
    def set_geometry(cls, geometry: Any) -> Any:
        """set geometry from geo interface or input"""
        if hasattr(geometry, "__geo_interface__"):
            return geometry.__geo_interface__

        return geometry

set_geometry(geometry)

set geometry from geo interface or input

Source code in stapi-pydantic/src/stapi_pydantic/order.py
118
119
120
121
122
123
124
@field_validator("geometry", mode="before")
def set_geometry(cls, geometry: Any) -> Any:
    """set geometry from geo interface or input"""
    if hasattr(geometry, "__geo_interface__"):
        return geometry.__geo_interface__

    return geometry

OrderCollection

Bases: _GeoJsonBase, Generic[T]

Source code in stapi-pydantic/src/stapi_pydantic/order.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
class OrderCollection(_GeoJsonBase, Generic[T]):
    type: Literal["FeatureCollection"] = "FeatureCollection"
    features: list[Order[T]]
    links: list[Link] = Field(default_factory=list)

    def __iter__(self) -> Iterator[Order[T]]:  # type: ignore [override]
        """iterate over features"""
        return iter(self.features)

    def __len__(self) -> int:
        """return features length"""
        return len(self.features)

    def __getitem__(self, index: int) -> Order[T]:
        """get feature at a given index"""
        return self.features[index]

__getitem__(index)

get feature at a given index

Source code in stapi-pydantic/src/stapi_pydantic/order.py
141
142
143
def __getitem__(self, index: int) -> Order[T]:
    """get feature at a given index"""
    return self.features[index]

__iter__()

iterate over features

Source code in stapi-pydantic/src/stapi_pydantic/order.py
133
134
135
def __iter__(self) -> Iterator[Order[T]]:  # type: ignore [override]
    """iterate over features"""
    return iter(self.features)

__len__()

return features length

Source code in stapi-pydantic/src/stapi_pydantic/order.py
137
138
139
def __len__(self) -> int:
    """return features length"""
    return len(self.features)

OrderStatus

Bases: BaseModel

Source code in stapi-pydantic/src/stapi_pydantic/order.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class OrderStatus(BaseModel):
    timestamp: AwareDatetime
    status_code: OrderStatusCode
    reason_code: str | None = None
    reason_text: str | None = None
    links: list[Link] = Field(default_factory=list)

    model_config = ConfigDict(extra="allow")

    @classmethod
    def new(
        cls, status_code: OrderStatusCode, reason_code: str | None = None, reason_text: str | None = None
    ) -> OrderStatus:
        """Creates a new order status with timestamp set to now in UTC."""
        return OrderStatus(
            timestamp=datetime.datetime.now(tz=datetime.UTC),
            status_code=status_code,
            reason_code=reason_code,
            reason_text=reason_text,
        )

new(status_code, reason_code=None, reason_text=None) classmethod

Creates a new order status with timestamp set to now in UTC.

Source code in stapi-pydantic/src/stapi_pydantic/order.py
62
63
64
65
66
67
68
69
70
71
72
@classmethod
def new(
    cls, status_code: OrderStatusCode, reason_code: str | None = None, reason_text: str | None = None
) -> OrderStatus:
    """Creates a new order status with timestamp set to now in UTC."""
    return OrderStatus(
        timestamp=datetime.datetime.now(tz=datetime.UTC),
        status_code=status_code,
        reason_code=reason_code,
        reason_text=reason_text,
    )