← Back to Pull requests

feat(lib): add notebook cards and Nominal connection options #711

Merged
arsenovicAtNominal merged 26 files (1264 lines) on Nov 12, 2026 12:11 UTC
View on GitHub
arsenovicAtNominal arsenovicAtNominal commented on Nov 03, 2026 19:16 UTC
Author

Summary

First half of #709.

Notebook cards. Instruments and publishers display as HTML cards in Jupyter, VS Code and Colab, and have a one-line repr.

  • An instrument card shows:

  • - the driver and channel count
    - the background daemon's state, interval and last loop time
    - each publisher, with an Open in Nominal link for a NominalCorePublisher
    - the latest channel values once start() has run
    - the default tags
  • Cards are built only from in-memory state. Displaying an instrument never calls the driver.

  • set_display_options / get_display_options / DisplayOptions are exported from instro.lib and follow nominal-client's options.

  • The helpers in instro/lib/_display.py are copied from nominal-io/nominal-client#1260 and keep its CSS class names and render/Section signatures. Switching to a shared module is tracked in #710 and nominal-io/nominal-client#1263.
  • Connecting to Nominal.

  • NominalCorePublisher's first argument is dataset: a RID or an already-fetched Dataset. A Dataset carries its client's credentials, so NominalCorePublisher(client.get_dataset(rid)) works with any client. dataset_rid= still works as a keyword alias. Credentials for a RID are still profile or api_key; conflicting combinations raise ValueError.

  • client, dataset, dataset_rid, profile, batch_size, max_wait, file_fallback, write_stream and closed are public attributes. The API key isn't stored.

  • Instrument(..., dataset_rid=..., nominal_profile=..., nominal_client=...): the two new keywords configure the auto-created publisher and are not default tags. Either one without dataset_rid raises.

  • A NominalCorePublisher entry in JSON config takes max_wait_s and file_fallback.
  • Public publisher state.

  • NominalConnectPublisher: client, stream_id, source

  • FilePublisher: writer

  • BufferedPublisher: closed

  • QueuedPublisher: max_queue_size, wait_for_queue, queue_size

  • SharedPublisher: publisher

  • ChannelBufferPublisher: a new latest() method
  • Type of change

  • New feature (feat)
  • Verification

  • just check-python passes, and so does uv run pytest tests except tests/ethernetip, which I couldn't run because the locally built EtherNet/IP extension fails to load on my machine (unrelated to this change).

  • The strict docs build (sphinx-build -E -W) passes.

  • I rendered a VirtualPSU card with the daemon running and a queued FilePublisher attached, and checked the fields, publishers, channels and tags in the HTML.
  • Tests

  • Unit tests added or updated

  • - tests/lib/test_display.py:
    - the instrument card makes no driver calls
    - user values are escaped
    - the latest values appear while the instrument runs
    - style="text" returns no card
    - ChannelBufferPublisher.latest()
    - tests/lib/test_nominal_core_publisher.py:
    - exactly one dataset, and the dataset_rid= alias
    - the Dataset path
    - credential conflicts
    - the API key never appears in repr, the card or vars()
    - the dataset link, and no link when links are off or the URL can't be resolved
    - the Instrument keywords
    - The config tests now expect the two new NominalCorePublisher arguments.

    Checklist

  • PR title follows Conventional Commits

  • Documentation updated:

  • - new docs/library/notebook-display.md and docs/sdk/library/display.md
    - docs/library/publishers.md and docs/library/config-files.md
  • Code follows the style/conventions of the surrounding code
  • Notes for reviewers

  • Behaviour change: passing nominal_profile= or nominal_client= to an instrument used to add a default tag. Now they configure the auto-created NominalCorePublisher.

  • Not checked visually: I checked the cards as HTML, not in a notebook UI.

  • Follow-up: #709's second PR (publisher stats) is stacked on this branch.
  • 🤖 Generated with Claude Code

    Diff: 1264 lines (+1167 / -97) across 26 files Reviewer: arsenovicAtNominal Review duration: 12535m
    All Vouch review confidence checks passed
    Residual risk 0.12 = Change Risk (0.86) × (1 − Review Confidence (0.86)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.86 · 1264 lines diff across 26 files
    0.86
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.96 · 5 substantive comment(s)
    0.96
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    85%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Self Review self_review
    0.140
    Mass File Touch mass_file_touch
    0.080
    Real PR Conversation Timeline
    30 items
    claude[bot] claude[bot] commented on Nov 03, 2026 19:16 UTC
    Bot

    Claude finished @arsenovicAtNominal's task in 13m 29s —— View job

    ---

    Code review

  • Gather context (PR diff, AGENTS.md conventions)

  • Run /code-review --comment over the diff

  • Post inline findings

  • Post top-level overview
  • Overview: The display layer is well-scoped — _repr_html_/_display_fields() builds cards purely from in-memory state (confirmed: no driver calls), and the new public attributes (client, stream_id, writer, closed, max_queue_size, …) are a sensible minimal surface rather than a new facade. NominalCorePublisher's three credential paths (client=/api_key/profile) are cleanly mutually exclusive via ValueError, consistent with the repo's explicit-over-abstracted style.

    Posted 3 inline findings on instro/lib/publishers/nominal_core.py:

  • _credentials() (line 153) mislabels a directly-passed client= as "API key".

  • close() (line 144) isn't idempotent, unlike BufferedPublisher.close() added in this same PR.

  • profile/batch_size/max_wait default-fallback (lines 84, 91, 92) use x or default, which silently drops falsy-but-valid values like max_wait=timedelta(0).
  • One process note (not inline, no single line to anchor it): the PR body itself calls out that Instrument(..., nominal_profile=...) / nominal_client=... used to be stored as a default tag and now configures the auto-created publisher (and raises ValueError without dataset_rid) — that's a documented breaking behavior change, but the PR title (feat(lib): ...) doesn't carry the ! Conventional Commits requires for it.

    Test coverage looks solid elsewhere (credential conflicts, API-key redaction, link escaping, instrument-kwarg routing); no other convention or scope issues found.

    greptile-apps[bot] greptile-apps[bot] commented on Nov 03, 2026 19:21 UTC
    Bot

    <!-- greptile_summary -->

    <h2><a href="https://app.greptile.com/api/retrigger?id=94761046"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img alt="Retrigger" src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2" align="right"></picture></a><a href="https://app.greptile.com/-/switch-tenant?tenant=nominal&amp;next=%2Fnominal-io%2Finstro%2Fpull%2F711&amp;utm_source=greptile_review&amp;utm_medium=github&amp;utm_campaign=view_in_greptile"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img alt="View in Greptile" src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2" align="right"></picture></a>Confidence Score: 4/5</h2>

    [Medium impact] The changes affect notebook display and Nominal publishing for instro library users\.

    The PR appears safe to merge with two non-blocking fixes recommended for credential labels and large-buffer reads.

    <h2>Findings</h2>

    1. <img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top">&nbsp;Credential source is mislabeled <a href="https://github.com/nominal-io/instro/pull/711#discussion_r4459396878">▶</a>
    2. <img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top">&nbsp;Latest reads copy all history <a href="https://github.com/nominal-io/instro/pull/711#discussion_r4459396892">▶</a>

    <details><summary>Fix with agent prompt</summary>

    `

    ### Issue 1
    instro/lib/publishers/nominal_core.py:151-153
    Passing a client created with `NominalClient.from_profile("staging")` makes the card and `repr()` say `API key`. The constructor sets `profile=None` for every supplied client, and `_credentials()` treats that as proof of API-key authentication. Track supplied clients separately and show “provided client” when their credential source is unknown.
    
    ### Issue 2
    instro/lib/publishers/channel_buffer.py:192-193
    `latest()` requests one sample through helpers that copy each entire deque before slicing it. For a `DequeInMemoryPublisher` with a large history, returning one value per channel copies all retained values and timestamps while holding the lock that publishing needs. Read the deque tails directly, or add a one-sample path that avoids those copies.
    
    ---
    
    For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
    
    `

    </details>

    <h3>Summary</h3>

    Adds notebook cards, display options, public publisher state, and more ways to connect to Nominal.

  • Instruments and publishers show notebook cards with useful details.

  • Nominal publishers accept existing datasets and more credential choices.

  • Nominal Core cards link datasets only when a usable link is available.
  • <!-- greptile_confidence_score:4 -->

    <sub>Reviews (1) · Last reviewed commit: "feat(lib): add notebook cards and Nomina..." · Reviewed by Greptile</sub>

    greptile-apps[bot] greptile-apps[bot] commented on code on Nov 03, 2026 19:21 UTC
    Code Review
    instro/lib/publishers/nominal_core.py:1
    @@ -87,12 +134,49 @@ def __publish_measurement(self, data: Measurement):
     
         def __publish_command(self, data: Command):
             for ch_name in data.channel_data:
    -            self._write_stream.enqueue_batch(
    +            self.write_stream.enqueue_batch(
                     channel_name=ch_name,
                     timestamps=[data.timestamp],
                     values=[data.channel_data[ch_name]],
                     tags=data.tags,
                 )
     
         def close(self):
    -        self._write_stream.close()
    +        self.write_stream.close()
    +        self.closed = True
    +
    +    def _credentials(self) -> str:
    +        if self.profile is not None:
    +            return f"profile {self.profile!r}"
    +        if self.client is None:
    +            return "from the dataset passed in"
    +        return "API key" if self.base_url is None else f"API key, {self.base_url}"

    <a href="#"><img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top"></a> Credential source is mislabeled

    Passing a client created with NominalClient.from_profile("staging") makes the card and repr() say API key. The constructor sets profile=None for every supplied client, and _credentials() treats that as proof of API-key authentication. Track supplied clients separately and show “provided client” when their credential source is unknown.

    <details><summary>Prompt To Fix With AI</summary>

    `

    This is a comment left during a code review.
    Path: instro/lib/publishers/nominal_core.py
    Line: 151-153
    
    Comment:
    **Credential source is mislabeled**
    
    Passing a client created with `NominalClient.from_profile("staging")` makes the card and `repr()` say `API key`. The constructor sets `profile=None` for every supplied client, and `_credentials()` treats that as proof of API-key authentication. Track supplied clients separately and show “provided client” when their credential source is unknown.
    
    ---
    
    For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
    
    `
    </details>

    greptile-apps[bot] greptile-apps[bot] commented on code on Nov 03, 2026 19:21 UTC
    Code Review
    instro/lib/publishers/channel_buffer.py:1
    @@ -182,6 +182,21 @@ def close(self) -> None:
                 self._timestamps.clear()
                 self._total_added_count.clear()
     
    +    def latest(self) -> dict[str, tuple[int, float | str]]:
    +        """Return the newest ``(timestamp, value)`` of every channel holding data, in insertion order. Never blocks on new data."""
    +        with self._condition:
    +            snapshot: dict[str, tuple[int, float | str]] = {}
    +            for channel_name in self._values:
    +                if channel_name in self._timestamps and self._points_in_buffer(channel_name):
    +                    snapshot[channel_name] = (
    +                        self._get_timestamps(channel_name, 1)[0],
    +                        self._get_values(channel_name, 1)[0],

    <a href="#"><img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top"></a> Latest reads copy all history

    latest() requests one sample through helpers that copy each entire deque before slicing it. For a DequeInMemoryPublisher with a large history, returning one value per channel copies all retained values and timestamps while holding the lock that publishing needs. Read the deque tails directly, or add a one-sample path that avoids those copies.

    <details><summary>Prompt To Fix With AI</summary>

    `

    This is a comment left during a code review.
    Path: instro/lib/publishers/channel_buffer.py
    Line: 192-193
    
    Comment:
    **Latest reads copy all history**
    
    `latest()` requests one sample through helpers that copy each entire deque before slicing it. For a `DequeInMemoryPublisher` with a large history, returning one value per channel copies all retained values and timestamps while holding the lock that publishing needs. Read the deque tails directly, or add a one-sample path that avoids those copies.
    
    ---
    
    For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
    
    `
    </details>

    claude[bot] claude[bot] commented on code on Nov 03, 2026 19:29 UTC
    Code Review
    instro/lib/publishers/nominal_core.py:1
    @@ -87,12 +134,49 @@ def __publish_measurement(self, data: Measurement):
     
         def __publish_command(self, data: Command):
             for ch_name in data.channel_data:
    -            self._write_stream.enqueue_batch(
    +            self.write_stream.enqueue_batch(
                     channel_name=ch_name,
                     timestamps=[data.timestamp],
                     values=[data.channel_data[ch_name]],
                     tags=data.tags,
                 )
     
         def close(self):
    -        self._write_stream.close()
    +        self.write_stream.close()
    +        self.closed = True
    +
    +    def _credentials(self) -> str:
    +        if self.profile is not None:
    +            return f"profile {self.profile!r}"
    +        if self.client is None:
    +            return "from the dataset passed in"
    +        return "API key" if self.base_url is None else f"API key, {self.base_url}"

    _credentials() can't distinguish a directly-passed client= from API-key auth: both end up with self.profile is None and self.client is not None, so NominalCorePublisher(dataset_rid, client=my_client) reports "API key" in the repr/card even though no API key was used (see test_client_fetches_the_dataset, which doesn't assert on _credentials()).

    Fix this →%20at%20line%20148-153%20mislabels%20a%20directly-passed%20client%20as%20%22API%20key%22%20because%20self.profile%20is%20None%20and%20self.client%20is%20not%20None%20in%20both%20cases.%20Track%20whether%20the%20client%20was%20passed%20in%20directly%20(e.g.%20a%20new%20bool%20flag%20set%20in%20__init__)%20so%20_credentials()%20can%20report%20%22client%20passed%20directly%22%20instead.%20Branch%3A%20issue-709-notebook-cards&repo=nominal-io/instro)

    claude[bot] claude[bot] commented on code on Nov 03, 2026 19:30 UTC
    Code Review
    instro/lib/publishers/nominal_core.py:1
    @@ -87,12 +134,49 @@ def __publish_measurement(self, data: Measurement):
     
         def __publish_command(self, data: Command):
             for ch_name in data.channel_data:
    -            self._write_stream.enqueue_batch(
    +            self.write_stream.enqueue_batch(
                     channel_name=ch_name,
                     timestamps=[data.timestamp],
                     values=[data.channel_data[ch_name]],
                     tags=data.tags,
                 )
     
         def close(self):
    -        self._write_stream.close()
    +        self.write_stream.close()
    +        self.closed = True

    close() doesn't check self.closed before calling self.write_stream.close(), so a repeat close (e.g. instrument.close() called twice) closes the Rust-backed stream twice. BufferedPublisher.close() added in this same PR (publisher.py:43-48) guards this with if self.closed: ... return — worth the same guard here.

    Fix this →%20at%20line%20144-146%20calls%20self.write_stream.close()%20unconditionally%20even%20if%20self.closed%20is%20already%20True.%20Make%20it%20idempotent%20like%20BufferedPublisher.close()%20in%20instro%2Flib%2Fpublishers%2Fpublisher.py%20(around%20line%2043)%3A%20return%20early%20(optionally%20logging)%20if%20self.closed%20is%20already%20True.%20Branch%3A%20issue-709-notebook-cards&repo=nominal-io/instro)

    claude[bot] claude[bot] commented on code on Nov 03, 2026 19:30 UTC
    Code Review
    instro/lib/publishers/nominal_core.py:1
    @@ -34,28 +42,67 @@ def __init__(
                 profile: Named profile from the on-disk config (defaults to ``"default"``).
                 api_key: Inline API key; falls back to on-disk credentials when omitted.
                     See https://docs.nominal.io/core/sdk/python-client/authentication#using-the-api-key
    -        """
    -        self._rid = dataset_rid
    +            dataset: An already-fetched dataset to write to, instead of ``dataset_rid``.
    +            client: An existing `NominalClient` to fetch ``dataset_rid`` with, instead of ``profile`` or ``api_key``.
    +            base_url: API base URL for ``api_key``, such as ``"https://api.gov.nominal.io/api"``.
    +
    +        Raises:
    +            ValueError: If both or neither of ``dataset_rid`` and ``dataset`` are given, or credential options
    +                conflict.
     
    -        # Enforce valid configuration for file fallback functionality
    -        data_format: Literal["rust_experimental"] | None = "rust_experimental"
    -        if file_fallback is not None:
    -            if not str(file_fallback).endswith(".avro"):
    -                raise ValueError(f"The 'file_fallback' path must end with '.avro'. You provided: '{file_fallback}'.")
    +        Example:
    +            .. code-block:: python
     
    -        self._client, self._dataset = _resolve_nominal_client_and_dataset(self._rid, profile, api_key)
    +                from nominal.core import NominalClient
    +                from instro.lib.publishers import NominalCorePublisher
     
    -        ws_signature = inspect.signature(self._dataset.get_write_stream)
    +                publisher = NominalCorePublisher(dataset_rid="ri.catalog.main.dataset.abc123", profile="staging")
    +
    +                client = NominalClient.from_profile("staging")
    +                publisher = NominalCorePublisher(dataset=client.get_dataset("ri.catalog.main.dataset.abc123"))
    +        """
    +        if (dataset_rid is None) == (dataset is None):
    +            raise ValueError("Pass exactly one of dataset_rid or dataset.")
    +        if file_fallback is not None and not str(file_fallback).endswith(".avro"):
    +            raise ValueError(f"The 'file_fallback' path must end with '.avro'. You provided: '{file_fallback}'.")
    +
    +        self.client: NominalClient | None
    +        """The client used to fetch the dataset, or `None` when ``dataset`` was passed in directly."""
    +        self.dataset: Dataset
    +        if dataset is not None:
    +            if profile or api_key or base_url:
    +                raise ValueError("A Dataset carries its own credentials; don't pass profile, api_key or base_url.")
    +            self.client = client
    +            self.dataset = dataset
    +        else:
    +            assert dataset_rid is not None
    +            self.client, self.dataset = _resolve_nominal_client_and_dataset(
    +                dataset_rid, profile, api_key, client=client, base_url=base_url
    +            )
     
    -        self._write_stream = self._dataset.get_write_stream(
    -            batch_size=batch_size or ws_signature.parameters["batch_size"].default,
    -            max_wait=max_wait or ws_signature.parameters["max_wait"].default,
    -            data_format=data_format or ws_signature.parameters["data_format"].default,
    +        self.dataset_rid: str = self.dataset.rid
    +        self.profile: str | None = None if (dataset or client or api_key) else (profile or "default")
    +        """The on-disk profile the credentials came from, or `None` when they came from elsewhere."""
    +        self.base_url: str | None = base_url
    +        self.file_fallback: pathlib.Path | None = file_fallback
    +        self.closed: bool = False
    +
    +        ws_signature = inspect.signature(self.dataset.get_write_stream)
    +        self.batch_size: int = batch_size or ws_signature.parameters["batch_size"].default
    +        self.max_wait: timedelta = max_wait or ws_signature.parameters["max_wait"].default

    max_wait or ws_signature.parameters["max_wait"].default treats timedelta(0) as falsy, so an explicit max_wait=timedelta(0) (immediate flush) is silently replaced by the API default. Same pattern on line 84 (profile or "default" promotes profile="") and line 91 (batch_size or default). Use is not None checks instead.

    arsenovicAtNominal arsenovicAtNominal commented on code on Nov 04, 2026 19:28 UTC
    Code Review
    instro/lib/publishers/nominal_core.py:1
    @@ -87,12 +134,49 @@ def __publish_measurement(self, data: Measurement):
     
         def __publish_command(self, data: Command):
             for ch_name in data.channel_data:
    -            self._write_stream.enqueue_batch(
    +            self.write_stream.enqueue_batch(
                     channel_name=ch_name,
                     timestamps=[data.timestamp],
                     values=[data.channel_data[ch_name]],
                     tags=data.tags,
                 )
     
         def close(self):
    -        self._write_stream.close()
    +        self.write_stream.close()
    +        self.closed = True
    +
    +    def _credentials(self) -> str:
    +        if self.profile is not None:
    +            return f"profile {self.profile!r}"
    +        if self.client is None:
    +            return "from the dataset passed in"
    +        return "API key" if self.base_url is None else f"API key, {self.base_url}"

    Fixed in 03804a0: the publisher now records whether a client was passed in, and _credentials() reports provided client for it (covered in test_client_fetches_the_dataset).

    arsenovicAtNominal arsenovicAtNominal commented on code on Nov 04, 2026 19:28 UTC
    Code Review
    instro/lib/publishers/nominal_core.py:1
    @@ -87,12 +134,49 @@ def __publish_measurement(self, data: Measurement):
     
         def __publish_command(self, data: Command):
             for ch_name in data.channel_data:
    -            self._write_stream.enqueue_batch(
    +            self.write_stream.enqueue_batch(
                     channel_name=ch_name,
                     timestamps=[data.timestamp],
                     values=[data.channel_data[ch_name]],
                     tags=data.tags,
                 )
     
         def close(self):
    -        self._write_stream.close()
    +        self.write_stream.close()
    +        self.closed = True
    +
    +    def _credentials(self) -> str:
    +        if self.profile is not None:
    +            return f"profile {self.profile!r}"
    +        if self.client is None:
    +            return "from the dataset passed in"
    +        return "API key" if self.base_url is None else f"API key, {self.base_url}"

    Fixed in 03804a0 together with the thread above: a directly passed client= now shows as provided client, and the test asserts it.

    arsenovicAtNominal arsenovicAtNominal commented on code on Nov 04, 2026 19:28 UTC
    Code Review
    instro/lib/publishers/channel_buffer.py:1
    @@ -182,6 +182,21 @@ def close(self) -> None:
                 self._timestamps.clear()
                 self._total_added_count.clear()
     
    +    def latest(self) -> dict[str, tuple[int, float | str]]:
    +        """Return the newest ``(timestamp, value)`` of every channel holding data, in insertion order. Never blocks on new data."""
    +        with self._condition:
    +            snapshot: dict[str, tuple[int, float | str]] = {}
    +            for channel_name in self._values:
    +                if channel_name in self._timestamps and self._points_in_buffer(channel_name):
    +                    snapshot[channel_name] = (
    +                        self._get_timestamps(channel_name, 1)[0],
    +                        self._get_values(channel_name, 1)[0],

    Fixed in 03804a0: DequeInMemoryPublisher (and the deque path of NumpyInMemoryPublisher) now read the last n items with islice(reversed(deque), n), so latest() copies one item per channel instead of the whole history while holding the lock.

    arsenovicAtNominal arsenovicAtNominal commented on code on Nov 04, 2026 19:28 UTC
    Code Review
    instro/lib/publishers/nominal_core.py:1
    @@ -87,12 +134,49 @@ def __publish_measurement(self, data: Measurement):
     
         def __publish_command(self, data: Command):
             for ch_name in data.channel_data:
    -            self._write_stream.enqueue_batch(
    +            self.write_stream.enqueue_batch(
                     channel_name=ch_name,
                     timestamps=[data.timestamp],
                     values=[data.channel_data[ch_name]],
                     tags=data.tags,
                 )
     
         def close(self):
    -        self._write_stream.close()
    +        self.write_stream.close()
    +        self.closed = True

    Fixed in 03804a0: close() now returns early with a warning when already closed, matching BufferedPublisher.close(). Added test_close_is_idempotent.

    arsenovicAtNominal arsenovicAtNominal commented on code on Nov 04, 2026 19:28 UTC
    Code Review
    instro/lib/publishers/nominal_core.py:1
    @@ -34,28 +42,67 @@ def __init__(
                 profile: Named profile from the on-disk config (defaults to ``"default"``).
                 api_key: Inline API key; falls back to on-disk credentials when omitted.
                     See https://docs.nominal.io/core/sdk/python-client/authentication#using-the-api-key
    -        """
    -        self._rid = dataset_rid
    +            dataset: An already-fetched dataset to write to, instead of ``dataset_rid``.
    +            client: An existing `NominalClient` to fetch ``dataset_rid`` with, instead of ``profile`` or ``api_key``.
    +            base_url: API base URL for ``api_key``, such as ``"https://api.gov.nominal.io/api"``.
    +
    +        Raises:
    +            ValueError: If both or neither of ``dataset_rid`` and ``dataset`` are given, or credential options
    +                conflict.
     
    -        # Enforce valid configuration for file fallback functionality
    -        data_format: Literal["rust_experimental"] | None = "rust_experimental"
    -        if file_fallback is not None:
    -            if not str(file_fallback).endswith(".avro"):
    -                raise ValueError(f"The 'file_fallback' path must end with '.avro'. You provided: '{file_fallback}'.")
    +        Example:
    +            .. code-block:: python
     
    -        self._client, self._dataset = _resolve_nominal_client_and_dataset(self._rid, profile, api_key)
    +                from nominal.core import NominalClient
    +                from instro.lib.publishers import NominalCorePublisher
     
    -        ws_signature = inspect.signature(self._dataset.get_write_stream)
    +                publisher = NominalCorePublisher(dataset_rid="ri.catalog.main.dataset.abc123", profile="staging")
    +
    +                client = NominalClient.from_profile("staging")
    +                publisher = NominalCorePublisher(dataset=client.get_dataset("ri.catalog.main.dataset.abc123"))
    +        """
    +        if (dataset_rid is None) == (dataset is None):
    +            raise ValueError("Pass exactly one of dataset_rid or dataset.")
    +        if file_fallback is not None and not str(file_fallback).endswith(".avro"):
    +            raise ValueError(f"The 'file_fallback' path must end with '.avro'. You provided: '{file_fallback}'.")
    +
    +        self.client: NominalClient | None
    +        """The client used to fetch the dataset, or `None` when ``dataset`` was passed in directly."""
    +        self.dataset: Dataset
    +        if dataset is not None:
    +            if profile or api_key or base_url:
    +                raise ValueError("A Dataset carries its own credentials; don't pass profile, api_key or base_url.")
    +            self.client = client
    +            self.dataset = dataset
    +        else:
    +            assert dataset_rid is not None
    +            self.client, self.dataset = _resolve_nominal_client_and_dataset(
    +                dataset_rid, profile, api_key, client=client, base_url=base_url
    +            )
     
    -        self._write_stream = self._dataset.get_write_stream(
    -            batch_size=batch_size or ws_signature.parameters["batch_size"].default,
    -            max_wait=max_wait or ws_signature.parameters["max_wait"].default,
    -            data_format=data_format or ws_signature.parameters["data_format"].default,
    +        self.dataset_rid: str = self.dataset.rid
    +        self.profile: str | None = None if (dataset or client or api_key) else (profile or "default")
    +        """The on-disk profile the credentials came from, or `None` when they came from elsewhere."""
    +        self.base_url: str | None = base_url
    +        self.file_fallback: pathlib.Path | None = file_fallback
    +        self.closed: bool = False
    +
    +        ws_signature = inspect.signature(self.dataset.get_write_stream)
    +        self.batch_size: int = batch_size or ws_signature.parameters["batch_size"].default
    +        self.max_wait: timedelta = max_wait or ws_signature.parameters["max_wait"].default

    Fixed in 03804a0 for batch_size, max_wait and file_fallback: they now use is not None, so max_wait=timedelta(0) is kept (new test). I left profile or "default" as is on purpose: _resolve_nominal_client also treats profile="" as "default" and loads that profile, so the label matches the credentials actually used.

    stefanv stefanv commented on code on Nov 11, 2026 07:47 UTC
    Code Review
    docs/library/notebook-display.md:1
    @@ -0,0 +1,64 @@
    +---
    +myst:
    +  html_meta:
    +    description: "See instruments and publishers as cards in Jupyter, VS Code and Colab notebooks"
    +---
    +
    +# Notebook display
    +
    +{.lead}
    +Instruments and publishers display as cards in Jupyter, VS Code and Colab notebooks. A card needs no setup and never talks to the hardware.
    +
    +## Overview
    +
    +In Jupyter, VS Code and Colab, an instrument or publisher at the end of a cell displays as a card. Outside a notebook, `repr()` gives a one-line summary.
    +
    +```python
    +from instro.psu import InstroPSU
    +from instro.psu.drivers import VirtualPSU
    +
    +psu = InstroPSU(name="bench", driver=VirtualPSU(), num_channels=2, dataset_rid="<dataset RID>")
    +psu.start()
    +psu  # shows the card
    +```
    +
    +An instrument's card shows:
    +
    +- its driver, and category details such as the channel count
    +- the background daemon: whether it runs, its interval, and the last loop time
    +- its publishers, with a link to the Nominal dataset each one writes to
    +- the latest value of every channel, once `start()` has been called
    +- its default tags
    +
    +A card shows only what `instro` already holds in memory, so displaying an instrument is safe while the background daemon runs.
    +
    +Each publisher has a card too. A {py:class}`~instro.lib.publishers.nominal_core.NominalCorePublisher` card shows the dataset with an **Open in Nominal** link, its RID with a copy button, where the credentials came from, and the stream settings. It never shows an API key.

    This level of detail may be unnecessary; I'd cut the whole sentence, but especially the part about never showing the API key.

    stefanv stefanv commented on code on Nov 11, 2026 07:58 UTC
    Code Review
    docs/library/notebook-display.md:1
    @@ -0,0 +1,64 @@
    +---
    +myst:
    +  html_meta:
    +    description: "See instruments and publishers as cards in Jupyter, VS Code and Colab notebooks"
    +---
    +
    +# Notebook display
    +
    +{.lead}
    +Instruments and publishers display as cards in Jupyter, VS Code and Colab notebooks. A card needs no setup and never talks to the hardware.
    +
    +## Overview
    +
    +In Jupyter, VS Code and Colab, an instrument or publisher at the end of a cell displays as a card. Outside a notebook, `repr()` gives a one-line summary.
    +
    +```python
    +from instro.psu import InstroPSU
    +from instro.psu.drivers import VirtualPSU
    +
    +psu = InstroPSU(name="bench", driver=VirtualPSU(), num_channels=2, dataset_rid="<dataset RID>")
    +psu.start()
    +psu  # shows the card
    +```
    +
    +An instrument's card shows:

    Is this rendered as a notebook already? If so, is it worth repeating the content of the card in words?

    I couldn't confirm what this looks like, so added a PR for build previews.

    stefanv stefanv commented on code on Nov 11, 2026 08:00 UTC
    Code Review
    docs/library/notebook-display.md:1
    @@ -0,0 +1,64 @@
    +---
    +myst:
    +  html_meta:
    +    description: "See instruments and publishers as cards in Jupyter, VS Code and Colab notebooks"
    +---
    +
    +# Notebook display
    +
    +{.lead}
    +Instruments and publishers display as cards in Jupyter, VS Code and Colab notebooks. A card needs no setup and never talks to the hardware.
    +
    +## Overview
    +
    +In Jupyter, VS Code and Colab, an instrument or publisher at the end of a cell displays as a card. Outside a notebook, `repr()` gives a one-line summary.
    +
    +```python
    +from instro.psu import InstroPSU
    +from instro.psu.drivers import VirtualPSU
    +
    +psu = InstroPSU(name="bench", driver=VirtualPSU(), num_channels=2, dataset_rid="<dataset RID>")
    +psu.start()
    +psu  # shows the card
    +```
    +
    +An instrument's card shows:
    +
    +- its driver, and category details such as the channel count
    +- the background daemon: whether it runs, its interval, and the last loop time
    +- its publishers, with a link to the Nominal dataset each one writes to
    +- the latest value of every channel, once `start()` has been called
    +- its default tags
    +
    +A card shows only what `instro` already holds in memory, so displaying an instrument is safe while the background daemon runs.
    +
    +Each publisher has a card too. A {py:class}`~instro.lib.publishers.nominal_core.NominalCorePublisher` card shows the dataset with an **Open in Nominal** link, its RID with a copy button, where the credentials came from, and the stream settings. It never shows an API key.
    +
    +## Display options
    +
    +{py:func}`~instro.lib._display.set_display_options` changes every card, as a call or for the length of a `with` block:

    It's not typical to recommend using internal functions in Python; should probably be instro.lib.set_display_options?

    stefanv stefanv commented on code on Nov 11, 2026 08:02 UTC
    Code Review
    docs/library/notebook-display.md:1
    @@ -0,0 +1,64 @@
    +---
    +myst:
    +  html_meta:
    +    description: "See instruments and publishers as cards in Jupyter, VS Code and Colab notebooks"
    +---
    +
    +# Notebook display
    +
    +{.lead}
    +Instruments and publishers display as cards in Jupyter, VS Code and Colab notebooks. A card needs no setup and never talks to the hardware.
    +
    +## Overview
    +
    +In Jupyter, VS Code and Colab, an instrument or publisher at the end of a cell displays as a card. Outside a notebook, `repr()` gives a one-line summary.
    +
    +```python
    +from instro.psu import InstroPSU
    +from instro.psu.drivers import VirtualPSU
    +
    +psu = InstroPSU(name="bench", driver=VirtualPSU(), num_channels=2, dataset_rid="<dataset RID>")
    +psu.start()
    +psu  # shows the card
    +```
    +
    +An instrument's card shows:
    +
    +- its driver, and category details such as the channel count
    +- the background daemon: whether it runs, its interval, and the last loop time
    +- its publishers, with a link to the Nominal dataset each one writes to
    +- the latest value of every channel, once `start()` has been called
    +- its default tags
    +
    +A card shows only what `instro` already holds in memory, so displaying an instrument is safe while the background daemon runs.
    +
    +Each publisher has a card too. A {py:class}`~instro.lib.publishers.nominal_core.NominalCorePublisher` card shows the dataset with an **Open in Nominal** link, its RID with a copy button, where the credentials came from, and the stream settings. It never shows an API key.
    +
    +## Display options
    +
    +{py:func}`~instro.lib._display.set_display_options` changes every card, as a call or for the length of a `with` block:
    +
    +```python
    +from instro.lib import set_display_options
    +
    +set_display_options(timezone="America/Los_Angeles", time_precision="ms")
    +
    +with set_display_options(show_link=False):
    +    psu  # no request to resolve the Nominal workspace
    +```
    +
    +| Option | Default | Effect |
    +| --- | --- | --- |
    +| `style` | `"html"` | `"text"` keeps the plain `repr` |
    +| `timezone` | `"UTC"` | `"local"` or an IANA name |
    +| `time_format` | `"iso"` | `"readable"`: `2026-11-02 09:52:57 MST` |
    +| `time_precision` | `"s"` | `"ms"`, `"us"` or `"ns"`. Hovering shows the full value. |
    +| `show_link` | `True` | Link datasets to Nominal. The first link for a client makes one request to resolve its workspace. |
    +| `collapse_threshold` | `10` | Sections with more items start collapsed |
    +| `max_items` | `50` | Items listed per section |
    +
    +## Custom instruments and publishers
    +
    +A custom {py:class}`~instro.lib.Instrument` subclass gets a card without extra code. To add rows, override `_display_fields()` and return `(label, html)` pairs built from in-memory state only.

    A custom {py:class}`~instro.lib.Instrument` subclass gets a default card automatically. To customize the card, override `_display_fields()` and return `(label, html)` pairs built from in-memory state only.
    

    stefanv stefanv commented on code on Nov 11, 2026 08:04 UTC
    Code Review
    docs/library/notebook-display.md:1
    @@ -0,0 +1,64 @@
    +---
    +myst:
    +  html_meta:
    +    description: "See instruments and publishers as cards in Jupyter, VS Code and Colab notebooks"
    +---
    +
    +# Notebook display
    +
    +{.lead}
    +Instruments and publishers display as cards in Jupyter, VS Code and Colab notebooks. A card needs no setup and never talks to the hardware.
    +
    +## Overview
    +
    +In Jupyter, VS Code and Colab, an instrument or publisher at the end of a cell displays as a card. Outside a notebook, `repr()` gives a one-line summary.
    +
    +```python
    +from instro.psu import InstroPSU
    +from instro.psu.drivers import VirtualPSU
    +
    +psu = InstroPSU(name="bench", driver=VirtualPSU(), num_channels=2, dataset_rid="<dataset RID>")
    +psu.start()
    +psu  # shows the card
    +```
    +
    +An instrument's card shows:
    +
    +- its driver, and category details such as the channel count
    +- the background daemon: whether it runs, its interval, and the last loop time
    +- its publishers, with a link to the Nominal dataset each one writes to
    +- the latest value of every channel, once `start()` has been called
    +- its default tags
    +
    +A card shows only what `instro` already holds in memory, so displaying an instrument is safe while the background daemon runs.
    +
    +Each publisher has a card too. A {py:class}`~instro.lib.publishers.nominal_core.NominalCorePublisher` card shows the dataset with an **Open in Nominal** link, its RID with a copy button, where the credentials came from, and the stream settings. It never shows an API key.
    +
    +## Display options
    +
    +{py:func}`~instro.lib._display.set_display_options` changes every card, as a call or for the length of a `with` block:
    +
    +```python
    +from instro.lib import set_display_options
    +
    +set_display_options(timezone="America/Los_Angeles", time_precision="ms")
    +
    +with set_display_options(show_link=False):
    +    psu  # no request to resolve the Nominal workspace
    +```
    +
    +| Option | Default | Effect |
    +| --- | --- | --- |
    +| `style` | `"html"` | `"text"` keeps the plain `repr` |
    +| `timezone` | `"UTC"` | `"local"` or an IANA name |
    +| `time_format` | `"iso"` | `"readable"`: `2026-11-02 09:52:57 MST` |
    +| `time_precision` | `"s"` | `"ms"`, `"us"` or `"ns"`. Hovering shows the full value. |
    +| `show_link` | `True` | Link datasets to Nominal. The first link for a client makes one request to resolve its workspace. |
    +| `collapse_threshold` | `10` | Sections with more items start collapsed |
    +| `max_items` | `50` | Items listed per section |
    +
    +## Custom instruments and publishers
    +
    +A custom {py:class}`~instro.lib.Instrument` subclass gets a card without extra code. To add rows, override `_display_fields()` and return `(label, html)` pairs built from in-memory state only.
    +
    +A custom publisher appears in an instrument's card under its class name. Define `_display_summary()`, returning one line of HTML, to describe it there.

    This could be clearer.

    Between this and the above comment, I derive that _display_summary() is only for adding rows. What if you want to rewrite how a card looks?

    It may be better to have the user be able to override _display_summary() entirely, and to use super().display_summary() where they only want to append?

    stefanv stefanv commented on code on Nov 11, 2026 08:12 UTC
    Code Review
    docs/library/publishers.md:1
    @@ -84,15 +84,33 @@ Sends measurement and command data to [Nominal Core](https://nominal.io/products
     
     ```python
     NominalCorePublisher(
    -    dataset_rid: str,              # Required: RID of your Nominal Core dataset
    -    batch_size: int | None = None, # Optional: Batch size before writing
    +    dataset_rid: str | None = None,  # RID of your Nominal dataset (or pass dataset=)
    +    batch_size: int | None = None,   # Optional: Batch size before writing
         max_wait: timedelta | None = None,  # Optional: Max time before flush
         file_fallback: pathlib.Path | None = None,  # Optional: Path of fallback file (.avro) used if network connectivity is lost.
    -    profile: str | None = None,    # Optional: Nominal profile name
    -    api_key: str | None = None     # Optional: API key for authentication
    +    profile: str | None = None,      # Optional: Nominal profile name, "default" when omitted
    +    api_key: str | None = None,      # Optional: API key for authentication
    +    *,
    +    dataset: Dataset | None = None,  # Optional: an already-fetched nominal.core.Dataset, instead of dataset_rid

    Worth adding a field for this, vs interpreting dataset_rid as string | Dataset? Ideally would have used only dataset (which then also accepts rid), and deprecate dataset_id; is that too inconsistent with what's happening elsewhere?

    stefanv stefanv commented on code on Nov 11, 2026 08:13 UTC
    Code Review
    docs/library/publishers.md:1
    @@ -84,15 +84,33 @@ Sends measurement and command data to [Nominal Core](https://nominal.io/products
     
     ```python
     NominalCorePublisher(
    -    dataset_rid: str,              # Required: RID of your Nominal Core dataset
    -    batch_size: int | None = None, # Optional: Batch size before writing
    +    dataset_rid: str | None = None,  # RID of your Nominal dataset (or pass dataset=)
    +    batch_size: int | None = None,   # Optional: Batch size before writing
         max_wait: timedelta | None = None,  # Optional: Max time before flush
         file_fallback: pathlib.Path | None = None,  # Optional: Path of fallback file (.avro) used if network connectivity is lost.
    -    profile: str | None = None,    # Optional: Nominal profile name
    -    api_key: str | None = None     # Optional: API key for authentication
    +    profile: str | None = None,      # Optional: Nominal profile name, "default" when omitted
    +    api_key: str | None = None,      # Optional: API key for authentication
    +    *,
    +    dataset: Dataset | None = None,  # Optional: an already-fetched nominal.core.Dataset, instead of dataset_rid
    +    client: NominalClient | None = None,  # Optional: an existing NominalClient, instead of profile or api_key
    +    base_url: str | None = None,     # Optional: API base URL to use with api_key
     )
     ```
     
    +Pass exactly one of `dataset_rid` and `dataset`. Credentials come from `client`, `api_key` (with `base_url`), or the on-disk `profile`, and combining them raises `ValueError`.

    Yes, this confirms my feeling that these are the same parameter :)

    Maybe credential should also accept client | key | profile.

    stefanv stefanv commented on Nov 11, 2026 08:19 UTC
    Reviewer

    Overall looks good; just some quick API design questions.

    stefanv stefanv commented on code on Nov 11, 2026 08:29 UTC
    Code Review
    docs/library/notebook-display.md:1
    @@ -0,0 +1,64 @@
    +---
    +myst:
    +  html_meta:
    +    description: "See instruments and publishers as cards in Jupyter, VS Code and Colab notebooks"
    +---
    +
    +# Notebook display
    +
    +{.lead}
    +Instruments and publishers display as cards in Jupyter, VS Code and Colab notebooks. A card needs no setup and never talks to the hardware.
    +
    +## Overview
    +
    +In Jupyter, VS Code and Colab, an instrument or publisher at the end of a cell displays as a card. Outside a notebook, `repr()` gives a one-line summary.
    +
    +```python
    +from instro.psu import InstroPSU
    +from instro.psu.drivers import VirtualPSU
    +
    +psu = InstroPSU(name="bench", driver=VirtualPSU(), num_channels=2, dataset_rid="<dataset RID>")
    +psu.start()
    +psu  # shows the card
    +```
    +
    +An instrument's card shows:

    Note to self: notebook running is added in https://github.com/nominal-io/instro/pull/713

    arsenovicAtNominal arsenovicAtNominal commented on code on Nov 11, 2026 11:39 UTC
    Code Review
    docs/library/notebook-display.md:1
    @@ -0,0 +1,64 @@
    +---
    +myst:
    +  html_meta:
    +    description: "See instruments and publishers as cards in Jupyter, VS Code and Colab notebooks"
    +---
    +
    +# Notebook display
    +
    +{.lead}
    +Instruments and publishers display as cards in Jupyter, VS Code and Colab notebooks. A card needs no setup and never talks to the hardware.
    +
    +## Overview
    +
    +In Jupyter, VS Code and Colab, an instrument or publisher at the end of a cell displays as a card. Outside a notebook, `repr()` gives a one-line summary.
    +
    +```python
    +from instro.psu import InstroPSU
    +from instro.psu.drivers import VirtualPSU
    +
    +psu = InstroPSU(name="bench", driver=VirtualPSU(), num_channels=2, dataset_rid="<dataset RID>")
    +psu.start()
    +psu  # shows the card
    +```
    +
    +An instrument's card shows:
    +
    +- its driver, and category details such as the channel count
    +- the background daemon: whether it runs, its interval, and the last loop time
    +- its publishers, with a link to the Nominal dataset each one writes to
    +- the latest value of every channel, once `start()` has been called
    +- its default tags
    +
    +A card shows only what `instro` already holds in memory, so displaying an instrument is safe while the background daemon runs.
    +
    +Each publisher has a card too. A {py:class}`~instro.lib.publishers.nominal_core.NominalCorePublisher` card shows the dataset with an **Open in Nominal** link, its RID with a copy button, where the credentials came from, and the stream settings. It never shows an API key.

    Cut in 20797ec. The NominalCorePublisher card is now one sentence ("links its dataset in Nominal"), with no mention of the API key.

    arsenovicAtNominal arsenovicAtNominal commented on code on Nov 11, 2026 11:39 UTC
    Code Review
    docs/library/notebook-display.md:1
    @@ -0,0 +1,64 @@
    +---
    +myst:
    +  html_meta:
    +    description: "See instruments and publishers as cards in Jupyter, VS Code and Colab notebooks"
    +---
    +
    +# Notebook display
    +
    +{.lead}
    +Instruments and publishers display as cards in Jupyter, VS Code and Colab notebooks. A card needs no setup and never talks to the hardware.
    +
    +## Overview
    +
    +In Jupyter, VS Code and Colab, an instrument or publisher at the end of a cell displays as a card. Outside a notebook, `repr()` gives a one-line summary.
    +
    +```python
    +from instro.psu import InstroPSU
    +from instro.psu.drivers import VirtualPSU
    +
    +psu = InstroPSU(name="bench", driver=VirtualPSU(), num_channels=2, dataset_rid="<dataset RID>")
    +psu.start()
    +psu  # shows the card
    +```
    +
    +An instrument's card shows:

    Not rendered in this PR; #713 adds the executed example notebook. Either way, I replaced the bullet list with one sentence in 20797ec, so the page doesn't repeat the card.

    arsenovicAtNominal arsenovicAtNominal commented on code on Nov 11, 2026 11:39 UTC
    Code Review
    docs/library/notebook-display.md:1
    @@ -0,0 +1,64 @@
    +---
    +myst:
    +  html_meta:
    +    description: "See instruments and publishers as cards in Jupyter, VS Code and Colab notebooks"
    +---
    +
    +# Notebook display
    +
    +{.lead}
    +Instruments and publishers display as cards in Jupyter, VS Code and Colab notebooks. A card needs no setup and never talks to the hardware.
    +
    +## Overview
    +
    +In Jupyter, VS Code and Colab, an instrument or publisher at the end of a cell displays as a card. Outside a notebook, `repr()` gives a one-line summary.
    +
    +```python
    +from instro.psu import InstroPSU
    +from instro.psu.drivers import VirtualPSU
    +
    +psu = InstroPSU(name="bench", driver=VirtualPSU(), num_channels=2, dataset_rid="<dataset RID>")
    +psu.start()
    +psu  # shows the card
    +```
    +
    +An instrument's card shows:
    +
    +- its driver, and category details such as the channel count
    +- the background daemon: whether it runs, its interval, and the last loop time
    +- its publishers, with a link to the Nominal dataset each one writes to
    +- the latest value of every channel, once `start()` has been called
    +- its default tags
    +
    +A card shows only what `instro` already holds in memory, so displaying an instrument is safe while the background daemon runs.
    +
    +Each publisher has a card too. A {py:class}`~instro.lib.publishers.nominal_core.NominalCorePublisher` card shows the dataset with an **Open in Nominal** link, its RID with a copy button, where the credentials came from, and the stream settings. It never shows an API key.
    +
    +## Display options
    +
    +{py:func}`~instro.lib._display.set_display_options` changes every card, as a call or for the length of a `with` block:

    Done in 20797ec: the guide links instro.lib.set_display_options, and the reference page (docs/ref/library/display.md) now lists DisplayOptions and both functions under instro.lib instead of instro.lib._display.

    arsenovicAtNominal arsenovicAtNominal commented on code on Nov 11, 2026 11:39 UTC
    Code Review
    docs/library/notebook-display.md:1
    @@ -0,0 +1,64 @@
    +---
    +myst:
    +  html_meta:
    +    description: "See instruments and publishers as cards in Jupyter, VS Code and Colab notebooks"
    +---
    +
    +# Notebook display
    +
    +{.lead}
    +Instruments and publishers display as cards in Jupyter, VS Code and Colab notebooks. A card needs no setup and never talks to the hardware.
    +
    +## Overview
    +
    +In Jupyter, VS Code and Colab, an instrument or publisher at the end of a cell displays as a card. Outside a notebook, `repr()` gives a one-line summary.
    +
    +```python
    +from instro.psu import InstroPSU
    +from instro.psu.drivers import VirtualPSU
    +
    +psu = InstroPSU(name="bench", driver=VirtualPSU(), num_channels=2, dataset_rid="<dataset RID>")
    +psu.start()
    +psu  # shows the card
    +```
    +
    +An instrument's card shows:
    +
    +- its driver, and category details such as the channel count
    +- the background daemon: whether it runs, its interval, and the last loop time
    +- its publishers, with a link to the Nominal dataset each one writes to
    +- the latest value of every channel, once `start()` has been called
    +- its default tags
    +
    +A card shows only what `instro` already holds in memory, so displaying an instrument is safe while the background daemon runs.
    +
    +Each publisher has a card too. A {py:class}`~instro.lib.publishers.nominal_core.NominalCorePublisher` card shows the dataset with an **Open in Nominal** link, its RID with a copy button, where the credentials came from, and the stream settings. It never shows an API key.
    +
    +## Display options
    +
    +{py:func}`~instro.lib._display.set_display_options` changes every card, as a call or for the length of a `with` block:
    +
    +```python
    +from instro.lib import set_display_options
    +
    +set_display_options(timezone="America/Los_Angeles", time_precision="ms")
    +
    +with set_display_options(show_link=False):
    +    psu  # no request to resolve the Nominal workspace
    +```
    +
    +| Option | Default | Effect |
    +| --- | --- | --- |
    +| `style` | `"html"` | `"text"` keeps the plain `repr` |
    +| `timezone` | `"UTC"` | `"local"` or an IANA name |
    +| `time_format` | `"iso"` | `"readable"`: `2026-11-02 09:52:57 MST` |
    +| `time_precision` | `"s"` | `"ms"`, `"us"` or `"ns"`. Hovering shows the full value. |
    +| `show_link` | `True` | Link datasets to Nominal. The first link for a client makes one request to resolve its workspace. |
    +| `collapse_threshold` | `10` | Sections with more items start collapsed |
    +| `max_items` | `50` | Items listed per section |
    +
    +## Custom instruments and publishers
    +
    +A custom {py:class}`~instro.lib.Instrument` subclass gets a card without extra code. To add rows, override `_display_fields()` and return `(label, html)` pairs built from in-memory state only.

    Applied in 20797ec.

    arsenovicAtNominal arsenovicAtNominal commented on code on Nov 11, 2026 11:39 UTC
    Code Review
    docs/library/notebook-display.md:1
    @@ -0,0 +1,64 @@
    +---
    +myst:
    +  html_meta:
    +    description: "See instruments and publishers as cards in Jupyter, VS Code and Colab notebooks"
    +---
    +
    +# Notebook display
    +
    +{.lead}
    +Instruments and publishers display as cards in Jupyter, VS Code and Colab notebooks. A card needs no setup and never talks to the hardware.
    +
    +## Overview
    +
    +In Jupyter, VS Code and Colab, an instrument or publisher at the end of a cell displays as a card. Outside a notebook, `repr()` gives a one-line summary.
    +
    +```python
    +from instro.psu import InstroPSU
    +from instro.psu.drivers import VirtualPSU
    +
    +psu = InstroPSU(name="bench", driver=VirtualPSU(), num_channels=2, dataset_rid="<dataset RID>")
    +psu.start()
    +psu  # shows the card
    +```
    +
    +An instrument's card shows:
    +
    +- its driver, and category details such as the channel count
    +- the background daemon: whether it runs, its interval, and the last loop time
    +- its publishers, with a link to the Nominal dataset each one writes to
    +- the latest value of every channel, once `start()` has been called
    +- its default tags
    +
    +A card shows only what `instro` already holds in memory, so displaying an instrument is safe while the background daemon runs.
    +
    +Each publisher has a card too. A {py:class}`~instro.lib.publishers.nominal_core.NominalCorePublisher` card shows the dataset with an **Open in Nominal** link, its RID with a copy button, where the credentials came from, and the stream settings. It never shows an API key.
    +
    +## Display options
    +
    +{py:func}`~instro.lib._display.set_display_options` changes every card, as a call or for the length of a `with` block:
    +
    +```python
    +from instro.lib import set_display_options
    +
    +set_display_options(timezone="America/Los_Angeles", time_precision="ms")
    +
    +with set_display_options(show_link=False):
    +    psu  # no request to resolve the Nominal workspace
    +```
    +
    +| Option | Default | Effect |
    +| --- | --- | --- |
    +| `style` | `"html"` | `"text"` keeps the plain `repr` |
    +| `timezone` | `"UTC"` | `"local"` or an IANA name |
    +| `time_format` | `"iso"` | `"readable"`: `2026-11-02 09:52:57 MST` |
    +| `time_precision` | `"s"` | `"ms"`, `"us"` or `"ns"`. Hovering shows the full value. |
    +| `show_link` | `True` | Link datasets to Nominal. The first link for a client makes one request to resolve its workspace. |
    +| `collapse_threshold` | `10` | Sections with more items start collapsed |
    +| `max_items` | `50` | Items listed per section |
    +
    +## Custom instruments and publishers
    +
    +A custom {py:class}`~instro.lib.Instrument` subclass gets a card without extra code. To add rows, override `_display_fields()` and return `(label, html)` pairs built from in-memory state only.
    +
    +A custom publisher appears in an instrument's card under its class name. Define `_display_summary()`, returning one line of HTML, to describe it there.

    Agreed, overriding and calling super() is the model; the docs didn't say so. Clarified in 20797ec:

  • _display_fields() returns all the category rows, so InstroPSU's returns the channel count. A subclass that overrides it without super() drops those rows. The guide now shows [*super()._display_fields(), (label, html)].

  • To replace the whole card, override _repr_html_().

  • _display_summary() is the one-line description of a publisher in an instrument's card, not rows. A subclass of a built-in publisher can extend it with super()._display_summary().
  • I didn't add a default _display_summary to the Publisher Protocol, because that would make it a required member for mypy and break duck-typed publishers. Publishers without it still show their class name.

    arsenovicAtNominal arsenovicAtNominal commented on code on Nov 11, 2026 11:39 UTC
    Code Review
    docs/library/publishers.md:1
    @@ -84,15 +84,33 @@ Sends measurement and command data to [Nominal Core](https://nominal.io/products
     
     ```python
     NominalCorePublisher(
    -    dataset_rid: str,              # Required: RID of your Nominal Core dataset
    -    batch_size: int | None = None, # Optional: Batch size before writing
    +    dataset_rid: str | None = None,  # RID of your Nominal dataset (or pass dataset=)
    +    batch_size: int | None = None,   # Optional: Batch size before writing
         max_wait: timedelta | None = None,  # Optional: Max time before flush
         file_fallback: pathlib.Path | None = None,  # Optional: Path of fallback file (.avro) used if network connectivity is lost.
    -    profile: str | None = None,    # Optional: Nominal profile name
    -    api_key: str | None = None     # Optional: API key for authentication
    +    profile: str | None = None,      # Optional: Nominal profile name, "default" when omitted
    +    api_key: str | None = None,      # Optional: API key for authentication
    +    *,
    +    dataset: Dataset | None = None,  # Optional: an already-fetched nominal.core.Dataset, instead of dataset_rid

    Done in 20797ec. The first argument is now dataset: str | Dataset, a RID or a fetched Dataset. Callers who pass the RID positionally don't change.

    I kept dataset_rid= as a silent keyword alias rather than deprecating it in this PR. About 60 call sites use it (examples, docs, hardware tests, instro-unstable), and #724 rewrites many of the same example files. A DeprecationWarning would show on every example run as a script. Once #724 lands, I'd do the migration and the deprecation in a follow-up. Instrument(dataset_rid=...) and the JSON config key stay as they are, since they only ever take a RID.

    arsenovicAtNominal arsenovicAtNominal commented on code on Nov 11, 2026 11:39 UTC
    Code Review
    docs/library/publishers.md:1
    @@ -84,15 +84,33 @@ Sends measurement and command data to [Nominal Core](https://nominal.io/products
     
     ```python
     NominalCorePublisher(
    -    dataset_rid: str,              # Required: RID of your Nominal Core dataset
    -    batch_size: int | None = None, # Optional: Batch size before writing
    +    dataset_rid: str | None = None,  # RID of your Nominal dataset (or pass dataset=)
    +    batch_size: int | None = None,   # Optional: Batch size before writing
         max_wait: timedelta | None = None,  # Optional: Max time before flush
         file_fallback: pathlib.Path | None = None,  # Optional: Path of fallback file (.avro) used if network connectivity is lost.
    -    profile: str | None = None,    # Optional: Nominal profile name
    -    api_key: str | None = None     # Optional: API key for authentication
    +    profile: str | None = None,      # Optional: Nominal profile name, "default" when omitted
    +    api_key: str | None = None,      # Optional: API key for authentication
    +    *,
    +    dataset: Dataset | None = None,  # Optional: an already-fetched nominal.core.Dataset, instead of dataset_rid
    +    client: NominalClient | None = None,  # Optional: an existing NominalClient, instead of profile or api_key
    +    base_url: str | None = None,     # Optional: API base URL to use with api_key
     )
     ```
     
    +Pass exactly one of `dataset_rid` and `dataset`. Credentials come from `client`, `api_key` (with `base_url`), or the on-disk `profile`, and combining them raises `ValueError`.

    I went a slightly different way in 20797ec. A single credential would have to tell a profile name from an API key, and both are strings. Instead, I dropped client= and base_url=, which this PR had added. A Dataset already carries its client's credentials, so any client is covered by NominalCorePublisher(client.get_dataset(rid)), including an API key with another base URL (documented in publishers.md). The remaining credential options are profile and api_key, the same as on main. Instrument(dataset_rid=..., nominal_client=...) now fetches the dataset with that client.

    arsenovicAtNominal arsenovicAtNominal commented on code on Nov 12, 2026 11:54 UTC
    Code Review
    docs/library/notebook-display.md:1
    @@ -0,0 +1,64 @@
    +---
    +myst:
    +  html_meta:
    +    description: "See instruments and publishers as cards in Jupyter, VS Code and Colab notebooks"
    +---
    +
    +# Notebook display
    +
    +{.lead}
    +Instruments and publishers display as cards in Jupyter, VS Code and Colab notebooks. A card needs no setup and never talks to the hardware.
    +
    +## Overview
    +
    +In Jupyter, VS Code and Colab, an instrument or publisher at the end of a cell displays as a card. Outside a notebook, `repr()` gives a one-line summary.
    +
    +```python
    +from instro.psu import InstroPSU
    +from instro.psu.drivers import VirtualPSU
    +
    +psu = InstroPSU(name="bench", driver=VirtualPSU(), num_channels=2, dataset_rid="<dataset RID>")
    +psu.start()
    +psu  # shows the card
    +```
    +
    +An instrument's card shows:
    +
    +- its driver, and category details such as the channel count
    +- the background daemon: whether it runs, its interval, and the last loop time
    +- its publishers, with a link to the Nominal dataset each one writes to
    +- the latest value of every channel, once `start()` has been called
    +- its default tags
    +
    +A card shows only what `instro` already holds in memory, so displaying an instrument is safe while the background daemon runs.
    +
    +Each publisher has a card too. A {py:class}`~instro.lib.publishers.nominal_core.NominalCorePublisher` card shows the dataset with an **Open in Nominal** link, its RID with a copy button, where the credentials came from, and the stream settings. It never shows an API key.
    +
    +## Display options
    +
    +{py:func}`~instro.lib._display.set_display_options` changes every card, as a call or for the length of a `with` block:
    +
    +```python
    +from instro.lib import set_display_options
    +
    +set_display_options(timezone="America/Los_Angeles", time_precision="ms")
    +
    +with set_display_options(show_link=False):
    +    psu  # no request to resolve the Nominal workspace
    +```
    +
    +| Option | Default | Effect |
    +| --- | --- | --- |
    +| `style` | `"html"` | `"text"` keeps the plain `repr` |
    +| `timezone` | `"UTC"` | `"local"` or an IANA name |
    +| `time_format` | `"iso"` | `"readable"`: `2026-11-02 09:52:57 MST` |
    +| `time_precision` | `"s"` | `"ms"`, `"us"` or `"ns"`. Hovering shows the full value. |
    +| `show_link` | `True` | Link datasets to Nominal. The first link for a client makes one request to resolve its workspace. |
    +| `collapse_threshold` | `10` | Sections with more items start collapsed |
    +| `max_items` | `50` | Items listed per section |
    +
    +## Custom instruments and publishers
    +
    +A custom {py:class}`~instro.lib.Instrument` subclass gets a card without extra code. To add rows, override `_display_fields()` and return `(label, html)` pairs built from in-memory state only.
    +
    +A custom publisher appears in an instrument's card under its class name. Define `_display_summary()`, returning one line of HTML, to describe it there.

    Small update since my last reply: as of 69b3f8c, PSU, scope and AWG no longer override _display_fields(). Their override was the same "Channel count" row three times, so the base card now reads _num_channels with getattr, the same way it already handles _driver. Built-in instruments have no _display_fields() override now, but the guide still recommends starting from super()._display_fields().

    Assignees
    arsenovicAtNominal arsenovicAtNominal
    Labels
    risk: low confidence: 85.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 85.5% (HIGH) · Higher = larger blast radius
    85.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 85.8% · Lower = rushed or shallow review
    85.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 12.1% · Safe to merge
    12.1%