GSP Pydantic API Reference¶
The GSP Pydantic module provides serialization and deserialization capabilities using Pydantic models, enabling data validation and JSON schema generation for GSP objects.
Overview¶
gsp_pydantic
¶
GSP Pydantic package initialization.
Serializer Module¶
The serializer module contains the serialization and parsing utilities for converting GSP objects to and from Pydantic models.
gsp_pydantic.serializer
¶
Pydantic serializer and parser for GSP data structures.
Pydantic Serializer¶
gsp_pydantic.serializer.pydantic_serializer
¶
Pydantic serializer for GSP data structures.
PydanticSerializer
¶
Bases: gsp.types.serializer_base.SerializerBase
Serializer that converts GSP data structures into Pydantic models.
Source code in src/gsp_pydantic/serializer/pydantic_serializer.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 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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
__init__(canvas: Canvas)
¶
Initialize the PydanticSerializer with a canvas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
canvas
|
gsp.core.canvas.Canvas
|
The canvas to be used in the serialization. |
required |
Source code in src/gsp_pydantic/serializer/pydantic_serializer.py
46 47 48 49 50 51 52 | |
serialize(viewports: Sequence[Viewport], visuals: Sequence[VisualBase], model_matrices: Sequence[TransBuf], cameras: Sequence[Camera]) -> PydanticDict
¶
Serialize the provided GSP data structures into a PydanticDict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
viewports
|
typing.Sequence[gsp.core.viewport.Viewport]
|
The list of viewports to serialize. |
required |
visuals
|
typing.Sequence[gsp.types.visual_base.VisualBase]
|
The list of visual elements to serialize. |
required |
model_matrices
|
typing.Sequence[gsp.types.transbuf.TransBuf]
|
The list of model transformation matrices to serialize. |
required |
cameras
|
typing.Sequence[gsp.core.camera.Camera]
|
The list of cameras to serialize. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
PydanticDict |
gsp_pydantic.types.pydantic_dict.PydanticDict
|
The serialized data as a PydanticDict. |
Source code in src/gsp_pydantic/serializer/pydantic_serializer.py
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 | |
Pydantic Parser¶
gsp_pydantic.serializer.pydantic_parser
¶
Pydantic parser for GSP data structures.
PydanticParser
¶
Parser that converts Pydantic models into GSP data structures.
Source code in src/gsp_pydantic/serializer/pydantic_parser.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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
__init__()
¶
Initialize the PydanticParser.
Source code in src/gsp_pydantic/serializer/pydantic_parser.py
39 40 41 | |
parse(json_dict: PydanticDict) -> tuple[Canvas, list[Viewport], list[VisualBase], list[TransBuf], list[Camera]]
¶
Parse a Pydantic JSON dictionary into GSP data structures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
json_dict
|
gsp_pydantic.types.pydantic_dict.PydanticDict
|
The Pydantic JSON dictionary representing the scene. |
required |
Returns:
| Type | Description |
|---|---|
gsp.core.canvas.Canvas
|
tuple[ Canvas, list[Viewport], list[VisualBase], list[TransBuf], list[Camera], |
list[gsp.core.viewport.Viewport]
|
]: The parsed GSP data structures. |
Source code in src/gsp_pydantic/serializer/pydantic_parser.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 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 | |
Types Module¶
The types module defines Pydantic models for GSP data structures, providing validation and schema generation.
gsp_pydantic.types
¶
Pydantic types for GSP data structures.
Pydantic Dict¶
gsp_pydantic.types.pydantic_dict
¶
Pydantic type for a dictionary with string keys and any values.
PydanticDict = Dict[str, Any]
module-attribute
¶
Type alias for a dictionary with string keys and any values.
Pydantic Types¶
gsp_pydantic.types.pydantic_types
¶
"Pydantic models for GSP data types.
PydanticGroups = Union[int, list[int], list[list[int]]]
module-attribute
¶
Type alias for groups which can be an int, a list of ints, or a list of list of ints.
PydanticBuffer
¶
Bases: pydantic.BaseModel
Pydantic model representing a buffer with encoded data.
This class stores buffer data in a serializable format using base64 encoding.
Source code in src/gsp_pydantic/types/pydantic_types.py
14 15 16 17 18 19 20 21 22 23 24 25 | |
PydanticCamera
¶
Bases: pydantic.BaseModel
Pydantic model representing a camera.
Defines the camera's view and projection transformations for rendering the scene.
Source code in src/gsp_pydantic/types/pydantic_types.py
196 197 198 199 200 201 202 203 204 | |
PydanticCanvas
¶
Bases: pydantic.BaseModel
Pydantic model representing a canvas for rendering.
Defines the rendering surface with dimensions and resolution.
Source code in src/gsp_pydantic/types/pydantic_types.py
162 163 164 165 166 167 168 169 170 171 | |
PydanticMarkers
¶
Bases: pydantic.BaseModel
Pydantic model representing marker visual elements.
Markers are geometric shapes (circles, squares, etc.) positioned in space with configurable appearance properties.
Source code in src/gsp_pydantic/types/pydantic_types.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
PydanticModelMatrix
¶
Bases: pydantic.BaseModel
Pydantic model representing a model transformation matrix.
Contains the transformation matrix for positioning objects in the scene.
Source code in src/gsp_pydantic/types/pydantic_types.py
187 188 189 190 191 192 193 | |
PydanticPaths
¶
Bases: pydantic.BaseModel
Pydantic model representing path visual elements.
Paths are continuous lines or curves with configurable line styles and colors.
Source code in src/gsp_pydantic/types/pydantic_types.py
75 76 77 78 79 80 81 82 83 84 85 86 87 | |
PydanticPixels
¶
Bases: pydantic.BaseModel
Pydantic model representing pixel visual elements.
Pixels are individual colored points organized into groups.
Source code in src/gsp_pydantic/types/pydantic_types.py
90 91 92 93 94 95 96 97 98 99 | |
PydanticPoints
¶
Bases: pydantic.BaseModel
Pydantic model representing point visual elements.
Points are circular elements with configurable size and appearance, including face color, edge color, and edge width.
Source code in src/gsp_pydantic/types/pydantic_types.py
102 103 104 105 106 107 108 109 110 111 112 113 114 | |
PydanticScene
¶
Bases: pydantic.BaseModel
Pydantic model representing a complete scene.
Aggregates all scene elements including canvas, viewports, visual elements, transformation matrices, and cameras.
Source code in src/gsp_pydantic/types/pydantic_types.py
207 208 209 210 211 212 213 214 215 216 217 218 | |
PydanticSegments
¶
Bases: pydantic.BaseModel
Pydantic model representing line segment visual elements.
Segments are individual line segments with configurable width, color, and cap style.
Source code in src/gsp_pydantic/types/pydantic_types.py
117 118 119 120 121 122 123 124 125 126 127 | |
PydanticTexts
¶
Bases: pydantic.BaseModel
Pydantic model representing text visual elements.
Text elements with configurable position, font properties, colors, and orientation.
Source code in src/gsp_pydantic/types/pydantic_types.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
PydanticTransBuf
¶
Bases: pydantic.BaseModel
Pydantic model for a transform buffer union type.
Can represent either a buffer or a transform chain, discriminated by the type field.
Source code in src/gsp_pydantic/types/pydantic_types.py
37 38 39 40 41 42 43 44 | |
PydanticTransformChain
¶
Bases: pydantic.BaseModel
Pydantic model representing a chain of transformations.
Contains a dictionary representing the transformation chain configuration.
Source code in src/gsp_pydantic/types/pydantic_types.py
28 29 30 31 32 33 34 | |
PydanticViewport
¶
Bases: pydantic.BaseModel
Pydantic model representing a viewport region.
Defines a rectangular viewing area within the canvas.
Source code in src/gsp_pydantic/types/pydantic_types.py
174 175 176 177 178 179 180 181 182 183 184 | |
PydanticVisual
¶
Bases: pydantic.BaseModel
Pydantic model for a visual element union type.
Discriminated union that can represent any of the visual element types, distinguished by the type field.
Source code in src/gsp_pydantic/types/pydantic_types.py
146 147 148 149 150 151 152 153 154 | |