> ## Documentation Index
> Fetch the complete documentation index at: https://docs.generalrobotics.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# GenericClient

> A generic Zenoh client that can handle arbitrary message types and processing functions

```python theme={null}
from grid_sim_client.isaac import GenericClient
```

A generic Zenoh client that can handle arbitrary message types and processing functions.

This class inherits from ZenohClient and provides functionality for publishing and
processing generic messages with optional custom processing functions.

## Fields

<ResponseField name="msg_type" type="str">
  The message type
</ResponseField>

<ResponseField name="fn" type="callable">
  Optional function for custom message processing
</ResponseField>

<ResponseField name="msg">
  The most recently published/received message
</ResponseField>

## Constructor

```python Signature theme={null}
GenericClient(
    *,
    client_dict: dict,
    agent_dict: Optional[dict] = None,
    shared_session: Any = None,
)
```

Initialize the generic client.

Note: \{
For generic client, you also need to include the following keys:

* "msg\_type": The message type (e.g., "Bool", "Twist", "Pose")
* "fn": The function to process the message
  }

<ParamField body="client_dict" type="dict" required>
  Configuration dictionary for the client
</ParamField>

<ParamField body="agent_dict" type="dict, optional">
  Dictionary of agent parameters. Defaults to None.
</ParamField>

<ParamField body="shared_session">
  Optional shared Zenoh session. Defaults to None.
</ParamField>

## Methods

### `getLatestMessage()`

```python Signature theme={null}
getLatestMessage() -> Any
```

Return the most recent message from the subscription queue.

Blocks for up to one second waiting for a message.

**Returns:**

The raw payload bytes of the latest message, or `None` if no
message was received within the timeout.

### `get_msg()`

```python Signature theme={null}
get_msg() -> Any
```

Get the most recent message.

**Returns:**

The most recently published/received message

### `msg_cb()`

```python Signature theme={null}
msg_cb(sample: Any) -> None
```

Handle an incoming Zenoh sample by storing its payload in the queue.

<ParamField body="sample" required>
  The Zenoh sample received from the subscription.
</ParamField>

### `process_latest_msg()`

```python Signature theme={null}
process_latest_msg() -> None
```

Process the latest received message.

Gets the latest message, deserializes it using CDR or JSON fallback,
and processes it with the configured function if one exists.

**Returns:**

None

### `publish()`

```python Signature theme={null}
publish(data: bytes) -> None
```

Publish data to the topic.

<ParamField body="data" required>
  Raw bytes to publish on the configured topic.
</ParamField>

### `publish_msg()`

```python Signature theme={null}
publish_msg(msg: Any) -> None
```

Publish a message to the configured topic.

If a processing function is defined, it will be called before publishing.

<ParamField body="msg" required>
  The message to publish (can be a pycdr2 IdlStruct, dict, or primitive)
</ParamField>

**Raises:**

Exception: If the message is None

### `run()`

```python Signature theme={null}
run() -> None
```

Start the client by declaring a subscriber or publisher on the session.

### `stop()`

```python Signature theme={null}
stop() -> None
```

Undeclare the subscriber and close the owned Zenoh session if any.


## Related topics

- [GRID Cortex Client](/models/cortex.md)
- [grid-cortex-client](/python-api/grid-cortex-client/overview.md)
- [CortexClient](/python-api/grid-cortex-client/cortexclient.md)
- [AsyncCortexClient](/python-api/grid-cortex-client/asynccortexclient.md)
- [CortexHubClient](/python-api/grid-cortex-client/cortexhubclient.md)
