Skip to main content

Calculate volumetric (dimensional) and chargeable weight for air, courier, sea, road, and rail freight

Project description

chargeable-weight

Calculate volumetric (dimensional) weight and chargeable weight for air, courier, sea, road, and rail freight shipments.

Carriers bill shipments based on whichever is greater: the actual weight or the volumetric weight (calculated from package dimensions). This library implements that calculation cleanly, with support for multiple units, transport modes, named divisor presets, and multi-package consignments.

Install

pip install chargeable-weight

Quick start

from chargeable_weight import calculate

result = calculate(
    length=60, width=40, height=40, unit="cm",
    actual_weight=18, weight_unit="kg",
    mode="air",
)

print(result.volumetric_weight_kg)   # 19.2
print(result.chargeable_weight_kg)   # 19.2
print(result.basis)                  # "volumetric"

Supported modes and default divisors

Mode Default divisor (cm³/kg)
air 6000
courier 5000
road 3000
rail 3000
sea N/A (uses CBM × 1000, see below)

These are sensible starting defaults based on common conventions seen across the freight and parcel industry. They are not tied to any specific carrier - always confirm the applicable divisor with your own carrier or contract for billing-critical calculations.

Divisor presets

Two divisor values - 5000 and 6000 - are both widely used across the industry, often for different services, regions, or contracts (sometimes even by the same carrier depending on the product). Rather than guessing which one applies to your situation, you can refer to them by generic preset labels and swap between them easily:

Preset Divisor
"a" 5000
"b" 6000
# Same package, two different divisor conventions
pkg = dict(length=60, width=40, height=40, actual_weight=10, mode="air")

result_a = calculate(**pkg, divisor_preset="a")  # divisor 5000
result_b = calculate(**pkg, divisor_preset="b")  # divisor 6000

print(result_a.volumetric_weight_kg)  # 19.2
print(result_b.volumetric_weight_kg)  # 16.0

This makes it easy to compare "what would this shipment cost under each convention" without hardcoding either value, and to plug in your own carrier's documented divisor (whether that happens to be 5000, 6000, or something else entirely) via divisor_preset or a raw divisor= value.

You can also pass an explicit divisor directly, which overrides any preset:

result = calculate(**pkg, divisor=4500)

Units

Input units

Dimensions accept cm, m, mm, in, ft (default cm). Weights accept kg, g, lb, oz (default kg).

result = calculate(
    length=20, width=15, height=10, unit="in",
    actual_weight=5, weight_unit="lb",
    mode="courier",
)

Output units (always normalized)

Regardless of the input units you choose, all results are returned in a single fixed unit system:

Field Unit
actual_weight_kg, volumetric_weight_kg, chargeable_weight_kg kilograms (kg)
volume_m3 cubic meters (m³)

The input units (unit, weight_unit) are only used to interpret the numbers you pass in - they are converted to centimeters and kilograms internally before any calculation happens. The output is never expressed back in the input units.

For example, these two calls describe the same physical package and return (effectively) the same result, in kg/m³, even though one is given in inches/pounds and the other in cm/kg:

calculate(length=50, width=40, height=40, unit="cm",
          actual_weight=10, weight_unit="kg", mode="air")

calculate(length=19.685, width=15.748, height=15.748, unit="in",
          actual_weight=22.0462, weight_unit="lb", mode="air")

# Both return approximately:
# volumetric_weight_kg: 13.333
# volume_m3: 0.08

If you need the result in a different unit (e.g. pounds), convert the returned kg value yourself - the library does not provide unit conversion on outputs.

Sea freight (CBM)

Sea freight chargeable weight is derived from volume in cubic meters (CBM), using the common 1 CBM ≈ 1000 kg convention:

result = calculate(
    length=1, width=1, height=1, unit="m",
    actual_weight=500, mode="sea",
)
print(result.volumetric_weight_kg)  # 1000.0

Divisor presets are ignored for sea mode, since it uses a CBM-based calculation rather than a divisor.

Multi-package consignments

from chargeable_weight import calculate_consignment

packages = [
    {"length": 50, "width": 40, "height": 40, "actual_weight": 10},
    {"length": 60, "width": 40, "height": 40, "actual_weight": 25, "quantity": 2},
]

result = calculate_consignment(packages, mode="air")

print(result.total_actual_weight_kg)
print(result.total_volumetric_weight_kg)
print(result.total_chargeable_weight_kg)

By default, totals are compared (sum(actual) vs sum(volumetric)). Some couriers calculate chargeable weight per package and sum those - use per_piece=True for that behavior:

result = calculate_consignment(packages, mode="air", per_piece=True)

Disclaimer

This library implements widely-used industry conventions for illustrative and estimation purposes. Divisors and CBM ratios vary by carrier, service level, region, and contract terms. Always confirm exact billing methodology with your carrier or freight forwarder for invoicing-critical calculations.

License

MIT

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

chargeable_weight-0.1.0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

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

chargeable_weight-0.1.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for chargeable_weight-0.1.0.tar.gz
Algorithm Hash digest
SHA256 897cf1bf8aec6ed863ed727b75afcbc626957103fe2406e70fd686c655f24f27
MD5 eb7785fd2eef16ae0e74063a3ad29076
BLAKE2b-256 f7638e501d7cec509e5e3ffcda8ad74fdaf649883f92e482e5fefc4b3a3e4147

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for chargeable_weight-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf899901c8be8505f52fd2ae709e45af23d060dd58d680f5cc447f288cd78bbe
MD5 6230d3796c7c79c6a954ae696bc929ee
BLAKE2b-256 e9168aa26a6b68d14fbaedbec02cd7d5c8016d9d2a7131b8f8b8debc41f655ee

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