GSP Network API Reference¶
The GSP Network module provides network-based rendering capabilities, enabling remote visualization and client-server architectures.
Overview¶
gsp_network
¶
gsp_network provides functionality for rendering graphics over a network using different remote renderers.
Renderer Module¶
The renderer module contains the network renderer implementation for remote rendering.
gsp_network.renderer
¶
Network renderer that sends rendering requests to a remote server and displays the results using Matplotlib.
NetworkRenderer
¶
Bases: gsp.types.renderer_base.RendererBase
Note: this requires a running gsp_network server. See the README for instructions.
IMPORTANT: it DOES NOT depend on GSP matplotlib renderer, it only uses pip matplotlib to display the remotely rendered images.
Source code in src/gsp_network/renderer/network_renderer.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
__init__(canvas: Canvas, server_base_url: str, remote_renderer_name: Literal['matplotlib', 'datoviz'] = 'matplotlib') -> None
¶
Initialize the NetworkRenderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
canvas
|
gsp.core.canvas.Canvas
|
description |
required |
server_base_url
|
str
|
description |
required |
remote_renderer_name
|
typing.Literal['matplotlib', 'datoviz']
|
description. Defaults to "matplotlib". |
'matplotlib'
|
Source code in src/gsp_network/renderer/network_renderer.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
get_canvas() -> Canvas
¶
Get the canvas associated with the network renderer.
Returns:
| Name | Type | Description |
|---|---|---|
Canvas |
gsp.core.canvas.Canvas
|
The canvas associated with the network renderer. |
Source code in src/gsp_network/renderer/network_renderer.py
71 72 73 74 75 76 77 | |
close() -> None
¶
Close the network renderer and release resources.
Source code in src/gsp_network/renderer/network_renderer.py
79 80 81 82 83 84 85 | |
get_remote_renderer_name() -> Literal['matplotlib', 'datoviz']
¶
Get the name of the remote renderer being used.
Returns:
| Type | Description |
|---|---|
typing.Literal['matplotlib', 'datoviz']
|
Literal["matplotlib", "datoviz"]: The name of the remote renderer. |
Source code in src/gsp_network/renderer/network_renderer.py
87 88 89 90 91 92 93 | |
render(viewports: Sequence[Viewport], visuals: Sequence[VisualBase], model_matrices: Sequence[TransBuf], cameras: Sequence[Camera]) -> bytes
¶
Render the scene remotely and update the matplotlib figure with the rendered image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
viewports
|
typing.Sequence[gsp.core.viewport.Viewport]
|
The viewports to render. |
required |
visuals
|
typing.Sequence[gsp.types.visual_base.VisualBase]
|
The visuals to render. |
required |
model_matrices
|
typing.Sequence[gsp.types.transbuf.TransBuf]
|
The model matrices for the visuals. |
required |
cameras
|
typing.Sequence[gsp.core.camera.Camera]
|
The cameras to use for rendering. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
The rendered image data in PNG format. |
Raises:
| Type | Description |
|---|---|
Exception
|
If the network request fails. |
Source code in src/gsp_network/renderer/network_renderer.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
show() -> None
¶
Show the rendered canvas (blocking call).
Source code in src/gsp_network/renderer/network_renderer.py
157 158 159 160 161 162 163 164 | |
get_mpl_figure() -> matplotlib.figure.Figure
¶
Get the underlying Matplotlib figure.
Returns:
| Type | Description |
|---|---|
matplotlib.figure.Figure
|
matplotlib.figure.Figure: The Matplotlib figure used by the renderer. |
Source code in src/gsp_network/renderer/network_renderer.py
166 167 168 169 170 171 172 | |
Network Renderer¶
gsp_network.renderer.network_renderer
¶
Network renderer that sends rendering requests to a remote server and displays the results using Matplotlib.
NetworkPayload
¶
Bases: typing.TypedDict
Type definition for the network payload sent to the server.
Source code in src/gsp_network/renderer/network_renderer.py
31 32 33 34 | |
NetworkRenderer
¶
Bases: gsp.types.renderer_base.RendererBase
Note: this requires a running gsp_network server. See the README for instructions.
IMPORTANT: it DOES NOT depend on GSP matplotlib renderer, it only uses pip matplotlib to display the remotely rendered images.
Source code in src/gsp_network/renderer/network_renderer.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
__init__(canvas: Canvas, server_base_url: str, remote_renderer_name: Literal['matplotlib', 'datoviz'] = 'matplotlib') -> None
¶
Initialize the NetworkRenderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
canvas
|
gsp.core.canvas.Canvas
|
description |
required |
server_base_url
|
str
|
description |
required |
remote_renderer_name
|
typing.Literal['matplotlib', 'datoviz']
|
description. Defaults to "matplotlib". |
'matplotlib'
|
Source code in src/gsp_network/renderer/network_renderer.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
close() -> None
¶
Close the network renderer and release resources.
Source code in src/gsp_network/renderer/network_renderer.py
79 80 81 82 83 84 85 | |
get_canvas() -> Canvas
¶
Get the canvas associated with the network renderer.
Returns:
| Name | Type | Description |
|---|---|---|
Canvas |
gsp.core.canvas.Canvas
|
The canvas associated with the network renderer. |
Source code in src/gsp_network/renderer/network_renderer.py
71 72 73 74 75 76 77 | |
get_mpl_figure() -> matplotlib.figure.Figure
¶
Get the underlying Matplotlib figure.
Returns:
| Type | Description |
|---|---|
matplotlib.figure.Figure
|
matplotlib.figure.Figure: The Matplotlib figure used by the renderer. |
Source code in src/gsp_network/renderer/network_renderer.py
166 167 168 169 170 171 172 | |
get_remote_renderer_name() -> Literal['matplotlib', 'datoviz']
¶
Get the name of the remote renderer being used.
Returns:
| Type | Description |
|---|---|
typing.Literal['matplotlib', 'datoviz']
|
Literal["matplotlib", "datoviz"]: The name of the remote renderer. |
Source code in src/gsp_network/renderer/network_renderer.py
87 88 89 90 91 92 93 | |
render(viewports: Sequence[Viewport], visuals: Sequence[VisualBase], model_matrices: Sequence[TransBuf], cameras: Sequence[Camera]) -> bytes
¶
Render the scene remotely and update the matplotlib figure with the rendered image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
viewports
|
typing.Sequence[gsp.core.viewport.Viewport]
|
The viewports to render. |
required |
visuals
|
typing.Sequence[gsp.types.visual_base.VisualBase]
|
The visuals to render. |
required |
model_matrices
|
typing.Sequence[gsp.types.transbuf.TransBuf]
|
The model matrices for the visuals. |
required |
cameras
|
typing.Sequence[gsp.core.camera.Camera]
|
The cameras to use for rendering. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
The rendered image data in PNG format. |
Raises:
| Type | Description |
|---|---|
Exception
|
If the network request fails. |
Source code in src/gsp_network/renderer/network_renderer.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
show() -> None
¶
Show the rendered canvas (blocking call).
Source code in src/gsp_network/renderer/network_renderer.py
157 158 159 160 161 162 163 164 | |
Tools Module¶
The tools module provides server utilities for network-based rendering.
gsp_network.tools
¶
tools package initialization.
Network Server¶
gsp_network.tools.network_server
¶
Server example using Flask to render a scene from JSON input.
- use Flask to create a simple web server
- render with matplotlib or datoviz based on environment variable
ServerSample
¶
Sample class to demonstrate server functionality.
Source code in src/gsp_network/tools/network_server.py
92 93 94 95 96 97 98 99 100 | |
__init__()
¶
Initialize the server sample.
Source code in src/gsp_network/tools/network_server.py
94 95 96 | |
run()
¶
Run the Flask server.
Source code in src/gsp_network/tools/network_server.py
98 99 100 | |
render_scene_json() -> Response
¶
Flask route to render a scene from JSON input.
Returns:
| Name | Type | Description |
|---|---|---|
Response |
flask.Response
|
Flask response containing the rendered PNG image. |
Source code in src/gsp_network/tools/network_server.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
text_cyan(text: str) -> str
¶
Return the given text string wrapped in ANSI escape codes for cyan color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to color. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The colored text string. |
Source code in src/gsp_network/tools/network_server.py
28 29 30 31 32 33 34 35 36 37 | |
Network Server Kill¶
gsp_network.tools.network_server_kill
¶
Kill any process using port 5000 (commonly used for flask server).
in shell: lsof -ti tcp:5000 | xargs kill
main() -> int
¶
Main function to kill processes using port 5000.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Exit code (0 for success, 1 for failure). |
Source code in src/gsp_network/tools/network_server_kill.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |