shipstation_sdk.client

Interacting with ShipStation.

Attributes

Classes

ShipStationClient

A class wrapping ShipStation API v2 interaction.

Functions

_retry_after_seconds(response) → float

Determine how long to sleep before retrying a rate-limited request.

Module Contents

shipstation_sdk.client.API_HOST = 'api.shipstation.com'[source]
shipstation_sdk.client.RETRY_ATTEMPTS = 3[source]
shipstation_sdk.client.DEFAULT_RETRY_AFTER_SECONDS = 5.0[source]
shipstation_sdk.client.MAX_RETRY_AFTER_SECONDS = 60.0[source]
shipstation_sdk.client._retry_after_seconds(response: niquests.Response) → float[source]

Determine how long to sleep before retrying a rate-limited request.

Parameters:

response – The 429 response, whose Retry-After header is honored in either RFC 9110 form – delta-seconds or an HTTP-date – capped at MAX_RETRY_AFTER_SECONDS.

class shipstation_sdk.client.ShipStationClient(api_key: str, base_url: str = 'https://api.shipstation.com', timeout: float = 60.0)[source]

A class wrapping ShipStation API v2 interaction.

session[source]
make_request(method: str, path: str, params: dict[str, Any] | None = None, json: dict[str, Any] | None = None) → niquests.Response[source]

Make a request to ShipStation, retrying when rate-limited.

Retries up to RETRY_ATTEMPTS total attempts on HTTP 429, sleeping the response’s Retry-After (DEFAULT_RETRY_AFTER_SECONDS when absent).

list_shipments(parameters: shipstation_sdk.parameters.ShipmentListParameters | None = None) → shipstation_sdk.models.ShipmentsList[source]

Get a page of shipments.

iter_shipments(parameters: shipstation_sdk.parameters.ShipmentListParameters | None = None) → collections.abc.Iterator[shipstation_sdk.models.Shipment][source]

Iterate over every shipment matching the parameters, following pagination.

get_shipment(shipment_id: str) → shipstation_sdk.models.Shipment[source]

Get a specific shipment.

get_shipment_by_external_id(external_shipment_id: str) → shipstation_sdk.models.Shipment[source]

Get a specific shipment by the external shipment ID it was created with.

External shipment IDs are caller-defined and may contain URL metacharacters (e.g. marketplace IDs like gid://...), so the path segment is escaped.

list_carriers() → shipstation_sdk.models.CarriersList[source]

Get the connected carrier accounts.

list_tags() → shipstation_sdk.models.TagsList[source]

Get the tags defined on the account.

create_shipments(shipments: list[shipstation_sdk.models.ShipmentRequest]) → shipstation_sdk.models.CreateShipmentsResponse[source]

Create shipments; each comes back with its id, or with the errors that stopped it.

A shipment ShipStation refuses does not fail the call: check has_errors and each shipment’s errors.

update_shipment(shipment_id: str, shipment: shipstation_sdk.models.ShipmentRequest) → shipstation_sdk.models.Shipment[source]

Update a shipment that has no label yet; fields left None are left as they are.

list_labels(parameters: shipstation_sdk.parameters.LabelListParameters | None = None) → shipstation_sdk.models.LabelsList[source]

Get a page of labels.

iter_labels(parameters: shipstation_sdk.parameters.LabelListParameters | None = None) → collections.abc.Iterator[shipstation_sdk.models.Label][source]

Iterate over every label matching the parameters, following pagination.

iter_labels_at(resource_url: str) → collections.abc.Iterator[shipstation_sdk.models.Label][source]

Iterate over the labels a label_created_v2 webhook’s resource_url names.

The URL is https://api.shipstation.com/v2/labels?batch_id=.... Its query becomes list parameters, so the request goes to this client’s own host with its own key: a URL naming any other host or path is refused rather than sent the key.

Raises:

ValueError – If the URL is not a labels list on ShipStation’s API host.

list_webhooks() → list[shipstation_sdk.models.Webhook][source]

Get the account’s webhook subscriptions.

create_webhook(*, name: str, event: str, url: str, headers: list[shipstation_sdk.models.WebhookHeader] | None = None, store_id: str | None = None) → shipstation_sdk.models.Webhook[source]

Subscribe url to event (such as label_created_v2).

headers are sent with every call, which is how a listener tells ShipStation’s calls from anyone else’s.

start_tracking(carrier_code: str, tracking_number: str, *, carrier_id: str | None = None) → None[source]

Subscribe to a package’s tracking updates, which then arrive through track webhooks.

carrier_id names which of the account’s connections to the carrier to track with.

stop_tracking(carrier_code: str, tracking_number: str) → None[source]

Unsubscribe from a package’s tracking updates.

get_tracking(carrier_code: str, tracking_number: str, *, carrier_id: str | None = None) → shipstation_sdk.models.TrackingInfo[source]

Get a package’s tracking status and events.

carrier_id names which of the account’s connections to the carrier to ask.