Home → Blog

You’re routing containers via Port Klang (MYPKG) and need a dependable congestion signal you can automate into ETAs, allocation logic, or booking holds. By the end of this guide, you’ll query congestion for MYPKG via API, parse the fields you actually need, and ship a safe integration that accounts for data lag and averaging windows.

What this dataset measures (and what it does not)

The congestion signal you’ll query here is sourced from IMF PortWatch and republished through FreightPulse. It is a lagged indicator: a 7-day average of port calls compared against a 90-day baseline for the same port. It is not live AIS wait times or anchorage delays, and it does not measure time-in-port. A lower-than-baseline activity reading can appear during closures or slowdowns even if vessels are queued offshore. Keep this distinction in mind when wiring alerts or ETAs.

Illustration: Port Klang (MYPKG) Congestion

Key facts before you integrate

How to query Port Klang (MYPKG) congestion

The endpoint is a simple GET with the UN/LOCODE. For Port Klang, use MYPKG. Authentication goes in the X-API-Key header. If you are just testing locally, you can start without a key (guest quota applies), then add a key once you move to automation.

Copy-paste cURL

Live FreightPulse congestion for MYPKG.
Source: live

cURL:

JSON:

{
    "success": true,
    "data": {
        "results": [
            {
                "port": "Port Klang",
                "locode": "MY PKG",
                "country": "Malaysia",
                "activity": "moderate",
                "congestion": "moderate",
                "as_of": "2026-11-13",
                "metrics": {
                    "recent_avg_portcalls_per_day": 29.9,
                    "baseline_avg_portcalls_per_day": 31.7,
                    "ratio_vs_baseline": 0.94
                }
            },
            {
                "port": "Pelabuhan Sungai Udang",
                "locode": "MY PKG",
                "country": "Malaysia",
                "activity": "moderate",
                "congestion": "moderate",
                "as_of": "2026-11-13",
                "metrics": {
                    "recent_avg_portcalls_per_day": 2.1,
                    "baseline_avg_portcalls_per_day": 1.8,
                    "ratio_vs_baseline": 1.19
                }
            }
        ],
        "global_summary": {
            "ports_high_activity": 0,
            "ports_moderate_activity": 2,
            "ports_low_activity": 0,
            "ports_high_congestion": 0,
            "ports_moderate": 2,
            "ports_low": 0
        },
        "meta": {
            "source": "IMF PortWatch (portwatch.imf.org) - UN Global Platform AIS data",
            "data_lag_days": "4-11 (PortWatch republishes the daily series once a week; check as_of)",
            "methodology": "activity is port-call volume, not congestion: last 7 days' avg calls vs a 90-day baseline for the same port. low means fewer calls than usual, which can be a closure or ships waiting offshore. It does not measure vessel wait or anchorage time. congestion is a deprecated alias of activity."
        }
    },
    "meta": {
        "request_id": "deda4f5f-86b4-4eb0-8dcd-d3326de854d9"
    }
}

What to read from the response

Python example: fetch MYPKG congestion and normalize the output

The snippet below queries the endpoint, extracts ratio_vs_baseline and as_of for Port Klang, and returns a compact dict your app can cache and render. It also checks the top-level success flag and guards against missing fields.

import os
import requests

API_URL = "https://freightpulsehq.com/api/v1/port-congestion"
PORT = "MYPKG"
API_KEY = os.getenv("FREIGHTPULSE_API_KEY", "YOUR_API_KEY")

def fetch_port_klang_congestion():
headers = {"X-API-Key": API_KEY}
params = {"port": PORT}
resp = requests.get(API_URL, headers=headers, params=params, timeout=15)
resp.raise_for_status()
payload = resp.json()

if not payload.get("success"):
raise RuntimeError("API returned success=false")

data = payload.get("data", {})
results = data.get("results", []) or []
# Filter for Port Klang specifically (the response may include nearby terminals)
klang = next((r for r in results if r.get("port") == "Port Klang"), None)
if not klang:
# Fallback: take the first result if exact match not found
klang = results[0] if results else None

if not klang:
raise RuntimeError("No results found for MYPKG")

metrics = klang.get("metrics", {}) or {}
ratio = metrics.get("ratio_vs_baseline")
as_of = klang.get("as_of")
label = klang.get("congestion") or klang.get("activity")

if ratio is None or as_of is None:
raise RuntimeError("Missing required fields ratio_vs_baseline or as_of")

return {
"port": klang.get("port"),
"locode": klang.get("locode"),
"as_of": as_of, # YYYY-MM-DD (no timezone)
"ratio_vs_baseline": ratio, # unitless ratio
"label": label # string category aligned with activity
}

if __name__ == "__main__":
summary = fetch_port_klang_congestion()
print(summary)

Interpreting Port Klang (MYPKG) results in your app

Use ratio_vs_baseline for any quantitative rule. Because it’s a ratio, you can wire simple thresholds without tuning for absolute volume. For example, flag “below-normal activity” when ratio_vs_baseline < 0.9 and display a heads-up to planners. Keep in mind that fewer port calls can accompany a queue offshore, so combine this with your own vessel tracking or carrier advisories if you need wait-time estimates.

Caching, retries, and update cadence

The series updates roughly weekly when PortWatch republishes. In most dashboards, caching the latest successful response for 24 hours is safe and avoids burning through the guest quota. On job pipelines, schedule a daily refresh and replace the cached document only if success is true.

Common UI patterns for supply and operations teams

Production hardening checklist

Troubleshooting and validation

If you see an unexpected drop or spike at MYPKG, confirm the as_of date first. If it’s older than a week, you may be looking at the last published window from PortWatch. When automating alerts, suppress duplicate notifications if as_of hasn’t changed.

Security and deployment notes

Field reference: what you likely need to persist

Extending to alerts and pipelines

Once the basic fetch is in place, add an alerting job that compares today’s ratio_vs_baseline vs the last saved as_of. Trigger a notification only when as_of advances and the ratio crosses a threshold. Include the as_of date and remind users this is a 7-day average vs a 90-day baseline, lagged from real time.

Where to go next

FAQ

Is this a live anchorage or dwell-time feed?
No. It’s a 7-day average of port-call volume vs a 90-day baseline (from IMF PortWatch). It does not measure time-in-port or anchorage wait times.

How fresh is the data for Port Klang?
Expect a lag of roughly 6–7 days. Always show the as_of date and treat it as authoritative for freshness.

What thresholds should I use for alerts?
Keep it simple: for example, alert when ratio_vs_baseline < 0.9 (below-normal activity). Tune thresholds to your tolerance, but anchor the logic on ratio_vs_baseline.

Do I need an API key?
You can start without one (guest: 100 requests/day per IP). For production or higher volume, pass X-API-Key: YOUR_API_KEY in the request header.

Can I quote freight rates based on this response?
No. This endpoint does not return rates or fares. Avoid implying any USD price as “today’s price” from this dataset.

Set up a lightweight job to pull MYPKG congestion daily, cache the latest success=true response, and display ratio_vs_baseline with the as_of date in your planning tools. When you’re ready to move beyond the guest cap and ship this in production, grab an API key here: Register.