client module#

The HTTP plumbing both part sources need#

JSONClient is the only place in this package that speaks HTTP. Both the LCSC and the JLCPCB list APIs are unauthenticated JSON POST endpoints that report failure in the response body rather than the status line, so the two clients differ in their base URL, their paths and how the body wraps a result, and in nothing else.

Every failure, including a transport error, a failure code in the body and malformed JSON, is raised as ProviderUnavailable. That is what lets a design with a populated lockfile build on a box with no network: the chain reports itself unreachable and the lock answers instead.

class JSONClient(base_url, timeout=20.0, attempts=2)[source]#

Bases: ABC

POSTs JSON to one host and unwraps whatever envelope it answers with.

Parameters:
  • base_url (str) – API host, for pointing at a mirror or a recording proxy.

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

  • attempts (int) – how many times a request is tried before giving up.

base_url: str#
timeout: float = 20.0#
attempts: int = 2#
abstract 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.

abstractmethod 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:
post(path, body)[source]#

The result of one request, or ProviderUnavailable naming why not.

Return type:

dict[str, Any]

Parameters:
unavailable(message)[source]#

A ProviderUnavailable naming this client, for unwrap to raise.

Return type:

ProviderUnavailable

Parameters:

message (str)