lcsc module#

The LCSC part source#

LCSCParts resolves passives against the LCSC catalogue and attaches the LCSC part number to every component it materializes, so a design resolved through it exports to JLCPCB without anyone writing a C-number by hand.

from jitxlib.parts import PartSource from jitxlib.jlcpcb.parts import LCSCParts

PartSource([LCSCParts()])

or by name, since the package registers the provider:

[tool.jitx.parts] chain = [“lcsc”]

This is no longer the chain the package publishes; JLCPCBParts is. The two read the same catalogue, and the reason to name this one is that a query needs a parameter JLCPCB does not aggregate - a resistor’s rated_voltage_dc is the one known case - or that LCSC’s roughly threefold lower latency matters more than knowing which assembly library a part comes from. JLCPCBParts is otherwise strictly more capable.

The wire API#

Two endpoints, which is what the LCSC product-list page itself uses:

POST /ftps/wm/product/query/list the parametric product list POST /ftps/wm/product/query/param/group the filter vocabulary per catalog

Neither needs authentication. Both answer {“code”: 200, “result”: …} and report failure in the body rather than the status line.

LCSC ships two catalog numberings. A product record carries both a catalogId (439 for chip resistors) and a wmCatalogId (1199 for the same rows); the filter endpoints take the second, and asking param/group for the first answers with an empty vocabulary rather than an error. Every id in CATALOGS is a wmCatalogId.

class LCSCClient(base_url='https://wmsc.lcsc.com', timeout=20.0, attempts=2)[source]#

Bases: JSONClient

Talks to the LCSC list API.

>>> client = LCSCClient()
>>> body = {"keyword": "C25744", "currentPage": 1, "pageSize": 1}
>>> client.product_list(body)["dataList"][0]["productCode"]
'C25744'
Parameters:
base_url: str = 'https://wmsc.lcsc.com'#
property label: str#

How this client names itself in a ProviderUnavailable message.

property origin: dict[str, str]#

Extra headers this host wants, such as an Origin and a Referer.

unwrap(path, payload)[source]#

The result object inside a decoded response body.

Raises ProviderUnavailable when the body says the request failed, which is where the two APIs’ envelopes differ: LCSC answers {“code”: 200, “result”: …} and JLCPCB {“code”: 200, “data”: …}, both reporting failure with a non-200 code and HTTP 200.

Return type:

dict[str, Any]

Parameters:
product_list(body)[source]#

Search results for one query body. Returns the result object.

Return type:

dict[str, Any]

Parameters:

body (dict[str, Any])

param_group(catalog_ids)[source]#

The filter vocabulary for a set of catalogs. Returns result.

Return type:

dict[str, Any]

Parameters:

catalog_ids (Sequence[int])

class LCSCParts(base_url='https://wmsc.lcsc.com', in_stock=True, page_size=25, cache_dir='.jitx/lcsc', timeout=20.0, name='lcsc')[source]#

Bases: CatalogSource

Resolve passives against the LCSC catalogue.

>>> from jitxlib.parts import PartSource
>>> source = PartSource([LCSCParts()])
Parameters:
  • base_url (str) – the API host.

  • in_stock (bool) – restrict the search to parts LCSC has in stock.

  • page_size (int) – how many rows to ask for per query.

  • cache_dir (str | None) – where the filter vocabulary is cached, relative to the project. None disables the on-disk copy.

  • timeout (float) – per-request timeout in seconds.

  • name (str)

base_url: str = 'https://wmsc.lcsc.com'#
in_stock: bool = True#
page_size: int = 25#
cache_dir: str | None = '.jitx/lcsc'#

Where the filter vocabulary is cached, or None for memory only.

timeout: float = 20.0#
name: str = 'lcsc'#

How this provider is named in diagnostics and lockfile entries.

Supply it as a dataclass field, a plain class attribute, or an assignment in __init__. A property or a ClassVar is an incompatible override; for a derived name, use field(init=False) and set it in __post_init__.

config()[source]#

What identifies this provider, and nothing that does not.

The host, the stock policy and the catalog mapping, because each of them changes which part can be selected. The cache directory, the timeout and the page size are out: they change how long an answer takes, never what it is.

Return type:

dict[str, JSON]

property sort_fields: Mapping[str, str]#

Rank keys this source pushes to the API’s own sort.

catalogues(category)[source]#

Which catalogues serve category, or None if this source has none.

Return type:

Catalogues | None

Parameters:

category (Category)

vocabulary(catalogues)[source]#

The filter vocabulary for a set of catalogues. One request.

Return type:

OptionTable

Parameters:

catalogues (Catalogues)

search(query, category, catalogues, table)[source]#

Rows for one query, or a NoMatch naming what could not be asked.

Return type:

Sequence[Mapping[str, Any]] | NoMatch

Parameters:
read(row, category, table)[source]#

A row of dataList, as a Row.

None when it has no C-number.

Return type:

Row | None

Parameters: