Python quickstart - Barcode Rendering

This guide shows how to call the barcode rendering facet from Python using httpx (recommended) or requests.

Prerequisites

Install:

pip install httpx
import os
import httpx

API_BASE = "https://api.product-data-api.com"


def render_barcode(payload: dict, api_key: str) -> dict:
    """
    Renders a barcode and returns the metadata response envelope.
    """
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }
    url = f"{API_BASE}/api/v1/barcodes/render"

    with httpx.Client() as client:
        r = client.post(url, json=payload, headers=headers)

    r.raise_for_status()
    return r.json()


if __name__ == "__main__":
    api_key = os.environ["PRODUCT_DATA_API_KEY"]

    request_payload = {
        "type": "ean13",
        "data": "4006381333931",
        "format": "png",
        "width": 200,
        "height": 100,
        "metadata": {
            "copyright": "Copyright 2026 open4goods"
        }
    }

    response = render_barcode(request_payload, api_key)
    print(f"Asset URL: {response['assetUrl']}")
    print(f"Expires at: {response['expiresAt']}")

Using requests

Install:

pip install requests
import os
import requests

API_BASE = "https://api.product-data-api.com"


def render_barcode(payload: dict, api_key: str) -> dict:
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }
    url = f"{API_BASE}/api/v1/barcodes/render"

    r = requests.post(url, json=payload, headers=headers)
    r.raise_for_status()
    return r.json()

Next steps