Unofficial MachShip SDK built with httpx and Pydantic
Project description
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
FusedShipClientfor live pricing and ecommerce flows.MachShipClientfor the direct MachShip API surface.- Sync and async clients.
- Typed Pydantic request and response models.
When to use which client
- Use
FusedShipClientfor live pricing and ecommerce UI access. - Use
MachShipClientif 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.6"
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:
settingsaddspydantic-settingsfor app-level env loading in Django, FastAPI, CLI tools, or workers.retriesaddstenacityfor transient request retries and backoff on 429/5xx responses.loggingaddsstructlogfor structured request logs.telemetryadds OpenTelemetry tracing support for outbound API calls.cacheaddscachetoolsfor TTL caches around carrier, company, or rate lookups.jsonaddsorjsonfor faster JSON encoding and decoding.testingaddsrespxfor HTTPX request mocking in tests.
Environment
The clients can read their configuration from environment variables through
from_env().
MachShip:
MACHSHIP_BASE_URLMACHSHIP_TOKENorMACHSHIP_API_TOKEN
FusedShip:
FUSEDSHIP_BASE_URLFUSEDSHIP_TOKENFUSEDSHIP_INTEGRATION_IDFUSEDSHIP_CLIENT_TOKENFUSEDSHIP_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()
Location Lookup
MachShip exposes suburb and postcode lookup endpoints rather than a full street-address verifier. You can use them to match raw locations or search by suburb/postcode text:
from machship_sdk import MachShipClient
from machship_sdk.models import (
LocationSearchOptions,
LocationSearchOptionsV2,
RawLocation,
RawLocationsWithLocationSearchOptions,
)
client = MachShipClient.from_env()
verified_locations = client.return_locations(
RawLocationsWithLocationSearchOptions(
raw_locations=[RawLocation(suburb="Melbourne", postcode="3000")],
location_search_options=LocationSearchOptions(company_id=123),
)
)
search_results = client.return_locations_with_search_options(
LocationSearchOptionsV2(company_id=123, retrieval_size=10),
search="Mel 3000",
)
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:
.envfile 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:
- Bump
versioninpyproject.toml. - Run
uv run pytest. - Run
uv run python -m build. - Run
uv run twine check dist/*. - Configure a PyPI trusted publisher for this repository:
- Owner:
Leggendario12 - Repository:
machship-sdk - Workflow file:
.github/workflows/publish.yml - Environment:
pypi
- Owner:
- Tag the release and push it:
git tag v0.1.6
git push origin v0.1.6
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file machship_sdk-0.1.7.tar.gz.
File metadata
- Download URL: machship_sdk-0.1.7.tar.gz
- Upload date:
- Size: 269.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69f66578f8de39211524fee95a1b32234dbf3dd43a7d445c5ad6618eb4406d45
|
|
| MD5 |
758b6d0a0f317d1eac3c24da1e3d54a2
|
|
| BLAKE2b-256 |
997ff5418bd5677d17a468cd0d44dc03cd2179cf6f2b7243a1b870e00d1d2dac
|
Provenance
The following attestation bundles were made for machship_sdk-0.1.7.tar.gz:
Publisher:
publish.yml on Leggendario12/machship-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
machship_sdk-0.1.7.tar.gz -
Subject digest:
69f66578f8de39211524fee95a1b32234dbf3dd43a7d445c5ad6618eb4406d45 - Sigstore transparency entry: 1237676351
- Sigstore integration time:
-
Permalink:
Leggendario12/machship-sdk@3763ec19fb350455e68b0b1c870c8ca7613efa45 -
Branch / Tag:
refs/tags/v0.1.7 - Owner: https://github.com/Leggendario12
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3763ec19fb350455e68b0b1c870c8ca7613efa45 -
Trigger Event:
push
-
Statement type:
File details
Details for the file machship_sdk-0.1.7-py3-none-any.whl.
File metadata
- Download URL: machship_sdk-0.1.7-py3-none-any.whl
- Upload date:
- Size: 90.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ebf26727a9118ba9c34039ca378884a1d97067f2a8559ee06236c4b44c74816
|
|
| MD5 |
3b0787083c3c547882c17206552fd1f6
|
|
| BLAKE2b-256 |
06b49ec68376825b5082c0e869452128bd29f79938ae68105f11f22efbaf5517
|
Provenance
The following attestation bundles were made for machship_sdk-0.1.7-py3-none-any.whl:
Publisher:
publish.yml on Leggendario12/machship-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
machship_sdk-0.1.7-py3-none-any.whl -
Subject digest:
1ebf26727a9118ba9c34039ca378884a1d97067f2a8559ee06236c4b44c74816 - Sigstore transparency entry: 1237676398
- Sigstore integration time:
-
Permalink:
Leggendario12/machship-sdk@3763ec19fb350455e68b0b1c870c8ca7613efa45 -
Branch / Tag:
refs/tags/v0.1.7 - Owner: https://github.com/Leggendario12
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3763ec19fb350455e68b0b1c870c8ca7613efa45 -
Trigger Event:
push
-
Statement type: