Skip to main content

apc-hypaship

A small, typed Python client for the APC Overnight Hypaship booking platform API (v3).

It wraps the JSON endpoints of the Hypaship API with httpx and pydantic models, so you can build shipments as Python objects and get validated, typed responses back.

Supported operations:

Operation Client method Hypaship endpoint
Check service availability APCClient.fetch_service_available() POST ServiceAvailability.json
Book a shipment (order) APCClient.fetch_book_shipment() POST Orders.json
Retrieve a label APCClient.fetch_label() GET Orders/{order_number}.json
Track an order APCClient.fetch_tracks() GET Tracks/{order_number}.json

Amending and cancelling orders are not implemented yet.

The upstream API reference (APC API v3 Integration Guide, edition 3.1.2) is in docs/ref/APC_API_Integration_Guide_V3.1.2.pdf.


Installation

Requires Python 3.13+.

uv add apc-hypaship
# or
pip install apc-hypaship

Configuration

Credentials and the API base URL come from an env file, loaded by APCSettings (a pydantic-settings class).

# apc.env
APC_EMAIL=you@example.com
APC_PASSWORD=your-hypaship-password
BASE_URL=https://apc-training.hypaship.com/api/3.0/
Variable Description
APC_EMAIL Hypaship login email. Training and live use separate credentials.
APC_PASSWORD Hypaship login password.
BASE_URL API root URL. Must end with /, because endpoint paths are appended to it.
Environment BASE_URL Website
Training https://apc-training.hypaship.com/api/3.0/ https://apc-training.hypaship.com
Live https://apc.hypaship.com/api/3.0/ https://apc.hypaship.com

There are three ways to load settings:

from pathlib import Path
from apc_hypaship.config import APCSettings

# 1. From an env var that holds the path to the env file (default var name: APC_ENV)
#    e.g. APC_ENV=/path/to/apc.env
settings = APCSettings.from_env()            # or APCSettings.from_env('MY_VAR')

# 2. From an explicit env-file path
settings = APCSettings.from_env_file(Path('apc.env'))

# 3. Directly (or from process environment variables)
settings = APCSettings(apc_email='...', apc_password='...', base_url='https://apc-training.hypaship.com/api/3.0/')

The client authenticates every request with the remote-user: Basic base64(email:password) header required by Hypaship. APCSettings.headers builds it for you.

Quick start

import base64
from datetime import date
from pathlib import Path

from apc_hypaship.apc_client import APCClient
from apc_hypaship.config import APCSettings
from apc_hypaship.models.request.address import Address, Contact
from apc_hypaship.models.request.services import APCServiceCode
from apc_hypaship.models.request.shipment import GoodsInfo, Order, Shipment, ShipmentDetails

client = APCClient(settings=APCSettings.from_env())

order = Order(
    collection_date=date(2026, 11, 16),
    product_code=APCServiceCode.PARCEL_1600,
    reference='ORDER-1234',
    delivery=Address(
        company_name='Acme Ltd',
        address_line_1='1 High Street',
        city='London',
        postal_code='NW2 3EJ',
        contact=Contact(person_name='Jane Doe', mobile_number='07700900000', email='jane@example.com'),
    ),
    goods_info=GoodsInfo(goods_value='250', goods_description='Radios'),
    shipment_details=ShipmentDetails(number_of_pieces=2),
)
shipment = Shipment.from_order(order)

# 1. (optional) see which services are available for this shipment
availability = client.fetch_service_available(shipment)
for svc in availability.service_availability.services.service:
    print(svc.product_code, svc.service_name, svc.total_cost)

# 2. book it - raises APCException if Hypaship rejects the order
booking = client.fetch_book_shipment(shipment)
order_num = booking.order_num

# 3. fetch the label (allow a few seconds after booking for it to be generated)
label = client.fetch_label(order_num)
Path(f'{order_num}.pdf').write_bytes(base64.b64decode(label.content))

# 4. track it
tracks = client.fetch_tracks(order_num)
print(tracks.messages.code, tracks.track.way_bill)

Things to know

  • Field names: models use snake_case in Python and serialize to the PascalCase names Hypaship expects (postal_code → PostalCode). Either form is accepted when constructing models.
  • Dates and times are sent as DD/MM/YYYY and HH:MM.
  • Collection address: if Order.collection is omitted, Hypaship uses the account's operational address. If you supply one that doesn't exactly match it, the order becomes a third-party pickup (PUR).
  • Items: if ShipmentDetails.items is omitted, one Item per piece is created automatically, each with a default weight of 12 kg. Pass explicit Items if your parcels differ.
  • Labels are returned base64-encoded in Label.content; decode before writing to disk. Only PDF is currently supported by fetch_label.
  • Errors: HTTP errors raise httpx.HTTPStatusError. Business errors on booking (e.g. invalid postcode) raise apc_hypaship.models.response.common.APCException, which carries code and error_fields.

Documentation

Full docs (guides + API reference generated from the source) are built with Sphinx:

uv sync
uv run sphinx-build -b html docs/source docs/build/html

Then open docs/build/html/index.html.

Development

uv sync                 # install with dev dependencies
uv run ruff check .     # lint
uv run ruff format .    # format

Tests

The tests hit the real Hypaship training API (they book real test orders), so you need training credentials:

export APC_ENV=/path/to/training/apc.env
uv run pytest

As a safety net, the tests are skipped unless BASE_URL contains training.

Metadata

Release files for apc-hypaship 0.1.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for apc-hypaship 0.1.12
File Size Uploaded Provenance Actions
apc_hypaship-0.1.12.tar.gz 11.5 kB Without provenance Details for apc_hypaship-0.1.12.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for apc-hypaship 0.1.12
File Interpreter ABI Platform Actions
apc_hypaship-0.1.12-py3-none-any.whl Python 3 none any Details for apc_hypaship-0.1.12-py3-none-any.whl

Total release size: 29.0 kB

Release files / apc_hypaship-0.1.12.tar.gz

Download URL apc_hypaship-0.1.12.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
42e8dad98f004048a2a6b732cec09474d7ce743fe4a9c9c63b8e09e660f4daae
BLAKE2b-256 checksum
How to use checksums
b2b5f70f029d42611dd25180242a554d602dd36424f5b5484416d11844609971
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / apc_hypaship-0.1.12-py3-none-any.whl

Download URL apc_hypaship-0.1.12-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b96793f751500f64712ac104ae077eee6b9a1dea36490efbe7b73fbe066524d1
BLAKE2b-256 checksum
How to use checksums
79154beea76635fcc721800e15a7d3dcf8605510feba347ba4cb60d450fbda49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for apc-hypaship 0.1.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page