Skip to main content

A Python client for the Shippingbo API.

Project description

shippingboapy

PyPI version Python versions License: MIT

An async Python SDK for the ShippingBo API.

shippingboapy is a faithful, low-level wrapper around the ShippingBo REST API. The SDK structure mirrors the actual API endpoints rather than introducing ergonomic abstractions that hide them — inspired by the design of the Stripe and Anthropic Python SDKs.

⚠️ Alpha: this SDK is in early development. The public API may change before v1.0.

Installation

pip install shippingboapy

Requirements

  • Python 3.10+

Usage

Initialization

If you already have an access token and refresh token:

from shippingboapy import Client

client = Client(
    access_token="your_access_token",
    refresh_token="your_refresh_token",
    app_id="your_app_id",
    api_version="your_api_version",
    client_id="your_client_id",
    client_secret="your_client_secret",
)

OAuth — first-time authentication

If you don't have tokens yet, use the OAuth flow with an authorization code:

from shippingboapy import Client

client = await Client.from_auth_code(
    auth_code="your_auth_code",
    app_id="your_app_id",
    api_version="your_api_version",
    client_id="your_client_id",
    client_secret="your_client_secret",
    redirect_uri="your_redirect_uri",
)

Context manager

async with Client(...) as client:
    products = await client.products.list()

Or with explicit cleanup:

client = Client(...)
try:
    products = await client.products.list()
finally:
    await client.close()

Configuration

client.set_config(
    timeout=30,
    max_retries=3,
    retry_backoff_factor=0.5,
    api_url="https://app.shippingbo.com",
)

Products

List products

products = await client.products.list()

With filters:

products = await client.products.list(
    limit=50,
    offset=0,
    is_pack=False,
    search=[("user-ref", "eq", "123456")],
    sort=[("updated_at": "asc")],
)

Get a product

product = await client.products.get(product_id=123)

Create a product

from shippingboapy import ProductCreate

product = await client.products.create(
    ProductCreate(
        user_ref="MY-REF-001",
        title="My Product",
        weight=500,
        width=200,
        length=300,
        height=100,
    )
)

Orders

List orders

orders = await client.orders.list(limit=50)

Get an order

order = await client.orders.get(order_id=456)

Create an order

from shippingboapy import OrderCreate, OrderItemCreate

order = await client.orders.create(
    OrderCreate(
        product_source= "product_src_str",
        source="source"
        title="Order Title"
        ...
    )
)

Token refresh

Token refresh is handled automatically on 401 responses. After any request, the current tokens are accessible on the client:

client.token.access_token
client.token.refresh_token

Persisting refreshed tokens

To persist tokens after an automatic refresh, register a callback at init:

async def save_tokens(access_token: str, refresh_token: str):
    # Persist to your database, file, or any storage
    await db.save(access_token=access_token, refresh_token=refresh_token)

client = Client(
    access_token="your_access_token",
    refresh_token="your_refresh_token",
    ...,
    on_token_refresh=save_tokens,
)

Token storage is intentionally left to the caller, the SDK does not persist tokens itself.


Error handling

The SDK raises typed exceptions for predictable failure modes:

ShippingboAPYException
├── AuthenticationError
│   ├── TokenExpiredError
│   └── TokenRefreshError
└── APIRequestError          # exposes .status_code and .message
    ├── BadRequestError      # 400
    ├── UnauthorizedError    # 401
    ├── ForbiddenError       # 403
    ├── NotFoundError        # 404
    ├── RateLimitError       # 429
    ├── ServerError          # 5xx
    └── UnexpectedError      # any other status
from shippingboapy import TokenRefreshError, ShippingBoAPIError

try:
    await client.products.get(product_id=123)
except TokenRefreshError:
    # Re-authenticate the user
    ...
except ShippingBoAPIError as e:
    print(e.status_code, e.message)

Available Resources

Resource Status
Products ✅ Available
Orders ✅ Available
Addresses ✅ Available
Address Labels ✅ Available
Order Tags ✅ Available
Order Documents ✅ Available
Stock Variations 🚧 Planned
Suppliers 🚧 Planned

Missing a resource? Contributions are welcome — see CONTRIBUTING.md.


License

MIT — see LICENSE.

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

shippingboapy-0.1.0.tar.gz (38.9 kB view details)

Uploaded Source

Built Distribution

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

shippingboapy-0.1.0-py3-none-any.whl (49.7 kB view details)

Uploaded Python 3

File details

Details for the file shippingboapy-0.1.0.tar.gz.

File metadata

  • Download URL: shippingboapy-0.1.0.tar.gz
  • Upload date:
  • Size: 38.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for shippingboapy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 690979a8cc2df8f496a86311193e503f6ad8047f56ab7f9d0ef1c4b37d7e61d0
MD5 979fc5a937f6910af11b278c54880cbb
BLAKE2b-256 a95f0fcdbf3596c01a5365e4f0284807c496daa12d24c2a67153035073a8f204

See more details on using hashes here.

File details

Details for the file shippingboapy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: shippingboapy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 49.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for shippingboapy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 55d9737054303428449f98a7b315a46a9772d49b71e9601ae484e61e0ccd95bf
MD5 f25fea1fca36a7cc7eeb19e20d7712af
BLAKE2b-256 0a3b72a45407a94854402a9bfeefd56f93fc3a3591956974059706e581c70a17

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