Skip to content

hashgraph-online/awesome-codex-plugins / plugins/aklofas/kicad-happy/skills/lcsc

Search LCSC Electronics for electronic components — find parts by LCSC number (Cxxxxx) or MPN, check stock/pricing, download datasheets, analyze specifications. Sister company to JLCPCB, same parts library. Sync and maintain a local datasheets directory for a KiCad project, or use batch MPN-list seeding (`--mpn-list`) for bulk workflows without a project. No API key needed — uses the free jlcsearch community API. Use this skill when the user mentions LCSC, JLCPCB parts library, JLCPCB assembly parts, production sourcing, Cxxxxx part numbers, needs to find LCSC equivalents for parts, is preparing a BOM for JLCPCB assembly, or wants to download datasheets and LCSC is available. For package cross-reference tables and BOM workflow, see the `bom` skill.

FileKindSize
SKILL.mdskill md11.9 KB
scripts/_core_path.pyscript697 B
scripts/fetch_datasheet_lcsc.pyscript6.5 KB
scripts/provider_lcsc.pyscript14.2 KB
scripts/search_lcsc.pyexecutablescript15.0 KB
scripts/sync_datasheets_lcsc.pyscript2.6 KB
scripts/test_search_lcsc.pyexecutablescript22.6 KB

scripts/fetch_datasheet_lcsc.py

View on GitHub
#!/usr/bin/env python3
"""Download a datasheet PDF by searching LCSC/jlcsearch for the URL.

Uses the jlcsearch community API (no auth required) to find parts by
MPN or LCSC code (Cxxxxx), then downloads the datasheet PDF directly
from LCSC's CDN (wmsc.lcsc.com). LCSC PDFs download without bot
protection — no special headers or browser fallback needed.

Usage:
    python3 fetch_datasheet_lcsc.py --search <MPN_or_LCSC_code> [--output <path>]
    python3 fetch_datasheet_lcsc.py <url> [--output <path>]

Exit codes:
    0 = success (PDF downloaded)
    1 = download failed after all attempts
    2 = search failed (part not found)

Dependencies:
    - requests (pip install requests) — preferred
    - Falls back to urllib if requests is not installed or is older than 2.32.2
    - playwright (optional) — for JS-rendered datasheet pages, only with datasheets.allow_private_hosts
"""

import argparse
import json
import re
import sys
import _core_path  # noqa: F401
from distributor_core.download import try_alternative_sources, add_download_args, apply_download_args
from distributor_core.verify import fetch_mismatch, refuse_fetch_hit, same_part, verify_datasheet
from distributor_core.manifest import _friendly_filename
from provider_lcsc import (
    download_pdf,
    search_lcsc,
    search_lcsc_direct,
    enrich_with_wmsc,
    _get_datasheet_url,
    _get_mpn,
    _get_lcsc_code,
    _get_manufacturer,
    _get_description,
)


# ---------------------------------------------------------------------------
# CLI
# ---------------------------------------------------------------------------

def main():
    parser = argparse.ArgumentParser(description="Download a datasheet PDF via LCSC/jlcsearch")
    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument("url", nargs="?", help="Direct URL to the PDF")
    group.add_argument("--search", metavar="QUERY",
                       help="Search by MPN or LCSC code (e.g., GRM155R71C104KA88D or C14663)")
    parser.add_argument("--output", "-o", help="Output file path (default: <MPN>.pdf)")
    parser.add_argument("--json", action="store_true", help="Output result as JSON")
    add_download_args(parser)
    args = parser.parse_args()
    apply_download_args(args)

    if args.search:
        def mismatch(c):
            return fetch_mismatch(args.search, _get_mpn(c), [_get_lcsc_code(c)])

        component = enrich_with_wmsc(search_lcsc(args.search))
        # A refused hit still lets a C-number fall back to the direct lookup.
        refused = mismatch(component) if component else ""
        if refused:
            component = None
        if not component and re.match(r"^C\d+$", args.search, re.IGNORECASE):
            print(f"jlcsearch returned no usable result for {args.search}, trying wmsc API...",
                  file=sys.stderr)
            component = search_lcsc_direct(args.search)
            refused = mismatch(component) if component else refused
            if refused and component:
                component = None
        if refused and not component:
            refuse_fetch_hit("LCSC", args.search, refused, args.json)
        if not component:
            if args.json:
                json.dump({"success": False, "error": "Part not found on LCSC"}, sys.stdout)
            else:
                print(f"No LCSC results for '{args.search}'", file=sys.stderr)
            sys.exit(2)

        mpn = _get_mpn(component)
        lcsc_code = _get_lcsc_code(component)
        desc = _get_description(component)
        mfg = _get_manufacturer(component)
        ds_url = _get_datasheet_url(component)
        verify_pn = args.search if same_part(args.search, mpn) else (mpn or args.search)

        display_pn = mpn or lcsc_code or args.search
        output_path = args.output or (_friendly_filename(display_pn, desc) + ".pdf")

        if args.json:
            result = {
                "mpn": mpn,
                "lcsc": lcsc_code,
                "manufacturer": mfg,
                "description": desc,
                "datasheet_url": ds_url,
                "in_stock": component.get("stock", 0),
                "price": component.get("price"),
            }

        if not ds_url:
            print(f"No datasheet URL for {display_pn}", file=sys.stderr)
            if args.json:
                result["success"] = False
                result["error"] = "No datasheet URL in LCSC listing"
                json.dump(result, sys.stdout)
            sys.exit(2)

        print(f"Downloading datasheet for {display_pn} ({lcsc_code})...", file=sys.stderr)
        if download_pdf(ds_url, output_path):
            vr = verify_datasheet(output_path, verify_pn, desc, mfg)
            if vr["confidence"] == "wrong":
                print(f"WARNING: Downloaded PDF may be wrong datasheet for {display_pn}",
                      file=sys.stderr)
                print(f"  {vr['details']}", file=sys.stderr)
            if args.json:
                result["success"] = True
                result["output"] = output_path
                result["verification"] = vr
                json.dump(result, sys.stdout)
            sys.exit(0)

        # Try alternative sources
        if mpn:
            print(f"LCSC URL failed, trying alternatives for {mpn}...", file=sys.stderr)
            if try_alternative_sources(mpn, output_path):
                vr = verify_datasheet(output_path, verify_pn, desc, mfg)
                if args.json:
                    result["success"] = True
                    result["output"] = output_path
                    result["source"] = "alternative"
                    result["verification"] = vr
                    json.dump(result, sys.stdout)
                sys.exit(0)

        print(f"Failed to download datasheet for {display_pn}", file=sys.stderr)
        if args.json:
            result["success"] = False
            result["error"] = "All download methods failed"
            json.dump(result, sys.stdout)
        sys.exit(1)

    else:
        # Direct URL mode
        url = args.url
        output_path = args.output or "datasheet.pdf"

        if download_pdf(url, output_path):
            if args.json:
                json.dump({"success": True, "output": output_path, "url": url}, sys.stdout)
            sys.exit(0)
        else:
            print(f"Failed to download PDF from {url}", file=sys.stderr)
            if args.json:
                json.dump({"success": False, "url": url, "error": "Download failed"}, sys.stdout)
            sys.exit(1)


if __name__ == "__main__":
    from kicad_core.cli import utf8_stdio
    utf8_stdio()
    main()
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 319kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 197kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 197kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 197kUpdated Claude CodeCodexVerifiedInstall