Skip to main content

Official Integrations

The Data Docked API is a REST API that works with any HTTP client. Here are examples for popular languages and frameworks.

Installation

Use the requests library for HTTP calls:
pip install requests

Usage

import requests

API_KEY = "your_api_key"
BASE_URL = "https://datadocked.com/api/vessels_operations"

def get_vessel_location(imo_or_mmsi: str) -> dict:
    response = requests.get(
        f"{BASE_URL}/get-vessel-location",
        params={"imo_or_mmsi": imo_or_mmsi},
        headers={"x-api-key": API_KEY}
    )
    return response.json()

# Track a vessel
vessel = get_vessel_location("9247431")
print(f"Vessel: {vessel['detail']['name']}")
print(f"Position: {vessel['detail']['latitude']}, {vessel['detail']['longitude']}")

Async with httpx

import httpx
import asyncio

async def get_vessel_location_async(imo_or_mmsi: str) -> dict:
    async with httpx.AsyncClient() as client:
        response = await client.get(
            f"{BASE_URL}/get-vessel-location",
            params={"imo_or_mmsi": imo_or_mmsi},
            headers={"x-api-key": API_KEY}
        )
        return response.json()

# Run async
vessel = asyncio.run(get_vessel_location_async("9247431"))

Helper Functions

Python: Complete API Client

import requests
from typing import Optional, List
from dataclasses import dataclass

@dataclass
class DataDockedClient:
    api_key: str
    base_url: str = "https://datadocked.com/api/vessels_operations"

    def _request(self, endpoint: str, params: dict = None) -> dict:
        response = requests.get(
            f"{self.base_url}/{endpoint}",
            params=params,
            headers={"x-api-key": self.api_key}
        )
        response.raise_for_status()
        return response.json()

    def get_credits(self) -> str:
        return self._request("my-credits")["detail"]

    def get_vessel_location(self, imo_or_mmsi: str) -> dict:
        return self._request("get-vessel-location", {"imo_or_mmsi": imo_or_mmsi})

    def get_vessel_info(self, imo_or_mmsi: str) -> dict:
        return self._request("get-vessel-info", {"imo_or_mmsi": imo_or_mmsi})

    def bulk_location_search(self, identifiers: List[str]) -> dict:
        return self._request("get-vessels-location-bulk-search",
                           {"imo_or_mmsi": ",".join(identifiers)})

    def get_port_calls(self, imo_or_mmsi: str) -> dict:
        return self._request("port-calls-by-vessel", {"imo_or_mmsi": imo_or_mmsi})

# Usage
client = DataDockedClient(api_key="your_api_key")
print(client.get_credits())
vessel = client.get_vessel_location("9247431")

Rate Limiting

Implement exponential backoff for production use:
import time
import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

def create_session(api_key: str) -> requests.Session:
    session = requests.Session()
    session.headers["x-api-key"] = api_key

    retries = Retry(
        total=3,
        backoff_factor=1,
        status_forcelist=[429, 500, 502, 503, 504]
    )
    session.mount("https://", HTTPAdapter(max_retries=retries))
    return session

session = create_session("your_api_key")
response = session.get("https://datadocked.com/api/vessels_operations/get-vessel-location",
                       params={"imo_or_mmsi": "9247431"})

Environment Variables

Store your API key securely:
DATADOCKED_API_KEY=your_api_key_here