Skip to content

Inventory

ItemsClient

Source code in src/spyre/inventory.py
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
class ItemsClient():

    def __init__(self, client : SpireClient):
        self.client = client
        self.endpoint = 'inventory/items'

    def get_item(self, id: int = None, part_no: str = None, warehouse: str = None) -> "item":
        """
        Retrieve an inventory item by ID or (part_no + warehouse).

        Sends a GET request to the Spire API to fetch inventory item data for the
        specified ID, or uses a filtered query with part number and warehouse.
        Wraps the result in an `item` instance, which retains a reference to the
        client for further actions.

        Args:
            id (int, optional): The ID of the inventory item to retrieve.
            part_no (str, optional): The part number of the item to retrieve.
            warehouse (str, optional): The warehouse code where the item is located.

        Returns:
            item: An `item` wrapper instance containing the retrieved data.

        Raises:
            ValueError: If neither ID nor (part_no and warehouse) are provided,
                        or if no matching item is found.
        """
        if id is not None:
            response = self.client._get(f"/{self.endpoint}/{str(id)}")
            return item.from_json(response, self.client)

        elif part_no and warehouse:
            items = self.query_inventory_items(filter={"partNo": part_no, "whse": warehouse})
            for itm in items:
                if getattr(itm, "partNo", None) == part_no and getattr(itm, "whse", None) == warehouse:
                    return itm
            raise ValueError(f"No item found with part_no='{part_no}' and warehouse='{warehouse}'.")

        else:
            raise ValueError("You must provide either 'id' or both 'part_no' and 'warehouse'.")

    def create_item(self, item : 'InventoryItem') -> 'item':
        """
        Create a new Inventory Item in Spire.

        Sends a POST request to the Inventory/Items endpoint .

        Args:
            item (dict): A InventoryItem instace containing the sales order details.

        Returns:
            item: The created InventoryItem instance.

        Raises:
            CreateRequestError: If the creation fails or response is invalid.
        """

        response =  self.client._post(f"/{self.endpoint}", json=item.model_dump(exclude_unset=True, exclude_none=True))
        if response.get('status_code') == 201:
            location = response.get('headers').get('location')
            parsed_url = urlparse(location)
            path_segments = parsed_url.path.rstrip("/").split("/")
            id = path_segments[-1]
            return self.get_item(id)
        else:
            error_message = response.get('content')
            raise CreateRequestError(self.endpoint, status_code=response.get('status_code'), error_message=error_message)


    def update_item(self, id: int, inventory_item : 'InventoryItem') -> "item":
        """
        Update an existing Inventory Item by ID.

        Sends a PUT request to the Inventory/Items endpoint with the provided data
        to update the existing record. Returns a wrapped `item` object containing
        the updated information.

        Args:
            id (int): The ID of the item to update.
            inventory_item (InventoryItem): A InventoryItem instance with the sales order details.

        Returns:
            item: An instance of the item wrapper class initialized with 
                        the updated data and client session.
        """
        response = self.client._put(f"/{self.endpoint}/{str(id)}", json=inventory_item.model_dump(exclude_none=True, exclude_unset=True))
        return item.from_json(response, self.client)

    def delete_item(self, id: int) -> bool:
        """
        Delete a inventory_item by its ID.

        Sends a DELETE request to the endpoint to remove the specified
        inventory item from the system.

        Args:
            id (int): The ID of the inventory item to delete.

        Returns:
            bool (bool): True if the item was successfully deleted, False otherwise.
        """
        return self.client._delete(f"/{self.endpoint}/{str(id)}")


    def query_inventory_items(
        self,
        *,
        query: Optional[str] = None,
        sort: Optional[Dict[str, str]] = None,
        filter: Optional[Dict[str, Any]] = None,
        all: bool = False,
        limit: int = 1000,
        start: int = 0,
        **extra_params
    ) -> List["item"]:
        """
        Query inventory items with optional full-text search, filtering, multi-field sorting, and pagination.

        Args:
            query (str, optional): Full-text search string.
            sort (dict, optional): Dictionary of sorting rules (e.g., {"orderDate": "desc", "orderNo": "asc"}).
            filter (dict, optional): Dictionary of filters to apply (will be JSON-encoded and URL-safe).
            all (bool, optional): If True, retrieves all pages of results.
            limit (int, optional): Number of results per page (max 1000).
            start (int, optional): Starting offset for pagination.
            **extra_params (Any): Any additional parameters to include in the query.

        Returns:
            List[item]: List of wrapped sales order resources.
        """
        return self.client._query(
            endpoint=self.endpoint,
            resource_cls=item,
            query=query,
            sort=sort,
            filter=filter,
            all=all,
            limit=limit,
            start=start,
            **extra_params
        )

    def get_item_uoms(self, id : int) -> List["uom"]:
        """
        Retrieve all Unit of Measure (UOM) entries for a specific inventory item.

        This method sends a GET request to the Spire API to retrieve the unit of measure
        records associated with the specified inventory item ID. Each returned record is 
        wrapped into a `uom` object, which includes the model and the client reference.

        Args:
            id (int): The unique identifier of the inventory item.

        Returns:
            List[uom]: A list of `uom` objects representing the UOM records for the item.
        """
        uoms = []
        response = self.client._get(f"{self.endpoint}/{str(id)}/uoms")
        items = response.get('records')
        for item in items:
            uoms.append(uom.from_json(json_data=item, client = self.client, item_id = id))
        return uoms

    def get_uom(self, item_id :int , uom_id : int) -> "uom":
        """
        Retrieve a specific Unit of Measure (UOM) for a given inventory item.

        This method sends a GET request to the Spire API to fetch a single UOM record
        associated with a specific inventory item and UOM ID. The response is wrapped
        into a `uom` object that maintains a reference to the API client.

        Args:
            item_id (int): The unique ID of the inventory item.
            uom_id (int): The unique ID of the UOM to retrieve.

        Returns:
            uom: A `uom` object representing the retrieved unit of measure.

        """
        response = self.client._get(f"/{self.endpoint}/{str(item_id)}/uoms/{str(uom_id)}")
        return uom.from_json(response, self.client , item_id = item_id)


    def create_item_uom(self, id: int, uom : UnitOfMeasure) -> "uom":
        """
        Create a new Unit of Measure (UOM) for a specific inventory item.

        Sends a POST request to the Spire API to create a new UOM for the inventory item
        with the specified ID. If successful, the method retrieves and returns the newly
        created UOM object. If the creation fails, an exception is raised.

        Args:
            id (int): The ID of the inventory item for which to create the UOM.
            uom (UnitOfMeasure): A Pydantic model instance representing the UOM to create.

        Returns:
            List[uom]: A list containing the created `uom` object.

        Raises:
            CreateRequestError: If the API response status is not 201 (Created).
        """
        response =  self.client._post(f"/{self.endpoint}/{str(id)}/uoms", json=uom.model_dump(exclude_unset=True, exclude_none=True))
        if response.get('status_code') == 201:
            location = response.get('headers').get('location')
            parsed_url = urlparse(location)
            path_segments = parsed_url.path.rstrip("/").split("/")
            new_uom_id = path_segments[-1]
            return self.get_uom(item_id=id, uom_id=new_uom_id)
        else:
            error_message = response.get('content')
            raise CreateRequestError(self.endpoint, status_code=response.get('status_code'), error_message=error_message)

    def delete_uom(self, item_id : int, uom_id :int) -> bool:
        """
        Delete a Unit of Measure (UOM) from a specific inventory item.

        Sends a DELETE request to the Spire API to remove a UOM associated with the
        given item and UOM ID.

        Args:
            item_id (int): The ID of the inventory item.
            uom_id (int): The ID of the Unit of Measure to delete.

        Returns:
            bool: True if the deletion was successful, otherwise raises an error.
        """
        return self.client._delete(f"/{self.endpoint}/{str(item_id)}/uoms/{str(uom_id)}")

    def update_item_uom(self, item_id: int, uom_id : int, uom_record :'uom') -> 'uom':
        """
        Update an existing Unit of Measure (UOM) for a given inventory item.

        Sends a PUT request to the Spire API to update the UOM record with the specified
        item and UOM ID using the provided `uom` data.

        Args:
            item_id (int): The ID of the inventory item.
            uom_id (int): The ID of the UOM to update.
            uom_record (uom): A `uom` instance with updated field values.

        Returns:
            uom: The updated `uom` instance returned from the API.
        """
        response = self.client._put(f"/{self.endpoint}/{str(item_id)}/uoms/{str(uom_id)}", json=uom_record.model_dump(exclude_none=True, exclude_unset=True))
        return uom.from_json(response, self.client, item_id = item_id)


    def get_item_upcs(self, id : int) -> List["upc"]:
        """
        Retrieve all UPC records associated with a specific inventory item.

        Sends a GET request to the Spire API to fetch UPCs for the specified item ID,
        then constructs and returns a list of `upc` objects.

        Args:
            id (int): The ID of the inventory item.

        Returns:
            List[upc]: A list of `upc` objects representing the item's UPC codes.
        """
        upcs = []
        response = self.client._get(f"{self.endpoint}/{str(id)}/upcs")
        items = response.get('records')
        for item in items:
            upcs.append(upc.from_json(json_data=item, client = self.client, item_id = id))

        return upcs

    def get_upc(self, item_id :int , upc_id : int) -> "upc":
        """
        Retrieve a specific UPC (upc) for a given inventory item.

        This method sends a GET request to the Spire API to fetch a single upc record
        associated with a specific inventory item and upc ID. The response is wrapped
        into a `upc` object that maintains a reference to the API client.

        Args:
            item_id (int): The unique ID of the inventory item.
            upc_id (int): The unique ID of the upc to retrieve.

        Returns:
            upc: A `upc` object representing the retrieved unit of measure.

        """
        response = self.client._get(f"/{self.endpoint}/{str(item_id)}/upcs/{str(upc_id)}")
        return upc.from_json(response, self.client , item_id = item_id)

    def create_item_upc(self, id: int, upc : UPC) -> "upc":
        """
        Create a new UPC (upc) for a specific inventory item.

        Sends a POST request to the Spire API to create a new upc for the inventory item
        with the specified ID. If successful, the method retrieves and returns the newly
        created upc object. If the creation fails, an exception is raised.

        Args:
            id (int): The ID of the inventory item for which to create the upc.
            upc (UPC): A Pydantic model instance representing the upc to create.

        Returns:
            List[upc]: A list containing the created `upc` object.

        Raises:
            CreateRequestError: If the API response status is not 201 (Created).
        """
        response =  self.client._post(f"/{self.endpoint}/{str(id)}/upcs", json=upc.model_dump(exclude_unset=True, exclude_none=True))
        if response.get('status_code') == 201:
            location = response.get('headers').get('location')
            parsed_url = urlparse(location)
            path_segments = parsed_url.path.rstrip("/").split("/")
            new_upc_id = path_segments[-1]
            return self.get_upc(item_id=id, upc_id = new_upc_id)
        else:
            error_message = response.get('content')
            raise CreateRequestError(self.endpoint, status_code=response.get('status_code'), error_message=error_message)

    def delete_upc(self, item_id : int, upc_id :int) -> bool:
        """
        Delete a UPC (upc) from a specific inventory item.

        Sends a DELETE request to the Spire API to remove a upc associated with the
        given item and upc ID.

        Args:
            item_id (int): The ID of the inventory item.
            upc_id (int): The ID of the Unit of Measure to delete.

        Returns:
            bool: True if the deletion was successful, otherwise raises an error.
        """
        return self.client._delete(f"/{self.endpoint}/{str(item_id)}/upcs/{str(upc_id)}")

    def update_item_upc(self, item_id: int, upc_id : int, upc_record :'upc') -> 'upc':
        """
        Update an existing UPC (upc) for a given inventory item.

        Sends a PUT request to the Spire API to update the upc record with the specified
        item and upc ID using the provided `upc` data.

        Args:
            item_id (int): The ID of the inventory item.
            upc_id (int): The ID of the upc to update.
            upc_record (upc): A `upc` instance with updated field values.

        Returns:
            upc: The updated `upc` instance returned from the API.
        """
        response = self.client._put(f"/{self.endpoint}/{str(item_id)}/upcs/{str(upc_id)}", json=upc_record.model_dump(exclude_none=True, exclude_unset=True))
        return upc.from_json(response, self.client, item_id = item_id)

create_item(item)

Create a new Inventory Item in Spire.

Sends a POST request to the Inventory/Items endpoint .

Parameters:

Name Type Description Default
item dict

A InventoryItem instace containing the sales order details.

required

Returns:

Name Type Description
item item

The created InventoryItem instance.

Raises:

Type Description
CreateRequestError

If the creation fails or response is invalid.

Source code in src/spyre/inventory.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
def create_item(self, item : 'InventoryItem') -> 'item':
    """
    Create a new Inventory Item in Spire.

    Sends a POST request to the Inventory/Items endpoint .

    Args:
        item (dict): A InventoryItem instace containing the sales order details.

    Returns:
        item: The created InventoryItem instance.

    Raises:
        CreateRequestError: If the creation fails or response is invalid.
    """

    response =  self.client._post(f"/{self.endpoint}", json=item.model_dump(exclude_unset=True, exclude_none=True))
    if response.get('status_code') == 201:
        location = response.get('headers').get('location')
        parsed_url = urlparse(location)
        path_segments = parsed_url.path.rstrip("/").split("/")
        id = path_segments[-1]
        return self.get_item(id)
    else:
        error_message = response.get('content')
        raise CreateRequestError(self.endpoint, status_code=response.get('status_code'), error_message=error_message)

create_item_uom(id, uom)

Create a new Unit of Measure (UOM) for a specific inventory item.

Sends a POST request to the Spire API to create a new UOM for the inventory item with the specified ID. If successful, the method retrieves and returns the newly created UOM object. If the creation fails, an exception is raised.

Parameters:

Name Type Description Default
id int

The ID of the inventory item for which to create the UOM.

required
uom UnitOfMeasure

A Pydantic model instance representing the UOM to create.

required

Returns:

Type Description
uom

List[uom]: A list containing the created uom object.

Raises:

Type Description
CreateRequestError

If the API response status is not 201 (Created).

Source code in src/spyre/inventory.py
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
def create_item_uom(self, id: int, uom : UnitOfMeasure) -> "uom":
    """
    Create a new Unit of Measure (UOM) for a specific inventory item.

    Sends a POST request to the Spire API to create a new UOM for the inventory item
    with the specified ID. If successful, the method retrieves and returns the newly
    created UOM object. If the creation fails, an exception is raised.

    Args:
        id (int): The ID of the inventory item for which to create the UOM.
        uom (UnitOfMeasure): A Pydantic model instance representing the UOM to create.

    Returns:
        List[uom]: A list containing the created `uom` object.

    Raises:
        CreateRequestError: If the API response status is not 201 (Created).
    """
    response =  self.client._post(f"/{self.endpoint}/{str(id)}/uoms", json=uom.model_dump(exclude_unset=True, exclude_none=True))
    if response.get('status_code') == 201:
        location = response.get('headers').get('location')
        parsed_url = urlparse(location)
        path_segments = parsed_url.path.rstrip("/").split("/")
        new_uom_id = path_segments[-1]
        return self.get_uom(item_id=id, uom_id=new_uom_id)
    else:
        error_message = response.get('content')
        raise CreateRequestError(self.endpoint, status_code=response.get('status_code'), error_message=error_message)

create_item_upc(id, upc)

Create a new UPC (upc) for a specific inventory item.

Sends a POST request to the Spire API to create a new upc for the inventory item with the specified ID. If successful, the method retrieves and returns the newly created upc object. If the creation fails, an exception is raised.

Parameters:

Name Type Description Default
id int

The ID of the inventory item for which to create the upc.

required
upc UPC

A Pydantic model instance representing the upc to create.

required

Returns:

Type Description
upc

List[upc]: A list containing the created upc object.

Raises:

Type Description
CreateRequestError

If the API response status is not 201 (Created).

Source code in src/spyre/inventory.py
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
def create_item_upc(self, id: int, upc : UPC) -> "upc":
    """
    Create a new UPC (upc) for a specific inventory item.

    Sends a POST request to the Spire API to create a new upc for the inventory item
    with the specified ID. If successful, the method retrieves and returns the newly
    created upc object. If the creation fails, an exception is raised.

    Args:
        id (int): The ID of the inventory item for which to create the upc.
        upc (UPC): A Pydantic model instance representing the upc to create.

    Returns:
        List[upc]: A list containing the created `upc` object.

    Raises:
        CreateRequestError: If the API response status is not 201 (Created).
    """
    response =  self.client._post(f"/{self.endpoint}/{str(id)}/upcs", json=upc.model_dump(exclude_unset=True, exclude_none=True))
    if response.get('status_code') == 201:
        location = response.get('headers').get('location')
        parsed_url = urlparse(location)
        path_segments = parsed_url.path.rstrip("/").split("/")
        new_upc_id = path_segments[-1]
        return self.get_upc(item_id=id, upc_id = new_upc_id)
    else:
        error_message = response.get('content')
        raise CreateRequestError(self.endpoint, status_code=response.get('status_code'), error_message=error_message)

delete_item(id)

Delete a inventory_item by its ID.

Sends a DELETE request to the endpoint to remove the specified inventory item from the system.

Parameters:

Name Type Description Default
id int

The ID of the inventory item to delete.

required

Returns:

Name Type Description
bool bool

True if the item was successfully deleted, False otherwise.

Source code in src/spyre/inventory.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
def delete_item(self, id: int) -> bool:
    """
    Delete a inventory_item by its ID.

    Sends a DELETE request to the endpoint to remove the specified
    inventory item from the system.

    Args:
        id (int): The ID of the inventory item to delete.

    Returns:
        bool (bool): True if the item was successfully deleted, False otherwise.
    """
    return self.client._delete(f"/{self.endpoint}/{str(id)}")

delete_uom(item_id, uom_id)

Delete a Unit of Measure (UOM) from a specific inventory item.

Sends a DELETE request to the Spire API to remove a UOM associated with the given item and UOM ID.

Parameters:

Name Type Description Default
item_id int

The ID of the inventory item.

required
uom_id int

The ID of the Unit of Measure to delete.

required

Returns:

Name Type Description
bool bool

True if the deletion was successful, otherwise raises an error.

Source code in src/spyre/inventory.py
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
def delete_uom(self, item_id : int, uom_id :int) -> bool:
    """
    Delete a Unit of Measure (UOM) from a specific inventory item.

    Sends a DELETE request to the Spire API to remove a UOM associated with the
    given item and UOM ID.

    Args:
        item_id (int): The ID of the inventory item.
        uom_id (int): The ID of the Unit of Measure to delete.

    Returns:
        bool: True if the deletion was successful, otherwise raises an error.
    """
    return self.client._delete(f"/{self.endpoint}/{str(item_id)}/uoms/{str(uom_id)}")

delete_upc(item_id, upc_id)

Delete a UPC (upc) from a specific inventory item.

Sends a DELETE request to the Spire API to remove a upc associated with the given item and upc ID.

Parameters:

Name Type Description Default
item_id int

The ID of the inventory item.

required
upc_id int

The ID of the Unit of Measure to delete.

required

Returns:

Name Type Description
bool bool

True if the deletion was successful, otherwise raises an error.

Source code in src/spyre/inventory.py
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
def delete_upc(self, item_id : int, upc_id :int) -> bool:
    """
    Delete a UPC (upc) from a specific inventory item.

    Sends a DELETE request to the Spire API to remove a upc associated with the
    given item and upc ID.

    Args:
        item_id (int): The ID of the inventory item.
        upc_id (int): The ID of the Unit of Measure to delete.

    Returns:
        bool: True if the deletion was successful, otherwise raises an error.
    """
    return self.client._delete(f"/{self.endpoint}/{str(item_id)}/upcs/{str(upc_id)}")

get_item(id=None, part_no=None, warehouse=None)

Retrieve an inventory item by ID or (part_no + warehouse).

Sends a GET request to the Spire API to fetch inventory item data for the specified ID, or uses a filtered query with part number and warehouse. Wraps the result in an item instance, which retains a reference to the client for further actions.

Parameters:

Name Type Description Default
id int

The ID of the inventory item to retrieve.

None
part_no str

The part number of the item to retrieve.

None
warehouse str

The warehouse code where the item is located.

None

Returns:

Name Type Description
item item

An item wrapper instance containing the retrieved data.

Raises:

Type Description
ValueError

If neither ID nor (part_no and warehouse) are provided, or if no matching item is found.

Source code in src/spyre/inventory.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def get_item(self, id: int = None, part_no: str = None, warehouse: str = None) -> "item":
    """
    Retrieve an inventory item by ID or (part_no + warehouse).

    Sends a GET request to the Spire API to fetch inventory item data for the
    specified ID, or uses a filtered query with part number and warehouse.
    Wraps the result in an `item` instance, which retains a reference to the
    client for further actions.

    Args:
        id (int, optional): The ID of the inventory item to retrieve.
        part_no (str, optional): The part number of the item to retrieve.
        warehouse (str, optional): The warehouse code where the item is located.

    Returns:
        item: An `item` wrapper instance containing the retrieved data.

    Raises:
        ValueError: If neither ID nor (part_no and warehouse) are provided,
                    or if no matching item is found.
    """
    if id is not None:
        response = self.client._get(f"/{self.endpoint}/{str(id)}")
        return item.from_json(response, self.client)

    elif part_no and warehouse:
        items = self.query_inventory_items(filter={"partNo": part_no, "whse": warehouse})
        for itm in items:
            if getattr(itm, "partNo", None) == part_no and getattr(itm, "whse", None) == warehouse:
                return itm
        raise ValueError(f"No item found with part_no='{part_no}' and warehouse='{warehouse}'.")

    else:
        raise ValueError("You must provide either 'id' or both 'part_no' and 'warehouse'.")

get_item_uoms(id)

Retrieve all Unit of Measure (UOM) entries for a specific inventory item.

This method sends a GET request to the Spire API to retrieve the unit of measure records associated with the specified inventory item ID. Each returned record is wrapped into a uom object, which includes the model and the client reference.

Parameters:

Name Type Description Default
id int

The unique identifier of the inventory item.

required

Returns:

Type Description
List[uom]

List[uom]: A list of uom objects representing the UOM records for the item.

Source code in src/spyre/inventory.py
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
def get_item_uoms(self, id : int) -> List["uom"]:
    """
    Retrieve all Unit of Measure (UOM) entries for a specific inventory item.

    This method sends a GET request to the Spire API to retrieve the unit of measure
    records associated with the specified inventory item ID. Each returned record is 
    wrapped into a `uom` object, which includes the model and the client reference.

    Args:
        id (int): The unique identifier of the inventory item.

    Returns:
        List[uom]: A list of `uom` objects representing the UOM records for the item.
    """
    uoms = []
    response = self.client._get(f"{self.endpoint}/{str(id)}/uoms")
    items = response.get('records')
    for item in items:
        uoms.append(uom.from_json(json_data=item, client = self.client, item_id = id))
    return uoms

get_item_upcs(id)

Retrieve all UPC records associated with a specific inventory item.

Sends a GET request to the Spire API to fetch UPCs for the specified item ID, then constructs and returns a list of upc objects.

Parameters:

Name Type Description Default
id int

The ID of the inventory item.

required

Returns:

Type Description
List[upc]

List[upc]: A list of upc objects representing the item's UPC codes.

Source code in src/spyre/inventory.py
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
def get_item_upcs(self, id : int) -> List["upc"]:
    """
    Retrieve all UPC records associated with a specific inventory item.

    Sends a GET request to the Spire API to fetch UPCs for the specified item ID,
    then constructs and returns a list of `upc` objects.

    Args:
        id (int): The ID of the inventory item.

    Returns:
        List[upc]: A list of `upc` objects representing the item's UPC codes.
    """
    upcs = []
    response = self.client._get(f"{self.endpoint}/{str(id)}/upcs")
    items = response.get('records')
    for item in items:
        upcs.append(upc.from_json(json_data=item, client = self.client, item_id = id))

    return upcs

get_uom(item_id, uom_id)

Retrieve a specific Unit of Measure (UOM) for a given inventory item.

This method sends a GET request to the Spire API to fetch a single UOM record associated with a specific inventory item and UOM ID. The response is wrapped into a uom object that maintains a reference to the API client.

Parameters:

Name Type Description Default
item_id int

The unique ID of the inventory item.

required
uom_id int

The unique ID of the UOM to retrieve.

required

Returns:

Name Type Description
uom uom

A uom object representing the retrieved unit of measure.

Source code in src/spyre/inventory.py
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
def get_uom(self, item_id :int , uom_id : int) -> "uom":
    """
    Retrieve a specific Unit of Measure (UOM) for a given inventory item.

    This method sends a GET request to the Spire API to fetch a single UOM record
    associated with a specific inventory item and UOM ID. The response is wrapped
    into a `uom` object that maintains a reference to the API client.

    Args:
        item_id (int): The unique ID of the inventory item.
        uom_id (int): The unique ID of the UOM to retrieve.

    Returns:
        uom: A `uom` object representing the retrieved unit of measure.

    """
    response = self.client._get(f"/{self.endpoint}/{str(item_id)}/uoms/{str(uom_id)}")
    return uom.from_json(response, self.client , item_id = item_id)

get_upc(item_id, upc_id)

Retrieve a specific UPC (upc) for a given inventory item.

This method sends a GET request to the Spire API to fetch a single upc record associated with a specific inventory item and upc ID. The response is wrapped into a upc object that maintains a reference to the API client.

Parameters:

Name Type Description Default
item_id int

The unique ID of the inventory item.

required
upc_id int

The unique ID of the upc to retrieve.

required

Returns:

Name Type Description
upc upc

A upc object representing the retrieved unit of measure.

Source code in src/spyre/inventory.py
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
def get_upc(self, item_id :int , upc_id : int) -> "upc":
    """
    Retrieve a specific UPC (upc) for a given inventory item.

    This method sends a GET request to the Spire API to fetch a single upc record
    associated with a specific inventory item and upc ID. The response is wrapped
    into a `upc` object that maintains a reference to the API client.

    Args:
        item_id (int): The unique ID of the inventory item.
        upc_id (int): The unique ID of the upc to retrieve.

    Returns:
        upc: A `upc` object representing the retrieved unit of measure.

    """
    response = self.client._get(f"/{self.endpoint}/{str(item_id)}/upcs/{str(upc_id)}")
    return upc.from_json(response, self.client , item_id = item_id)

query_inventory_items(*, query=None, sort=None, filter=None, all=False, limit=1000, start=0, **extra_params)

Query inventory items with optional full-text search, filtering, multi-field sorting, and pagination.

Parameters:

Name Type Description Default
query str

Full-text search string.

None
sort dict

Dictionary of sorting rules (e.g., {"orderDate": "desc", "orderNo": "asc"}).

None
filter dict

Dictionary of filters to apply (will be JSON-encoded and URL-safe).

None
all bool

If True, retrieves all pages of results.

False
limit int

Number of results per page (max 1000).

1000
start int

Starting offset for pagination.

0
**extra_params Any

Any additional parameters to include in the query.

{}

Returns:

Type Description
List[item]

List[item]: List of wrapped sales order resources.

Source code in src/spyre/inventory.py
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
def query_inventory_items(
    self,
    *,
    query: Optional[str] = None,
    sort: Optional[Dict[str, str]] = None,
    filter: Optional[Dict[str, Any]] = None,
    all: bool = False,
    limit: int = 1000,
    start: int = 0,
    **extra_params
) -> List["item"]:
    """
    Query inventory items with optional full-text search, filtering, multi-field sorting, and pagination.

    Args:
        query (str, optional): Full-text search string.
        sort (dict, optional): Dictionary of sorting rules (e.g., {"orderDate": "desc", "orderNo": "asc"}).
        filter (dict, optional): Dictionary of filters to apply (will be JSON-encoded and URL-safe).
        all (bool, optional): If True, retrieves all pages of results.
        limit (int, optional): Number of results per page (max 1000).
        start (int, optional): Starting offset for pagination.
        **extra_params (Any): Any additional parameters to include in the query.

    Returns:
        List[item]: List of wrapped sales order resources.
    """
    return self.client._query(
        endpoint=self.endpoint,
        resource_cls=item,
        query=query,
        sort=sort,
        filter=filter,
        all=all,
        limit=limit,
        start=start,
        **extra_params
    )

update_item(id, inventory_item)

Update an existing Inventory Item by ID.

Sends a PUT request to the Inventory/Items endpoint with the provided data to update the existing record. Returns a wrapped item object containing the updated information.

Parameters:

Name Type Description Default
id int

The ID of the item to update.

required
inventory_item InventoryItem

A InventoryItem instance with the sales order details.

required

Returns:

Name Type Description
item item

An instance of the item wrapper class initialized with the updated data and client session.

Source code in src/spyre/inventory.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
def update_item(self, id: int, inventory_item : 'InventoryItem') -> "item":
    """
    Update an existing Inventory Item by ID.

    Sends a PUT request to the Inventory/Items endpoint with the provided data
    to update the existing record. Returns a wrapped `item` object containing
    the updated information.

    Args:
        id (int): The ID of the item to update.
        inventory_item (InventoryItem): A InventoryItem instance with the sales order details.

    Returns:
        item: An instance of the item wrapper class initialized with 
                    the updated data and client session.
    """
    response = self.client._put(f"/{self.endpoint}/{str(id)}", json=inventory_item.model_dump(exclude_none=True, exclude_unset=True))
    return item.from_json(response, self.client)

update_item_uom(item_id, uom_id, uom_record)

Update an existing Unit of Measure (UOM) for a given inventory item.

Sends a PUT request to the Spire API to update the UOM record with the specified item and UOM ID using the provided uom data.

Parameters:

Name Type Description Default
item_id int

The ID of the inventory item.

required
uom_id int

The ID of the UOM to update.

required
uom_record uom

A uom instance with updated field values.

required

Returns:

Name Type Description
uom uom

The updated uom instance returned from the API.

Source code in src/spyre/inventory.py
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
def update_item_uom(self, item_id: int, uom_id : int, uom_record :'uom') -> 'uom':
    """
    Update an existing Unit of Measure (UOM) for a given inventory item.

    Sends a PUT request to the Spire API to update the UOM record with the specified
    item and UOM ID using the provided `uom` data.

    Args:
        item_id (int): The ID of the inventory item.
        uom_id (int): The ID of the UOM to update.
        uom_record (uom): A `uom` instance with updated field values.

    Returns:
        uom: The updated `uom` instance returned from the API.
    """
    response = self.client._put(f"/{self.endpoint}/{str(item_id)}/uoms/{str(uom_id)}", json=uom_record.model_dump(exclude_none=True, exclude_unset=True))
    return uom.from_json(response, self.client, item_id = item_id)

update_item_upc(item_id, upc_id, upc_record)

Update an existing UPC (upc) for a given inventory item.

Sends a PUT request to the Spire API to update the upc record with the specified item and upc ID using the provided upc data.

Parameters:

Name Type Description Default
item_id int

The ID of the inventory item.

required
upc_id int

The ID of the upc to update.

required
upc_record upc

A upc instance with updated field values.

required

Returns:

Name Type Description
upc upc

The updated upc instance returned from the API.

Source code in src/spyre/inventory.py
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
def update_item_upc(self, item_id: int, upc_id : int, upc_record :'upc') -> 'upc':
    """
    Update an existing UPC (upc) for a given inventory item.

    Sends a PUT request to the Spire API to update the upc record with the specified
    item and upc ID using the provided `upc` data.

    Args:
        item_id (int): The ID of the inventory item.
        upc_id (int): The ID of the upc to update.
        upc_record (upc): A `upc` instance with updated field values.

    Returns:
        upc: The updated `upc` instance returned from the API.
    """
    response = self.client._put(f"/{self.endpoint}/{str(item_id)}/upcs/{str(upc_id)}", json=upc_record.model_dump(exclude_none=True, exclude_unset=True))
    return upc.from_json(response, self.client, item_id = item_id)

UpcClient

Source code in src/spyre/inventory.py
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
class UpcClient():

    def __init__(self, client : SpireClient):
        self.endpoint = 'inventory/upcs'
        self.client = client

    def get_upc(self, upc_id : int) -> "upc":
        """
        Retrieve a specific UPC (upc) for given id.

        This method sends a GET request to the Spire API to fetch a single upc record
        associated with the upc ID. The response is wrapped
        into a `upc` object that maintains a reference to the API client.

        Args:
            upc_id (int): The unique ID of the upc to retrieve.

        Returns:
            upc: A `upc` object representing the retrieved unit of measure.

        """
        response = self.client._get(f"/{self.endpoint}/{str(upc_id)}")
        return upc.from_json(response, self.client)

    def create_item_upc(self, upc : UPC) -> "upc":
        """
        Create a new UPC (upc) for a given id.

        Sends a POST request to the Spire API to create a new upc.
        If successful, the method retrieves and returns the newly
        created upc object. If the creation fails, an exception is raised.
        For a successful creation, either the whse and the partNo or the inventory
        field has to be filled in

        Args:
            upc (UPC): A Pydantic model instance representing the upc to create.

        Returns:
            upc (upc): A list containing the created `upc` object.

        Raises:
            CreateRequestError: If the API response status is not 201 (Created).
        """
        response =  self.client._post(f"/{self.endpoint}/{str(id)}", json=upc.model_dump(exclude_unset=True, exclude_none=True))
        if response.get('status_code') == 201:
            location = response.get('headers').get('location')
            parsed_url = urlparse(location)
            path_segments = parsed_url.path.rstrip("/").split("/")
            new_upc_id = path_segments[-1]
            return self.get_upc(upc_id = new_upc_id)
        else:
            error_message = response.get('content')
            raise CreateRequestError(self.endpoint, status_code=response.get('status_code'), error_message=error_message)

    def delete_upc(self, upc_id :int) -> bool:
        """
        Delete a UPC.

        Sends a DELETE request to the Spire API to remove a upc associated with the
        given upc ID.

        Args:
            upc_id (int): The ID of the Unit of Measure to delete.

        Returns:
            bool: True if the deletion was successful, otherwise raises an error.
        """
        return self.client._delete(f"/{self.endpoint}/{str(upc_id)}")

    def update_item_upc(self, upc_id : int, upc_record :'upc') -> 'upc':
        """
        Update an existing UPC.

        Sends a PUT request to the Spire API to update the upc record with the specified
        upc ID using the provided `upc` data.

        Args:
            upc_id (int): The ID of the upc to update.
            upc_record (upc): A `upc` instance with updated field values.

        Returns:
            upc: The updated `upc` instance returned from the API.
        """
        response = self.client._put(f"/{self.endpoint}/{str(upc_id)}", json=upc_record.model_dump(exclude_none=True, exclude_unset=True))
        return upc.from_json(response, self.client)

create_item_upc(upc)

Create a new UPC (upc) for a given id.

Sends a POST request to the Spire API to create a new upc. If successful, the method retrieves and returns the newly created upc object. If the creation fails, an exception is raised. For a successful creation, either the whse and the partNo or the inventory field has to be filled in

Parameters:

Name Type Description Default
upc UPC

A Pydantic model instance representing the upc to create.

required

Returns:

Name Type Description
upc upc

A list containing the created upc object.

Raises:

Type Description
CreateRequestError

If the API response status is not 201 (Created).

Source code in src/spyre/inventory.py
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
def create_item_upc(self, upc : UPC) -> "upc":
    """
    Create a new UPC (upc) for a given id.

    Sends a POST request to the Spire API to create a new upc.
    If successful, the method retrieves and returns the newly
    created upc object. If the creation fails, an exception is raised.
    For a successful creation, either the whse and the partNo or the inventory
    field has to be filled in

    Args:
        upc (UPC): A Pydantic model instance representing the upc to create.

    Returns:
        upc (upc): A list containing the created `upc` object.

    Raises:
        CreateRequestError: If the API response status is not 201 (Created).
    """
    response =  self.client._post(f"/{self.endpoint}/{str(id)}", json=upc.model_dump(exclude_unset=True, exclude_none=True))
    if response.get('status_code') == 201:
        location = response.get('headers').get('location')
        parsed_url = urlparse(location)
        path_segments = parsed_url.path.rstrip("/").split("/")
        new_upc_id = path_segments[-1]
        return self.get_upc(upc_id = new_upc_id)
    else:
        error_message = response.get('content')
        raise CreateRequestError(self.endpoint, status_code=response.get('status_code'), error_message=error_message)

delete_upc(upc_id)

Delete a UPC.

Sends a DELETE request to the Spire API to remove a upc associated with the given upc ID.

Parameters:

Name Type Description Default
upc_id int

The ID of the Unit of Measure to delete.

required

Returns:

Name Type Description
bool bool

True if the deletion was successful, otherwise raises an error.

Source code in src/spyre/inventory.py
598
599
600
601
602
603
604
605
606
607
608
609
610
611
def delete_upc(self, upc_id :int) -> bool:
    """
    Delete a UPC.

    Sends a DELETE request to the Spire API to remove a upc associated with the
    given upc ID.

    Args:
        upc_id (int): The ID of the Unit of Measure to delete.

    Returns:
        bool: True if the deletion was successful, otherwise raises an error.
    """
    return self.client._delete(f"/{self.endpoint}/{str(upc_id)}")

get_upc(upc_id)

Retrieve a specific UPC (upc) for given id.

This method sends a GET request to the Spire API to fetch a single upc record associated with the upc ID. The response is wrapped into a upc object that maintains a reference to the API client.

Parameters:

Name Type Description Default
upc_id int

The unique ID of the upc to retrieve.

required

Returns:

Name Type Description
upc upc

A upc object representing the retrieved unit of measure.

Source code in src/spyre/inventory.py
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
def get_upc(self, upc_id : int) -> "upc":
    """
    Retrieve a specific UPC (upc) for given id.

    This method sends a GET request to the Spire API to fetch a single upc record
    associated with the upc ID. The response is wrapped
    into a `upc` object that maintains a reference to the API client.

    Args:
        upc_id (int): The unique ID of the upc to retrieve.

    Returns:
        upc: A `upc` object representing the retrieved unit of measure.

    """
    response = self.client._get(f"/{self.endpoint}/{str(upc_id)}")
    return upc.from_json(response, self.client)

update_item_upc(upc_id, upc_record)

Update an existing UPC.

Sends a PUT request to the Spire API to update the upc record with the specified upc ID using the provided upc data.

Parameters:

Name Type Description Default
upc_id int

The ID of the upc to update.

required
upc_record upc

A upc instance with updated field values.

required

Returns:

Name Type Description
upc upc

The updated upc instance returned from the API.

Source code in src/spyre/inventory.py
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
def update_item_upc(self, upc_id : int, upc_record :'upc') -> 'upc':
    """
    Update an existing UPC.

    Sends a PUT request to the Spire API to update the upc record with the specified
    upc ID using the provided `upc` data.

    Args:
        upc_id (int): The ID of the upc to update.
        upc_record (upc): A `upc` instance with updated field values.

    Returns:
        upc: The updated `upc` instance returned from the API.
    """
    response = self.client._put(f"/{self.endpoint}/{str(upc_id)}", json=upc_record.model_dump(exclude_none=True, exclude_unset=True))
    return upc.from_json(response, self.client)

item

Bases: APIResource[InventoryItem]

Source code in src/spyre/inventory.py
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
class item(APIResource[InventoryItem]):

    endpoint =  'inventory/items'
    Model = InventoryItem

    def delete(self) -> bool:
        """
        Cancels or deletes the item.

        Sends a DELETE request to the API to remove the inventory item with the current ID.

        Returns:
            bool: True if the order was successfully deleted (HTTP 204 or 200), False otherwise.
        """

        return self._client._delete(f"/{self.endpoint}/{str(self.id)}")

    def update(self, inventory_item: "item" = None) -> 'item':
        """
        Update the inventory item.

        If no item object is provided, updates the current instance on the server.
        If an item object is provided, updates the item using the given data.

        Args:
            inventory_item (item, optional): An optional item instance to use for the update.

        Returns:
            item: The updated item object reflecting the new status.
        """
        data = inventory_item.model_dump(exclude_unset=True, exclude_none=True) if inventory_item else self.model_dump(exclude_unset=True, exclude_none=True)
        response = self._client._put(f"/{self.endpoint}/{str(self.id)}", json=data)
        return item.from_json(response, self._client)    

    def get_uoms(self) -> List["uom"]:
        """
        Retrieve all Unit of Measure (UOM) records for the current inventory item.

        This method sends a GET request to the Spire API and returns all UOMs
        associated with this item's ID.

        Returns:
            List[uom]: A list of `uom` instances representing the available units of measure.
        """       
        uoms = []
        response = self._client._get(f"{self.endpoint}/{self.id}/uoms")
        items = response.get('records')
        for item in items:
            uoms.append(uom.from_json(json_data=item, client = self._client, item_id = self.id))

        return uoms

    def get_upcs(self) -> List["upc"]:
        """
        Retrieve all UPC records for the current inventory item.

        This method sends a GET request to the Spire API and returns all UPCs
        associated with this item's ID.

        Returns:
            List[upc]: A list of `upc` instances representing the available units of measure.
        """     
        upcs = []
        response = self._client._get(f"{self.endpoint}/{self.id}/upcs")
        items = response.get('records')
        for item in items:
            upcs.append(upc.from_json(json_data=item, client = self._client, item_id = id))

        return upcs

    def add_uom(self, uom_record : UnitOfMeasure) -> "uom":
        """
        Add a new Unit of Measure (UOM) to the current inventory item.

        Sends a POST request to the Spire API to create a new UOM record using the provided
        `UnitOfMeasure` model. If the creation is successful (HTTP 201), it retrieves
        and returns the created UOM.

        Args:
            uom_record (UnitOfMeasure): The UnitOfMeasure Pydantic model to be created.

        Returns:
            uom (uom): The newly created Unit of measure as a `uom` instance.

        Raises:
            CreateRequestError: If the API returns a non-201 status code during creation.
        """
        response =  self._client._post(f"/{self.endpoint}/{str(self.id)}/uoms", json=uom_record.model_dump(exclude_unset=True, exclude_none=True))
        if response.get('status_code') == 201:
            location = response.get('headers').get('location')
            parsed_url = urlparse(location)
            path_segments = parsed_url.path.rstrip("/").split("/")
            id = path_segments[-1]
            return InventoryClient(self._client).items.get_uom(id)
        else:
            error_message = response.get('content')
            raise CreateRequestError(self.endpoint, status_code=response.get('status_code'), error_message=error_message)

    def add_upc(self, upc_record : UPC) -> "upc":
        """
        Add a new UPC to the current inventory item.

        Sends a POST request to the Spire API to create a new UPC record using the provided
        UPC model. If the creation is successful (HTTP 201), it retrieves
        and returns the created UPC.

        Args:
            upc_record (UPC): The UPC Pydantic model to be created.

        Returns:
            upc (upc): The newly created UPC as a `upc` instance.

        Raises:
            CreateRequestError: If the API returns a non-201 status code during creation.
        """
        response =  self._client._post(f"/{self.endpoint}/{str(self.id)}/upcs", json=upc_record.model_dump(exclude_unset=True, exclude_none=True))
        if response.get('status_code') == 201:
            location = response.get('headers').get('location')
            parsed_url = urlparse(location)
            path_segments = parsed_url.path.rstrip("/").split("/")
            id = path_segments[-1]
            return InventoryClient(self._client).items.get_upc(id)
        else:
            error_message = response.get('content')
            raise CreateRequestError(self.endpoint, status_code=response.get('status_code'), error_message=error_message)

add_uom(uom_record)

Add a new Unit of Measure (UOM) to the current inventory item.

Sends a POST request to the Spire API to create a new UOM record using the provided UnitOfMeasure model. If the creation is successful (HTTP 201), it retrieves and returns the created UOM.

Parameters:

Name Type Description Default
uom_record UnitOfMeasure

The UnitOfMeasure Pydantic model to be created.

required

Returns:

Name Type Description
uom uom

The newly created Unit of measure as a uom instance.

Raises:

Type Description
CreateRequestError

If the API returns a non-201 status code during creation.

Source code in src/spyre/inventory.py
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
def add_uom(self, uom_record : UnitOfMeasure) -> "uom":
    """
    Add a new Unit of Measure (UOM) to the current inventory item.

    Sends a POST request to the Spire API to create a new UOM record using the provided
    `UnitOfMeasure` model. If the creation is successful (HTTP 201), it retrieves
    and returns the created UOM.

    Args:
        uom_record (UnitOfMeasure): The UnitOfMeasure Pydantic model to be created.

    Returns:
        uom (uom): The newly created Unit of measure as a `uom` instance.

    Raises:
        CreateRequestError: If the API returns a non-201 status code during creation.
    """
    response =  self._client._post(f"/{self.endpoint}/{str(self.id)}/uoms", json=uom_record.model_dump(exclude_unset=True, exclude_none=True))
    if response.get('status_code') == 201:
        location = response.get('headers').get('location')
        parsed_url = urlparse(location)
        path_segments = parsed_url.path.rstrip("/").split("/")
        id = path_segments[-1]
        return InventoryClient(self._client).items.get_uom(id)
    else:
        error_message = response.get('content')
        raise CreateRequestError(self.endpoint, status_code=response.get('status_code'), error_message=error_message)

add_upc(upc_record)

Add a new UPC to the current inventory item.

Sends a POST request to the Spire API to create a new UPC record using the provided UPC model. If the creation is successful (HTTP 201), it retrieves and returns the created UPC.

Parameters:

Name Type Description Default
upc_record UPC

The UPC Pydantic model to be created.

required

Returns:

Name Type Description
upc upc

The newly created UPC as a upc instance.

Raises:

Type Description
CreateRequestError

If the API returns a non-201 status code during creation.

Source code in src/spyre/inventory.py
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
def add_upc(self, upc_record : UPC) -> "upc":
    """
    Add a new UPC to the current inventory item.

    Sends a POST request to the Spire API to create a new UPC record using the provided
    UPC model. If the creation is successful (HTTP 201), it retrieves
    and returns the created UPC.

    Args:
        upc_record (UPC): The UPC Pydantic model to be created.

    Returns:
        upc (upc): The newly created UPC as a `upc` instance.

    Raises:
        CreateRequestError: If the API returns a non-201 status code during creation.
    """
    response =  self._client._post(f"/{self.endpoint}/{str(self.id)}/upcs", json=upc_record.model_dump(exclude_unset=True, exclude_none=True))
    if response.get('status_code') == 201:
        location = response.get('headers').get('location')
        parsed_url = urlparse(location)
        path_segments = parsed_url.path.rstrip("/").split("/")
        id = path_segments[-1]
        return InventoryClient(self._client).items.get_upc(id)
    else:
        error_message = response.get('content')
        raise CreateRequestError(self.endpoint, status_code=response.get('status_code'), error_message=error_message)

delete()

Cancels or deletes the item.

Sends a DELETE request to the API to remove the inventory item with the current ID.

Returns:

Name Type Description
bool bool

True if the order was successfully deleted (HTTP 204 or 200), False otherwise.

Source code in src/spyre/inventory.py
381
382
383
384
385
386
387
388
389
390
391
def delete(self) -> bool:
    """
    Cancels or deletes the item.

    Sends a DELETE request to the API to remove the inventory item with the current ID.

    Returns:
        bool: True if the order was successfully deleted (HTTP 204 or 200), False otherwise.
    """

    return self._client._delete(f"/{self.endpoint}/{str(self.id)}")

get_uoms()

Retrieve all Unit of Measure (UOM) records for the current inventory item.

This method sends a GET request to the Spire API and returns all UOMs associated with this item's ID.

Returns:

Type Description
List[uom]

List[uom]: A list of uom instances representing the available units of measure.

Source code in src/spyre/inventory.py
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
def get_uoms(self) -> List["uom"]:
    """
    Retrieve all Unit of Measure (UOM) records for the current inventory item.

    This method sends a GET request to the Spire API and returns all UOMs
    associated with this item's ID.

    Returns:
        List[uom]: A list of `uom` instances representing the available units of measure.
    """       
    uoms = []
    response = self._client._get(f"{self.endpoint}/{self.id}/uoms")
    items = response.get('records')
    for item in items:
        uoms.append(uom.from_json(json_data=item, client = self._client, item_id = self.id))

    return uoms

get_upcs()

Retrieve all UPC records for the current inventory item.

This method sends a GET request to the Spire API and returns all UPCs associated with this item's ID.

Returns:

Type Description
List[upc]

List[upc]: A list of upc instances representing the available units of measure.

Source code in src/spyre/inventory.py
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
def get_upcs(self) -> List["upc"]:
    """
    Retrieve all UPC records for the current inventory item.

    This method sends a GET request to the Spire API and returns all UPCs
    associated with this item's ID.

    Returns:
        List[upc]: A list of `upc` instances representing the available units of measure.
    """     
    upcs = []
    response = self._client._get(f"{self.endpoint}/{self.id}/upcs")
    items = response.get('records')
    for item in items:
        upcs.append(upc.from_json(json_data=item, client = self._client, item_id = id))

    return upcs

update(inventory_item=None)

Update the inventory item.

If no item object is provided, updates the current instance on the server. If an item object is provided, updates the item using the given data.

Parameters:

Name Type Description Default
inventory_item item

An optional item instance to use for the update.

None

Returns:

Name Type Description
item item

The updated item object reflecting the new status.

Source code in src/spyre/inventory.py
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
def update(self, inventory_item: "item" = None) -> 'item':
    """
    Update the inventory item.

    If no item object is provided, updates the current instance on the server.
    If an item object is provided, updates the item using the given data.

    Args:
        inventory_item (item, optional): An optional item instance to use for the update.

    Returns:
        item: The updated item object reflecting the new status.
    """
    data = inventory_item.model_dump(exclude_unset=True, exclude_none=True) if inventory_item else self.model_dump(exclude_unset=True, exclude_none=True)
    response = self._client._put(f"/{self.endpoint}/{str(self.id)}", json=data)
    return item.from_json(response, self._client)    

uom

Bases: APIResource[UnitOfMeasure]

Source code in src/spyre/inventory.py
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
class uom(APIResource[UnitOfMeasure]):
    Model = UnitOfMeasure
    _endpoint = ''  # Will be dynamically set in __init__


    def __init__(self, model, client, item_id=None):
        if item_id is None:
            raise ValueError("item_id must be provided")
        super().__init__(model, client)
        uom_id = model.id
        self._endpoint = f'inventory/items/{item_id}/uoms/{str(uom_id)}'
        self._item_id = item_id

    def delete(self) -> bool:
        """
        Cancels or deletes the uom.

        Sends a DELETE request to the API to remove the uom with the current ID.

        Returns:
            bool: True if the uom was successfully deleted (HTTP 204 or 200), False otherwise.
        """

        return self._client._delete(f"/{self._endpoint}")

    def update(self, _uom: "uom" = None) -> 'uom':
        """
        Update the uom.

        If no uom object is provided, updates the current instance on the server.
        If an uom object is provided, updates the item using the given data.

        Args:
            _uom (uom, optional): An optional uom instance to use for the update.

        Returns:
            uom: The updated uom object reflecting the new status.
        """
        data = _uom.model_dump(exclude_unset=True, exclude_none=True) if _uom else self.model_dump(exclude_unset=True, exclude_none=True)
        response = self._client._put(f"/{self._endpoint}", json=data)
        return uom.from_json(response, self._client, item_id = self._item_id)    

delete()

Cancels or deletes the uom.

Sends a DELETE request to the API to remove the uom with the current ID.

Returns:

Name Type Description
bool bool

True if the uom was successfully deleted (HTTP 204 or 200), False otherwise.

Source code in src/spyre/inventory.py
515
516
517
518
519
520
521
522
523
524
525
def delete(self) -> bool:
    """
    Cancels or deletes the uom.

    Sends a DELETE request to the API to remove the uom with the current ID.

    Returns:
        bool: True if the uom was successfully deleted (HTTP 204 or 200), False otherwise.
    """

    return self._client._delete(f"/{self._endpoint}")

update(_uom=None)

Update the uom.

If no uom object is provided, updates the current instance on the server. If an uom object is provided, updates the item using the given data.

Parameters:

Name Type Description Default
_uom uom

An optional uom instance to use for the update.

None

Returns:

Name Type Description
uom uom

The updated uom object reflecting the new status.

Source code in src/spyre/inventory.py
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
def update(self, _uom: "uom" = None) -> 'uom':
    """
    Update the uom.

    If no uom object is provided, updates the current instance on the server.
    If an uom object is provided, updates the item using the given data.

    Args:
        _uom (uom, optional): An optional uom instance to use for the update.

    Returns:
        uom: The updated uom object reflecting the new status.
    """
    data = _uom.model_dump(exclude_unset=True, exclude_none=True) if _uom else self.model_dump(exclude_unset=True, exclude_none=True)
    response = self._client._put(f"/{self._endpoint}", json=data)
    return uom.from_json(response, self._client, item_id = self._item_id)    

upc

Bases: APIResource[UPC]

Source code in src/spyre/inventory.py
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
class upc(APIResource[UPC]):
    _endpoint = ''         
    Model = UPC

    def __init__(self, model, client, item_id=None):

        super().__init__(model, client)
        upc_id = model.id
        if item_id is None:
            self._endpoint = f'inventory/upcs/{str(upc_id)}'
        else:
            self._endpoint = f'inventory/items/{item_id}/upcs/{str(upc_id)}'
        self._item_id = item_id

    def delete(self) -> bool:
        """
        Cancels or deletes the upc.

        Sends a DELETE request to the API to remove the upc with the current ID.

        Returns:
            bool: True if the upc was successfully deleted (HTTP 204 or 200), False otherwise.
        """

        return self._client._delete(f"/{self._endpoint}")

    def update(self, _upc: "upc" = None) -> 'upc':
        """
        Update the upc.

        If no upc object is provided, updates the current instance on the server.
        If an upc object is provided, updates the item using the given data.

        Args:
            _upc (upc, optional): An optional upc instance to use for the update.

        Returns:
            upc: The updated upc object reflecting the new status.
        """
        data = _upc.model_dump(exclude_unset=True, exclude_none=True) if _upc else self.model_dump(exclude_unset=True, exclude_none=True)
        response = self._client._put(f"/{self._endpoint}", json=data)
        return upc.from_json(response, self._client, item_id = self._item_id)    

delete()

Cancels or deletes the upc.

Sends a DELETE request to the API to remove the upc with the current ID.

Returns:

Name Type Description
bool bool

True if the upc was successfully deleted (HTTP 204 or 200), False otherwise.

Source code in src/spyre/inventory.py
644
645
646
647
648
649
650
651
652
653
654
def delete(self) -> bool:
    """
    Cancels or deletes the upc.

    Sends a DELETE request to the API to remove the upc with the current ID.

    Returns:
        bool: True if the upc was successfully deleted (HTTP 204 or 200), False otherwise.
    """

    return self._client._delete(f"/{self._endpoint}")

update(_upc=None)

Update the upc.

If no upc object is provided, updates the current instance on the server. If an upc object is provided, updates the item using the given data.

Parameters:

Name Type Description Default
_upc upc

An optional upc instance to use for the update.

None

Returns:

Name Type Description
upc upc

The updated upc object reflecting the new status.

Source code in src/spyre/inventory.py
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
def update(self, _upc: "upc" = None) -> 'upc':
    """
    Update the upc.

    If no upc object is provided, updates the current instance on the server.
    If an upc object is provided, updates the item using the given data.

    Args:
        _upc (upc, optional): An optional upc instance to use for the update.

    Returns:
        upc: The updated upc object reflecting the new status.
    """
    data = _upc.model_dump(exclude_unset=True, exclude_none=True) if _upc else self.model_dump(exclude_unset=True, exclude_none=True)
    response = self._client._put(f"/{self._endpoint}", json=data)
    return upc.from_json(response, self._client, item_id = self._item_id)