Transport¶
Base Transport Interface¶
Transport ¶
Bases: ABC
Abstract base class for PhyCloud transports.
Implementations must provide async methods for sending single events and batches to PhyCloud endpoints.
Initialize the transport.
| PARAMETER | DESCRIPTION |
|---|---|
config | Transport configuration TYPE: |
Source code in phytrace/transport/base.py
Attributes¶
Functions¶
connect abstractmethod async ¶
Establish connection to PhyCloud.
| RAISES | DESCRIPTION |
|---|---|
TransportError | If connection fails |
disconnect abstractmethod async ¶
send abstractmethod async ¶
send(event: UDMEvent) -> SendResult
Send a single event to PhyCloud.
| PARAMETER | DESCRIPTION |
|---|---|
event | The UDM event to send TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
SendResult | SendResult indicating success or failure |
send_batch abstractmethod async ¶
send_batch(events: list[UDMEvent]) -> BatchSendResult
Send a batch of events to PhyCloud.
| PARAMETER | DESCRIPTION |
|---|---|
events | List of UDM events to send TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
BatchSendResult | BatchSendResult with per-event results |
Source code in phytrace/transport/base.py
health_check async ¶
Check if the transport connection is healthy.
| RETURNS | DESCRIPTION |
|---|---|
bool | True if healthy, False otherwise |
SendResult¶
SendResult dataclass ¶
SendResult(success: bool, event_id: str, timestamp: datetime = utcnow(), error: TransportError | None = None, response_time_ms: float | None = None, server_event_id: str | None = None)
Result of sending a single event.
Functions¶
ok classmethod ¶
ok(event_id: str, response_time_ms: float | None = None, server_event_id: str | None = None) -> SendResult
Create a successful result.
Source code in phytrace/transport/base.py
fail classmethod ¶
fail(event_id: str, error: TransportError) -> SendResult
BatchSendResult¶
BatchSendResult dataclass ¶
BatchSendResult(success: bool, total_events: int, successful_events: int, failed_events: int, results: list[SendResult] = list(), batch_id: str | None = None, response_time_ms: float | None = None)
HTTP Transport¶
HTTPTransport ¶
HTTPTransport(endpoint: str, api_key: str | None = None, timeout_sec: float = 30.0, max_retries: int = 3)
Bases: Transport
HTTP/REST transport for PhyCloud ingestion.
Sends events to PhyCloud using the REST API: - POST /api/v1/events - Single event - POST /api/v1/events/batch - Multiple events
Initialize HTTP transport.
| PARAMETER | DESCRIPTION |
|---|---|
endpoint | PhyCloud API endpoint (e.g., https://api.phycloud.io/v1) TYPE: |
api_key | API key for authentication TYPE: |
timeout_sec | Request timeout in seconds TYPE: |
max_retries | Maximum retry attempts TYPE: |
Source code in phytrace/transport/http.py
Functions¶
connect async ¶
Establish HTTP session.
Source code in phytrace/transport/http.py
disconnect async ¶
send async ¶
send(event: UDMEvent) -> SendResult
Send a single event to PhyCloud.
| PARAMETER | DESCRIPTION |
|---|---|
event | The UDM event to send TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
SendResult | SendResult indicating success or failure |
Source code in phytrace/transport/http.py
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 | |
send_batch async ¶
send_batch(events: list[UDMEvent]) -> BatchSendResult
Send a batch of events to PhyCloud.
| PARAMETER | DESCRIPTION |
|---|---|
events | List of UDM events to send TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
BatchSendResult | BatchSendResult with per-event results |
Source code in phytrace/transport/http.py
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 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |
Mock Transport¶
MockTransport ¶
Bases: Transport
Mock transport for testing.
Records all sent events and allows configuring behavior for testing different scenarios.
Example
transport = MockTransport() await transport.send(event)
assert len(transport.sent_events) == 1 assert transport.sent_events[0].source_id == "robot-001"
Test error handling¶
transport.behavior.fail_all = True result = await transport.send(event) assert not result.success
Initialize mock transport.
| PARAMETER | DESCRIPTION |
|---|---|
behavior | Optional MockBehavior configuration TYPE: |
Source code in phytrace/transport/mock.py
Attributes¶
Functions¶
connect async ¶
disconnect async ¶
send async ¶
send(event: UDMEvent) -> SendResult
Mock send - records the event and returns configured result.
| PARAMETER | DESCRIPTION |
|---|---|
event | The UDM event to "send" TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
SendResult | SendResult based on configured behavior |
Source code in phytrace/transport/mock.py
send_batch async ¶
send_batch(events: list[UDMEvent]) -> BatchSendResult
Mock batch send - records all events.
| PARAMETER | DESCRIPTION |
|---|---|
events | List of UDM events to "send" TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
BatchSendResult | BatchSendResult based on configured behavior |
Source code in phytrace/transport/mock.py
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 | |