# attach()

## attach( instrument: T, name: str, publishers: list[Publisher] | None = None, *, channel_map: ChannelMap | dict[str, Any] | str | Path | None = None, poll: list[str] | None = None, **kwargs: Any, ) → PymeasureInstrument[T][source]

Start publishing an existing pymeasure instrument’s traffic, without changing how it is used.

Your code keeps the pymeasure object and keeps calling it; this only adds publishing. Closing
the returned handle flushes and closes the publishers and detaches, but leaves the instrument
connected (`close_device=False`).

Example:

```
keithley = Keithley2400("GPIB::24")              # existing code
recorder = attach(keithley, "smu", [FilePublisher(format="jsonl")])
keithley.source_voltage = 1.0                    # existing code, now published
recorder.close()
```

Parameters:
:   - **instrument**

      The pymeasure instrument.
    - **name**

      Channel-name prefix for everything published.
    - **publishers**

      Publishers that receive the commands and measurements.
    - **channel_map**

      See [`PymeasureInstrument`](https://dev.nominal.io/instro/ref/library/instro.pymeasure.PymeasureInstrument.md#instro.pymeasure.PymeasureInstrument "instro.pymeasure.PymeasureInstrument").
    - **poll**

      See [`PymeasureInstrument`](https://dev.nominal.io/instro/ref/library/instro.pymeasure.PymeasureInstrument.md#instro.pymeasure.PymeasureInstrument "instro.pymeasure.PymeasureInstrument").
    - ****kwargs**

      Any other [`PymeasureInstrument`](https://dev.nominal.io/instro/ref/library/instro.pymeasure.PymeasureInstrument.md#instro.pymeasure.PymeasureInstrument "instro.pymeasure.PymeasureInstrument") argument, default tags, or `dataset_rid=`.

Returns:
:   The [`PymeasureInstrument`](https://dev.nominal.io/instro/ref/library/instro.pymeasure.PymeasureInstrument.md#instro.pymeasure.PymeasureInstrument "instro.pymeasure.PymeasureInstrument") doing the publishing; use it as a context manager or call `close()`.
