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

# shared_memory_image_client_python.c File Reference

Part of [Shared Memory Image Transport](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/group__shmem.md)

Python interface to the [shared\_memory\_image\_client.h](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client_8h.md) API.

`#include <Python.h>`\
&#x20;`#include "shared_memory_image_client_priv.h"`\


[Go to the source code of this file.](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client__python_8c_source)

## Macros

| Type | Name |
| - | - |
| #define | [MAX\_STREAMS](#a4a1e12ec49840b798c6413a8f6c947a9) 50 |

## Functions

| Type | Name |
| - | - |
| stream\_id | [stream\_create](#a68584fd5e8630714c738fc30ad19fa03) (str filename, int options=[IMAGESTREAM\_OPTIONS\_NONE](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client_8h.md#a7fbe522f7a46875a755f07c8ff69e2df)) Create a shared memory image stream. |
| frame | [stream\_lock](#ac78db99f06d47f7718fdcac4ae3cc374) (stream\_id id) Get any available image frame. |
| [SharedMemoryImageError](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client_8h.md#a0496a9a3db499fa9145fe97d2e6dae9a) | [stream\_unlock](#a233ea80003a929e8e60aabd26a3b5c5e) (stream\_id id) Unlock the frame allocated by [stream\_lock()](#ac78db99f06d47f7718fdcac4ae3cc374). |
| [SharedMemoryImageError](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client_8h.md#a0496a9a3db499fa9145fe97d2e6dae9a) | [stream\_destroy](#af656cd2bf739307f1d52221d49da37ae) (stream\_id id) Close down and destroy a shared memory transport interface. |
| [SharedMemoryImageError](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client_8h.md#a0496a9a3db499fa9145fe97d2e6dae9a) | [stream\_putframe](#a23b3d9929aaff2a388402452ce5228c1) (stream\_id id, int width, int height, int framenumber, bytes pixeldata) Push an image into the shared memory transport buffer. |

## Detailed Description

Python interface to the [shared\_memory\_image\_client.h](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client_8h.md) API.

**Author**

Randy Frank (randy.nosp@[m..fra.nosp@m.nk](mailto:m..fra.nosp@m.nk)@[an.nosp@m.sys](mailto:an.nosp@m.sys)[..nosp@m.com](mailto:..nosp@m.com))

**Version**

1.0

## ensight\_grpc\_shmem python module

This module implements a set of Python bindings to the shared memory image transport API.

A simple example exercising the API might be:

```c theme={null}
import ensight_grpc_shmem
import time

def run_server(dx=1920, dy=1080, n=500):
    s = ensight_grpc_shmem.stream_create("shmem.bin", ensight_grpc_shmem.IMAGESTREAM_OPTIONS_SERVER)
    img = b'\0'*dx*dy*3
 for i in range(n):
        time.sleep(1./60.)
        err = ensight_grpc_shmem.stream_putframe(s, dx, dy, i, img)
        print("Frame: {} {}".format(i, err))
 if i == 0:
            time.sleep(5)
    ensight_grpc_shmem.stream_destroy(s)

def run_client(num=200):
    c = ensight_grpc_shmem.stream_create("shmem.bin")
    count = 0
 while True:
        img = ensight_grpc_shmem.stream_lock(c)
 if type(img) is dict:
            print("Frame: {} {} {} {}".format(img['framenumber'], img['width'], img['height'],count))
            ensight_grpc_shmem.stream_unlock(c)
            count += 1
 if count > num:
 break
    ensight_grpc_shmem.stream_destroy(c)
```

Definition in file [shared\_memory\_image\_client\_python.c](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client__python_8c_source).

## Macro Definition Documentation

### MAX\_STREAMS

```cpp theme={null}
#define MAX_STREAMS 50
```

the maximum number of active streams we allow

Definition at line [30](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client__python_8c_source) of file [shared\_memory\_image\_client\_python.c](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client__python_8c_source).

## Function Documentation

### stream\_create()

```cpp theme={null}
stream_id stream_create(
    str filename,
    int options = IMAGESTREAM_OPTIONS_NONE
)
```

Create a shared memory image stream.

Python wrapper for [SharedMemoryImageStream\_create()](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client_8h.md#a03ba052ae823b3e39fef153db8f03ea2). Function in the [ensight\_grpc\_shmem python module](#ensight_grpc_shmem) Python module.

**See also**

[SharedMemoryImageStream\_create()](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client_8h.md#a03ba052ae823b3e39fef153db8f03ea2).

**Parameters**

| Name | Description |
| - | - |
| filename | the name of the shared memory file to use. |
| options | the stream creation options |

**Exceptions**

| Name | Description |
| - | - |
| IMAGESTREAM\_BAD\_ARGS | |
| IMAGESTREAM\_BAD\_FILE\_SIZE | |
| IMAGESTREAM\_UNABLE\_TO\_OPEN\_FILE | |
| IMAGESTREAM\_UNABLE\_TO\_MAP\_FILE | |
| IMAGESTREAM\_MEMORY\_ALLOC\_ERROR | |
| IMAGESTREAM\_THREAD\_CREATE\_ERROR | |

**Returns**

the allocated stream id.

### stream\_destroy()

```cpp theme={null}
SharedMemoryImageError stream_destroy(stream_id id)
```

Close down and destroy a shared memory transport interface.

Python wrapper for [SharedMemoryImageStream\_destroy()](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client_8h.md#a4ea47b6bda387b71ed5f91db329eff65). Function in the [ensight\_grpc\_shmem python module](#ensight_grpc_shmem) Python module.

**See also**

[SharedMemoryImageStream\_destroy()](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client_8h.md#a4ea47b6bda387b71ed5f91db329eff65). \


**Parameters**

| Name | Description |
| - | - |
| id | the stream to be destroyed. |

**Exceptions**

| Name | Description |
| - | - |
| IMAGESTREAM\_BAD\_ARGS | |

**Returns**

IMAGESTREAM\_NOERROR

### stream\_lock()

```cpp theme={null}
frame stream_lock(stream_id id)
```

Get any available image frame.

Python wrapper for [SharedMemoryImageStream\_lock()](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client_8h.md#afefb8f5297147640b46d1f9eb1e77c9e). Function in the [ensight\_grpc\_shmem python module](#ensight_grpc_shmem) Python module.

**See also**

[SharedMemoryImageStream\_lock()](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client_8h.md#afefb8f5297147640b46d1f9eb1e77c9e). \


**Parameters**

| Name | Description |
| - | - |
| id | the stream to read from. |

**Exceptions**

| Name | Description |
| - | - |
| IMAGESTREAM\_BAD\_ARGS | |
| IMAGESTREAM\_IS\_SERVER | |
| IMAGESTREAM\_LOCKED | |

**Returns**

SharedMemoryImageError if no images are read or a dictionary with the same fields as [\_SharedMemoryFrame](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/struct___shared_memory_frame.md).

### stream\_putframe()

```cpp theme={null}
SharedMemoryImageError stream_putframe(
    stream_id id,
    int width,
    int height,
    int framenumber,
    bytes pixeldata
)
```

Push an image into the shared memory transport buffer.

Python wrapper for [SharedMemoryImageStream\_putframe()](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client__priv_8h.md#abe3cb5374af97eeccf691864f6e2b2ad). Only used by server connections. Function in the [ensight\_grpc\_shmem python module](#ensight_grpc_shmem) Python module.

**See also**

[SharedMemoryImageStream\_putframe()](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client__priv_8h.md#abe3cb5374af97eeccf691864f6e2b2ad). \


**Parameters**

| Name | Description |
| - | - |
| id | the stream to write to. |
| width | width of the frame in pixels |
| height | height of the frame in pixels |
| framenumber | the sequence number of this frame |
| pixeldata | a bytes() object of at least width\*height\*3 bytes in size |

**Exceptions**

| Name | Description |
| - | - |
| IMAGESTREAM\_BAD\_ARGS | |
| IMAGESTREAM\_IS\_NOTSERVER | |
| IMAGESTREAM\_FRAME\_TOO\_LARGE | |

**Returns**

SharedMemoryImageError IMAGESTREAM\_UNCONNECTED, IMAGESTREAM\_NO\_BUFFERAVAILABLE, IMAGESTREAM\_NOERROR

### stream\_unlock()

```cpp theme={null}
SharedMemoryImageError stream_unlock(stream_id id)
```

Unlock the frame allocated by [stream\_lock()](#ac78db99f06d47f7718fdcac4ae3cc374).

Python wrapper for [SharedMemoryImageStream\_unlock()](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client_8h.md#ac885e449551afd5fb5a7f19c5ec785a6). Function in the [ensight\_grpc\_shmem python module](#ensight_grpc_shmem) Python module.

**See also**

[SharedMemoryImageStream\_unlock()](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/shared__memory__image__client_8h.md#ac885e449551afd5fb5a7f19c5ec785a6). \


**Parameters**

| Name | Description |
| - | - |
| id | the stream to read from. |

**Exceptions**

| Name | Description |
| - | - |
| IMAGESTREAM\_BAD\_ARGS | |
| IMAGESTREAM\_IS\_SERVER | |
| IMAGESTREAM\_NOT\_LOCKED | |

**Returns**

SharedMemoryImageError if no images are read or a dictionary with the same fields as [\_SharedMemoryFrame](https://developer.synopsys.com/docs/ensight/ensight-apis/2025-r2/struct___shared_memory_frame.md).
