Skip to main content

Updated 3 min read11 views

Automating KiCad Symbol Generation from PDF Datasheets

Drawing symbols and copy-pasting pinouts by hand is slow and error-prone. Learn how to script KiCad symbol generation from datasheet pin data using our API.

Felix S. Pavel

Founder & Lead Architect

The Library Bottleneck in PCB Design

Centralized component libraries are critical for team consistency, but creating schematic symbols is one of the most tedious manual tasks in PCB design. An engineer must copy pin names, numbers, and electrical types from the PDF table and translate them into their CAD editor. A single transposed pin can trigger a board respin.

This manual process is prone to human error, especially on high-pin-count microcontrollers or dense BGA packages. Generating symbols from extracted pin data removes the retyping step, and the review moves to checking rows against the pages they came from.

Programmatic Library Generation

The solution is treating component definitions as code. By leveraging the DatasheetVend API, we can programmatically extract structured pin maps as JSON and pipe them into library generation scripts.

# Fetch structured pinout from DatasheetVend and generate a .kicad_sym file
# No external dependencies, uses only Python stdlib
# Full tool: https://github.com/FelixNovaNexus/kicad-tools

import json
from http.client import HTTPSConnection

PIN_TYPE_MAP = {
    "POWER": "power_in", "GROUND": "power_in",
    "INPUT": "input", "OUTPUT": "output",
    "BIDIRECTIONAL": "bidirectional", "RESET": "input",
    "CLOCK": "input", "ANALOG": "passive", "NC": "no_connect",
}

def pin_name(pin):
    return pin.get("pin_name") or pin.get("name", "")

def pin_number(pin):
    return pin.get("pin_number") or pin.get("number", "")

def generate_kicad_sym(part_name, pins):
    left  = [p for i, p in enumerate(pins) if i % 2 == 0]
    right = [p for i, p in enumerate(pins) if i % 2 == 1]
    half_h = (max(len(left), len(right)) * 2.54 + 2.54) / 2
    lines = [
        "(kicad_symbol_lib (version 20220914) (generator datasheetvend_pdf_to_symbol)",
        f'  (symbol "{part_name}" (in_bom yes) (on_board yes)',
        '    (symbol "' + part_name + '_0_1"',
    ]
    for i, pin in enumerate(left):
        ktype = PIN_TYPE_MAP.get(pin.get("pin_type", "").upper(), "unspecified")
        y = half_h - 1.27 - i * 2.54
        lines += [f'      (pin {ktype} line (at -10.16 {y:.2f} 0) (length 5.08)',
                  f'        (name "{pin_name(pin)}" (effects (font (size 1.016 1.016))))',
                  f'        (number "{pin_number(pin)}" (effects (font (size 1.016 1.016))))',
                   '      )']
    for i, pin in enumerate(right):
        ktype = PIN_TYPE_MAP.get(pin.get("pin_type", "").upper(), "unspecified")
        y = half_h - 1.27 - i * 2.54
        lines += [f'      (pin {ktype} line (at 10.16 {y:.2f} 180) (length 5.08)',
                  f'        (name "{pin_name(pin)}" (effects (font (size 1.016 1.016))))',
                  f'        (number "{pin_number(pin)}" (effects (font (size 1.016 1.016))))',
                   '      )']
    lines += ['    )', '  )', ')']
    return '\n'.join(lines)

job_id  = "YOUR_JOB_ID"
api_key = "dsv_YOUR_API_KEY"  # your DatasheetVend developer API key

conn = HTTPSConnection("datasheetvend.com")
conn.request("GET", f"/api/v1/jobs/{job_id}/pinout",
             headers={"Accept": "application/json",
                      "Authorization": f"Bearer {api_key}"})
res  = json.loads(conn.getresponse().read())

payload  = res["data"]                    # pinout_api_payload_v1
pins     = payload["data"]["pins"]        # list of { pin_number, pin_name, pin_type, ... }
part     = payload.get("identity", {}).get("component", {}).get("manufacturer_part_number") or "PART"

# Stop if the run says the pin map is not safe to seed a CAD symbol yet
if not payload["machine_use"]["safe_for_cad_symbol_seed"]:
    raise SystemExit("Flagged for human review: check the warnings before generating a symbol")

with open(f"{part}.kicad_sym", "w") as f:
    f.write(generate_kicad_sym(part, pins))
print(f"{part}.kicad_sym written ({len(pins)} pins)")

Ready-to-Use CLI Tool

The snippet above is a condensed illustration. For a fuller version, grab the zero-dependency CLI tool we open-sourced on GitHub. It handles offline mode, strict CAD-safety gating, verbose extraction reports, and BGA alphanumeric pin designators out of the box.

Terminal

# Download and run, no pip install needed

curl -O https://raw.githubusercontent.com/FelixNovaNexus/kicad-tools/main/pdf_to_symbol.py

python pdf_to_symbol.py --job-id YOUR_JOB_ID --session-id YOUR_TOKEN --verbose

Applying Standards in Generation

Because generation is driven by code, you can layer your company's proprietary drafting standards on top, placing power pins on top, ground pins at the bottom, or grouping by peripheral family. The pin_type field returned by the API maps directly to KiCad electrical types, so the logic is a simple dictionary lookup rather than hand-crafted per-symbol rules.

Treat Components as Code.

Integrate DatasheetVend's developer API into your PCB library workflow. Generate symbols from extracted pin data, then review them against the pages they came from.

Sources

  1. DatasheetVend API reference: the pinout payload
  2. kicad-tools on GitHub: pdf_to_symbol.py

Was this useful?

A like tells other engineers it is worth their time.

Keep reading

All articles

Cookies. Strictly necessary cookies keep you signed in and remember this choice. Optional analytics (Google, Microsoft, PostHog) show us how the site is used. Cookie details