biopb¶
biopb ¶
Top-level BioPB Python package metadata.
Also the client for a biopb control plane (:mod:biopb._control, private):
every name below except __version__ is that package's content, re-exported
here rather than at biopb.control so that dotted path is never mistaken
for biopb-control, the separate control-plane server distribution this is
a client of. Stdlib only, so importing bare biopb stays cheap even
though biopb.tensor/biopb.image (pyarrow, dask) are not imported here.
DataPlaneEndpoint
dataclass
¶
DataPlaneEndpoint(
url: str,
token: Optional[str] = None,
tls_fingerprint: Optional[str] = None,
origin: str = "default",
tls_ca_pem: Optional[bytes] = None,
)
A resolved data-plane dial: where, with what credential, on what anchor.
LocalTrustError ¶
Bases: RuntimeError
The local data plane's TLS certificate could not be used as a trust anchor.
A distinct type because the layers above classify connect failures by
substring, and the most likely cause here — an unreadable cert file —
stringifies as [Errno 13] Permission denied. That matches an
authentication marker, so a file-permission problem would be reported as "the
server needs a token" and send the reader after a credential that has nothing
to do with it. Matching on the type is exact, and no errno wording can break it.
algorithm_logs ¶
The tail of a script entry's log: its installs and its server's output.
ValueError for a url entry.
Source code in src/main/python/biopb/_control/_algorithms.py
algorithms ¶
Every registry entry with its state and cached ops, or None when no
control answers. A url entry is probed, so this can take a probe's time.
Source code in src/main/python/biopb/_control/_algorithms.py
base_url ¶
control_grpc_url ¶
The data-plane URL the control publishes, or None if no control answers.
GETs the control's bare, unauthenticated /health and reads
data_plane.grpc_url from the supervisor snapshot — the single source of
truth for where the plane lives (biopb/biopb#413), because the control is what
chose the bind, the port, and the scheme. Best-effort: an absent, slow, or
malformed control is "no answer", never an exception, so the caller falls
through to the default rather than failing to resolve anything at all.
Source code in src/main/python/biopb/_control/_data_plane.py
default_data_plane_url ¶
The endpoint a default deployment puts the data plane on (grpc://…:8815).
ensure_algorithm ¶
Bring a script entry up, installing it first if its file changed, and
answer its row; a url entry is probed. Waits under timeout: a row still
installing or starting means ask again.
Raises LookupError for an unknown name.
Source code in src/main/python/biopb/_control/_algorithms.py
ensure_data_plane ¶
Have the control bring its plane up; {"url", "token"} or None.
POST /api/data_plane/ensure, idempotent on the control's side.
timeout is both this call's HTTP timeout and the client_timeout the
control keeps its own wait under, so a slow start comes back as a verdict
rather than as a timeout that looks like no control at all. None when
no control answers or it could not bring the plane up.
Source code in src/main/python/biopb/_control/_client.py
find_data_plane ¶
The plane the control names, {"url", "token"}, or None.
A plain read of GET /health: None when no control answers or it
names no plane. It does not start the plane; :func:ensure_data_plane
does.
Source code in src/main/python/biopb/_control/_client.py
is_local_url ¶
Whether url points at this machine.
local_data_plane_fingerprint ¶
Identity of the certificate a local plane serves, as a SHA-256 digest.
A loopback grpcs:// plane is this machine's own, so what it serves is
knowable here rather than something to accept on first sight (TOFU). The
digest is checked against the certificate the server actually presents on
every connect, which is strictly stronger than a pin learned from the wire
and keeps the client out of the shared pin store — where an operator's
cert init --force would otherwise strand it.
A fingerprint rather than the PEM itself, deliberately: handing the client a PEM resolves trust entirely offline, which also skips the hostname-override probe, and a local client dials loopback. A certificate carrying only the host's public name — the ordinary shape of an operator's own cert — then fails hostname verification on every connect (biopb/biopb#916).
Two sources, in order:
- what the plane published for this port (:mod:
biopb._tls_record), which is the only thing that knows about a--tls-certthe plane was handed; - failing that, the certificate the plane would have minted
(
state/biopb/tls/server-cert.pem), which is what a plane too old to publish anything serves.
None — leaving TOFU in charge — for a plaintext endpoint or a remote one,
whose certificate is not on this disk and cannot be. Raises
:class:LocalTrustError when a local plane is TLS and neither source
answers: silently falling back to TOFU there would trade a verified identity
for an unverified one exactly where the strong option was meant to apply.
Known edge: a loopback grpcs:// URL that is really an ssh -L tunnel to
a remote plane is indistinguishable from a local one by host alone, so it is
checked against the local plane's identity and fails. Loud and fixable (dial
the plane directly, or tunnel to a non-loopback alias), not silent.
Source code in src/main/python/biopb/_control/_data_plane.py
probe_data_plane_scheme ¶
"grpcs" / "grpc" by asking the listener, or None if nothing is there.
The scheme is the one thing a directly-launched plane still tells you for
free: a TLS listener completes a handshake and a plaintext one does not. So
ask it, rather than inferring from the presence of a cert on disk — a cert
minted once by cert init says nothing about whether the running plane was
started with --tls, and guessing wrong in either direction produces the
same "server unreachable" that #615 was filed for.
Certificate validation is deliberately off: this asks a yes/no question about
the wire protocol, and the answer decides which scheme to dial. Trust is
established afterwards, on the real connection, by :func:local_data_plane_fingerprint
or TOFU.
Source code in src/main/python/biopb/_control/_data_plane.py
refresh_algorithms ¶
Have the control install and describe new or edited script entries;
answers the rows at once, with those entries installing.
Source code in src/main/python/biopb/_control/_algorithms.py
resolve_data_plane ¶
resolve_data_plane(
override: Optional[str] = None,
token: Optional[str] = None,
*,
timeout: float = 1.0,
probe: bool = True
) -> DataPlaneEndpoint
Resolve the data-plane endpoint: override -> env -> control -> default.
override is an explicit --server-style address and wins over everything;
it is the escape hatch for a plane nothing records — one launched directly on
a custom port. token is an explicit --token and likewise wins over the
environment and over the control's credential file.
The credential file is read only for an endpoint the control named (see the module docstring): an address that bypassed the control is dialed with an explicit token or with none.
Set probe=False to skip the socket scheme probe on the default fallback
(a caller that only wants to name the endpoint, not dial it).
Raises :class:LocalTrustError when the resolved plane is local TLS but
nothing on this machine says what it serves — see :func:local_data_plane_fingerprint.
The TLS anchor is :func:data_plane_trust's.
Source code in src/main/python/biopb/_control/_data_plane.py
resolve_data_plane_token ¶
resolve_data_plane_token(
explicit: Optional[str] = None,
*,
allow_credential_file: bool = True
) -> Optional[str]
The data-plane token: explicit -> BIOPB_TENSOR_TOKEN -> credential file.
The credential file is what closes the gap for a local plane behind a token (biopb/biopb#470): the control writes the resolved token to an owner-only file in the user's state dir, so a client that never inherited the control's environment can still authenticate. The core CLI read only the env var until #615, which is why a token-gated local plane reported itself as unreachable.
allow_credential_file=False drops that last step, for a caller dialing an
endpoint the control did not name: the file holds this machine's credential
for the control's own plane, and it has no business being sent to an address
the user pointed elsewhere. The two explicit sources still apply — someone
naming a server can also name its token.
None — unauthenticated, correct for a tokenless local plane — when nothing
yields one. A blank value is None, never "": an empty string would be
sent as an empty Bearer header rather than omitted.
Source code in src/main/python/biopb/_control/_data_plane.py
restart_algorithm ¶
Stop a script entry and ensure it again. ValueError for a url entry.
stop_algorithm ¶
Stop a script entry's server. ValueError for a url entry.
user_base_url ¶
Where the user's browser reaches the control, for a link handed to them.
:func:control_base_url is where this machine connects, and behind a reverse
proxy (an Open OnDemand /node/<host>/<port> route) that is a loopback
address the user's browser cannot reach. A control told its public form
(--url-prefix, --public-origin) publishes it in its record: origin plus
prefix, or the bare path when only the prefix is set (a path on whatever site
the user opened the session from). Otherwise the two are the same.