Skip to main content

Unofficial MachShip SDK built with httpx and Pydantic

Project description

machship-sdk

Unofficial Python SDK for MachShip integrations

Unofficial Python 3.13+ pip install Community maintained

Unofficial notice This project is a community-maintained SDK. It is not affiliated with, endorsed by, or supported by MachShip.

MachShip SDK for Python, with dedicated FusedShip support for live pricing, ecommerce session tokens, and the direct MachShip API surface when you still need it.

What this includes

  • FusedShipClient for live pricing and ecommerce flows.
  • MachShipClient for the direct MachShip API surface.
  • Sync and async clients.
  • Typed Pydantic request and response models.

When to use which client

  • Use FusedShipClient for live pricing and ecommerce UI access.
  • Use MachShipClient if you still need the direct MachShip API surface.

Install

pip install machship-sdk

If you want to install from git:

pip install "machship-sdk @ git+ssh://git@github.com/<org>/machship-sdk.git@v0.1.0"

Optional Extras

Install the full feature set:

pip install "machship-sdk[all]"

Install only the pieces you need:

pip install "machship-sdk[settings]"
pip install "machship-sdk[retries]"
pip install "machship-sdk[logging]"
pip install "machship-sdk[telemetry]"
pip install "machship-sdk[cache]"
pip install "machship-sdk[json]"
pip install "machship-sdk[testing]"

Use cases:

  • settings adds pydantic-settings for app-level env loading in Django, FastAPI, CLI tools, or workers.
  • retries adds tenacity for transient request retries and backoff on 429/5xx responses.
  • logging adds structlog for structured request logs.
  • telemetry adds OpenTelemetry tracing support for outbound API calls.
  • cache adds cachetools for TTL caches around carrier, company, or rate lookups.
  • json adds orjson for faster JSON encoding and decoding.
  • testing adds respx for HTTPX request mocking in tests.

Environment

The clients can read their configuration from environment variables through from_env().

MachShip:

  • MACHSHIP_BASE_URL
  • MACHSHIP_TOKEN or MACHSHIP_API_TOKEN

FusedShip:

  • FUSEDSHIP_BASE_URL
  • FUSEDSHIP_TOKEN
  • FUSEDSHIP_INTEGRATION_ID
  • FUSEDSHIP_CLIENT_TOKEN
  • FUSEDSHIP_STORE_ID

App Settings

If you want a single settings object for a Django app or plain Python service, use MachShipSDKSettings from machship_sdk.settings:

from machship_sdk import MachShipClient
from machship_sdk.settings import MachShipSDKSettings

app_settings = MachShipSDKSettings(_env_file=".env")

machship_client = MachShipClient(app_settings.to_machship_config())
fusedship_config = app_settings.to_fusedship_config()

Usage

MachShip

from machship_sdk import MachShipClient

client = MachShipClient.from_env()

Enhancements

from machship_sdk.cache import ttl_cache
from machship_sdk.logging import get_logger
from machship_sdk.retries import RetryPolicy
from machship_sdk.telemetry import get_tracer

logger = get_logger()
tracer = get_tracer()

client = MachShipClient(
    machship_config,
    retry_policy=RetryPolicy(attempts=3),
    logger=logger,
    tracer=tracer,
)

@ttl_cache(maxsize=64, ttl=300)
def get_carriers():
    return client.get_available_carriers_accounts_and_services()

If you need HTTP mocking in tests, install machship-sdk[testing] and use respx:

import httpx
import respx

from machship_sdk import MachShipClient, MachShipConfig

client = MachShipClient(MachShipConfig(base_url="https://example.com", token="secret"))

with respx.mock(base_url="https://example.com") as mock:
    mock.post("/apiv2/authenticate/ping").respond(
        200,
        json={"object": True, "errors": []},
    )
    client.ping()

FusedShip live pricing

from machship_sdk.fusedship import (
    FusedShipAddress,
    FusedShipClient,
    FusedShipLivePricingRequest,
    FusedShipQuote,
    FusedShipQuoteItem,
    FusedShipShippingItem,
    FusedShipShippingOptions,
)

client = FusedShipClient.from_env()

request = FusedShipLivePricingRequest(
    quote=FusedShipQuote(
        warehouse=FusedShipAddress(
            country="AU",
            postal_code="3076",
            province="VIC",
            city="Epping",
            address1="123 main st",
            name="ABC123",
        ),
        shipping_address=FusedShipAddress(
            country="AU",
            postal_code="6720",
            province="WA",
            city="Wickham",
            address1="123 main st",
            name="ABC123",
        ),
        shipping_options=FusedShipShippingOptions(
            authority_to_leave=True,
            residential=False,
        ),
        items=[
            FusedShipQuoteItem(
                name="Banana Bottle 200ml",
                sku="BCE345",
                quantity=5,
                price=328,
                categories=["flavoured_drinks", "bottles"],
                shipping_items=[
                    FusedShipShippingItem(
                        weight=240,
                        length=100,
                        width=20,
                        height=10,
                        item_type="Carton",
                    )
                ],
            )
        ],
    )
)

response = client.quote_live_pricing("your_platform", request)

Ecommerce token

session = client.request_token(
    client_token="your_client_token_here",
    store_id="your_store_id_here",
)

iframe_url = client.build_ecommerce_url(session.session_key, active_tab="quote")

Django or plain Python

The SDK does not require Django. It only reads environment variables, so you can populate them in any application style:

  • .env file loaded at startup
  • shell environment variables
  • Docker or Kubernetes secrets
  • Django settings that proxy to os.environ

For HTTP mocking in tests, install machship-sdk[testing] and use respx to stub the outbound httpx calls cleanly.

Data mapping

FusedShip payloads in this package are modeled with snake_case fields so they match the example request and response format from the handbook. The models accept extra fields, which keeps the SDK flexible when FusedShip mappings evolve.

Generating Models

The MachShip model file is generated from macship_api_schema/macship_schema.json with datamodel-code-generator. Run this from the repository root:

uv run datamodel-codegen \
  --input macship_api_schema/macship_schema.json \
  --input-file-type openapi \
  --output src/machship_sdk/models/generated.py \
  --base-class machship_sdk.models.base.MachShipBaseModel \
  --custom-file-header-path macship_api_schema/generated_header.txt \
  --disable-timestamp \
  --use-annotated \
  --use-schema-description \
  --use-field-description \
  --use-inline-field-description \
  --snake-case-field \
  --extra-fields ignore \
  --target-pydantic-version 2.11 \
  --output-model-type pydantic_v2.BaseModel \
  --formatters black isort

The schema descriptions populate class and field docstrings where the OpenAPI spec provides them. The generated file is checked in, so it should be regenerated rather than edited by hand.

Publishing To PyPI

Recommended release flow:

  1. Bump version in pyproject.toml.
  2. Run uv run pytest.
  3. Run uv run python -m build.
  4. Run uv run twine check dist/*.
  5. Configure a PyPI trusted publisher for this repository:
    • Owner: Leggendario12
    • Repository: machship-sdk
    • Workflow file: .github/workflows/publish.yml
    • Environment: pypi
  6. Tag the release and push it:
git tag v0.1.1
git push origin v0.1.1

GitHub Actions will build the sdist and wheel, validate the metadata, and publish the release from .github/workflows/publish.yml.

License

This project is released under the MIT License. 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

machship_sdk-0.1.0.tar.gz (237.5 kB view details)

Uploaded Source

Built Distribution

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

machship_sdk-0.1.0-py3-none-any.whl (89.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: machship_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 237.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for machship_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 201711a8a764ae34ec08297c72e450e59793a6900681ab2d972c372a8c351052
MD5 dada5f94ae9e91fdd49004a4855e69ed
BLAKE2b-256 ee87c171f6afc934dbfeb5c3ef3c6b9297b39a055abc1645fd964aa5520492e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for machship_sdk-0.1.0.tar.gz:

Publisher: publish.yml on Leggendario12/machship-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: machship_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 89.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for machship_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f9b5282e11012dac0ba2a7870cc353e055efa839272e5ad287f829f155fa1a44
MD5 a3d83b7e4f762db4949164a1dab8fc73
BLAKE2b-256 6b654b3d545f7644a07e3b108b82405a5bd5936fd47486a343b134b3745fdd51

See more details on using hashes here.

Provenance

The following attestation bundles were made for machship_sdk-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Leggendario12/machship-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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