Skip to main content

Async Python wrapper for the ShipStation API

Project description

ShipStation Interaction / Automation

Type-Check Linting Code style: black Validation: Pydantic v2 Python 3.11.14 PyPI - Version PyPI - License

Async Python client for ShipStation v1 and v2 APIs with an emphasis on typing.

Install

pip

pip install AsyncShipStation

Manual

git clone git@github.com:sudoDeVinci/AsyncShipStation.git
cd AsyncShipStation
pip install -r requirements.txt

Quick Start

Create a connection, then pass it to the portal you want to use.

import asyncio

from AsyncShipStation import ShipStationClient, ShipmentPortal


async def main() -> None:
    connection = await ShipStationClient.configure(
        v2_key="your_v2_api_key",
        v1_key="your_v1_api_key",
        v1_secret="your_v1_secret",
    )

    async with ShipStationClient.scoped_client(connection=connection, version="v2"):
        status, shipments = await ShipmentPortal.list(
            connection,
            page_size=10,
            page=1,
        )
        print(status, shipments)


if __name__ == "__main__":
    asyncio.run(main())

Client Lifecycle

Use the async context manager

Use scoped_client() when you want the connection lifecycle handled for you.

import asyncio
import os

from dotenv import load_dotenv

from AsyncShipStation import ShipStationClient, ShipmentPortal

load_dotenv()
V2_API_KEY: str | None = os.getenv("SHIP_STATION_V2")
V1_API_KEY: str | None = os.getenv("SHIP_STATION_V1")
V1_SECRET: str | None = os.getenv("SHIP_STATION_SECRET")


async def main() -> None:
    connection = await ShipStationClient.configure(
        v2_key=V2_API_KEY or "",
        v1_key=V1_API_KEY,
        v1_secret=V1_SECRET,
    )

    async with ShipStationClient.scoped_client(connection=connection, version="v2"):
        status, shipments = await ShipmentPortal.list(connection, page_size=10, page=1)
        print(status, shipments)


if __name__ == "__main__":
    asyncio.run(main())

Start and close explicitly

Use start() and close() if you want to manage the lifecycle yourself.

import asyncio
import os

from dotenv import load_dotenv

from AsyncShipStation import ShipStationClient, ShipmentPortal

load_dotenv()
V2_API_KEY: str | None = os.getenv("SHIP_STATION_V2")
V1_API_KEY: str | None = os.getenv("SHIP_STATION_V1")
V1_SECRET: str | None = os.getenv("SHIP_STATION_SECRET")


async def main() -> None:
    connection = await ShipStationClient.configure(
        v2_key=V2_API_KEY or "",
        v1_key=V1_API_KEY,
        v1_secret=V1_SECRET,
    )

    await ShipStationClient.start(connection=connection, version="v2")
    try:
        status, shipments = await ShipmentPortal.list(connection, page_size=10, page=1)
        print(status, shipments)
    finally:
        await ShipStationClient.close(connection=connection, version="v2")


if __name__ == "__main__":
    asyncio.run(main())

Concurrent Requests

A single connection can be shared across concurrent requests.

import asyncio

from AsyncShipStation import (
    BatchPortal,
    LabelPortal,
    ShipmentPortal,
    ShipStationClient,
)


async def main() -> None:
    connection = await ShipStationClient.configure(
        v2_key="your_v2_api_key",
        v1_key="your_v1_api_key",
        v1_secret="your_v1_secret",
    )

    async with ShipStationClient.scoped_client(connection=connection, version="v2"):
        results = await asyncio.gather(
            ShipmentPortal.list(connection, page_size=10, page=1),
            BatchPortal.list(connection, page_size=10, page=1),
            LabelPortal.list(connection, page_size=10, page=1),
        )

    for status, data in results:
        if status in (200, 201, 207):
            print(f"Success :: {data}")
        else:
            print(f"Error :: {data}")


if __name__ == "__main__":
    asyncio.run(main())

Connection Lookup

If you need to retrieve a connection from the pool later, use connection.pool_key.

import asyncio

from AsyncShipStation import ShipStationClient, ShipmentPortal


async def main() -> None:
    connection = await ShipStationClient.configure(
        v2_key="your_v2_api_key",
        v1_key="your_v1_api_key",
        v1_secret="your_v1_secret",
    )

    async with ShipStationClient.scoped_client(
        connection_hash=connection.pool_key,
        version="v2",
    ) as scoped_connection:
        status, shipments = await ShipmentPortal.list(
            scoped_connection,
            page_size=10,
            page=1,
        )
        print(status, shipments)


if __name__ == "__main__":
    asyncio.run(main())

Rate Limiting

Accounts that send too many requests in quick succession will receive a 429 Too Many Requests response with a Retry-After header that tells you how long to wait.

ShipStation bulk operation endpoints count as a single request.

Endpoints

/batches
Process labels in bulk and receive labels and customs forms in bulk responses.

/carriers
Retrieve details about the carriers connected to your account, including carrier IDs, service IDs, advanced options, and package types.

/fulfillments
Manage fulfillments that represent completed shipments.

/inventory
Manage inventory, adjust quantities, and work with warehouses and locations.

/labels
Purchase and print shipping labels, create return labels, void labels, and retrieve label details.

/manifests
Retrieve and work with shipment manifests.

/rates (v2)
Calculate and estimate shipping rates across multiple carriers.

/shipments (v2)
Create, retrieve, and manage shipments.

/tags (v2)
Manage tags for organizing shipments and orders.

/warehouses (v2)
Retrieve warehouse information, including shipment origin addresses.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asyncshipstation-0.2.0.1.tar.gz (43.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asyncshipstation-0.2.0.1-py3-none-any.whl (64.9 kB view details)

Uploaded Python 3

File details

Details for the file asyncshipstation-0.2.0.1.tar.gz.

File metadata

  • Download URL: asyncshipstation-0.2.0.1.tar.gz
  • Upload date:
  • Size: 43.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for asyncshipstation-0.2.0.1.tar.gz
Algorithm Hash digest
SHA256 6becbc9fb18ffa0e718552b516e696687daf8ca49f37780494da4fdcb349250c
MD5 1dba9ce2c6a215757206ec950d487ff7
BLAKE2b-256 66402d621b9f3b7392e9ff7b40feeddb46252efdde7279d9d846a14f3778c3b9

See more details on using hashes here.

File details

Details for the file asyncshipstation-0.2.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for asyncshipstation-0.2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8dff370db407e6790cec5a513c99bf322e156278d729affa6f1f1076f646d311
MD5 19ae489e887339ac4768a912e8e43b69
BLAKE2b-256 e0f4bbdffae8a58feea9ba3c5e486f1961e8a7aef083b1c25ff6958d3036ff2f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page