foxglove-sdk 0.7.0__cp311-cp311-macosx_10_12_x86_64.whl → 0.15.3__cp311-cp311-macosx_10_12_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of foxglove-sdk might be problematic. Click here for more details.
- foxglove/__init__.py +165 -44
- foxglove/_foxglove_py/__init__.pyi +118 -25
- foxglove/_foxglove_py/channels.pyi +1828 -186
- foxglove/_foxglove_py/cloud.pyi +9 -0
- foxglove/_foxglove_py/mcap.pyi +24 -12
- foxglove/_foxglove_py/schemas.pyi +628 -301
- foxglove/_foxglove_py/schemas_wkt.pyi +17 -9
- foxglove/_foxglove_py/websocket.pyi +74 -80
- foxglove/_foxglove_py.cpython-311-darwin.so +0 -0
- foxglove/benchmarks/test_mcap_serialization.py +4 -5
- foxglove/channel.py +76 -39
- foxglove/channels/__init__.py +21 -1
- foxglove/cloud.py +61 -0
- foxglove/notebook/__init__.py +0 -0
- foxglove/notebook/foxglove_widget.py +100 -0
- foxglove/notebook/notebook_buffer.py +114 -0
- foxglove/notebook/static/widget.js +1 -0
- foxglove/schemas/__init__.py +11 -0
- foxglove/tests/test_channel.py +116 -15
- foxglove/tests/test_context.py +10 -0
- foxglove/tests/test_logging.py +46 -0
- foxglove/tests/test_mcap.py +110 -2
- foxglove/tests/test_parameters.py +40 -16
- foxglove/tests/test_schemas.py +17 -0
- foxglove/tests/test_server.py +46 -2
- foxglove/websocket.py +30 -20
- foxglove_sdk-0.15.3.dist-info/METADATA +53 -0
- foxglove_sdk-0.15.3.dist-info/RECORD +33 -0
- {foxglove_sdk-0.7.0.dist-info → foxglove_sdk-0.15.3.dist-info}/WHEEL +1 -1
- foxglove_sdk-0.7.0.dist-info/METADATA +0 -51
- foxglove_sdk-0.7.0.dist-info/RECORD +0 -25
foxglove/__init__.py
CHANGED
|
@@ -5,67 +5,128 @@ See :py:mod:`foxglove.schemas` and :py:mod:`foxglove.channels` for working with
|
|
|
5
5
|
schemas.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
8
10
|
import atexit
|
|
9
11
|
import logging
|
|
10
|
-
from typing import
|
|
12
|
+
from typing import TYPE_CHECKING
|
|
11
13
|
|
|
12
14
|
from . import _foxglove_py as _foxglove
|
|
13
15
|
|
|
14
16
|
# Re-export these imports
|
|
15
|
-
from ._foxglove_py import
|
|
17
|
+
from ._foxglove_py import (
|
|
18
|
+
ChannelDescriptor,
|
|
19
|
+
Context,
|
|
20
|
+
Schema,
|
|
21
|
+
SinkChannelFilter,
|
|
22
|
+
open_mcap,
|
|
23
|
+
)
|
|
16
24
|
from .channel import Channel, log
|
|
17
25
|
|
|
18
26
|
# Deprecated. Use foxglove.mcap.MCAPWriter instead.
|
|
19
27
|
from .mcap import MCAPWriter
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
ServerListener,
|
|
24
|
-
Service,
|
|
25
|
-
WebSocketServer,
|
|
26
|
-
)
|
|
28
|
+
|
|
29
|
+
if TYPE_CHECKING:
|
|
30
|
+
from .notebook.notebook_buffer import NotebookBuffer
|
|
27
31
|
|
|
28
32
|
atexit.register(_foxglove.shutdown)
|
|
29
33
|
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"""
|
|
43
|
-
Start a websocket server for live visualization.
|
|
44
|
-
|
|
45
|
-
:param name: The name of the server.
|
|
46
|
-
:param host: The host to bind to.
|
|
47
|
-
:param port: The port to bind to.
|
|
48
|
-
:param capabilities: A list of capabilities to advertise to clients.
|
|
49
|
-
:param server_listener: A Python object that implements the :py:class:`websocket.ServerListener`
|
|
50
|
-
protocol.
|
|
51
|
-
:param supported_encodings: A list of encodings to advertise to clients.
|
|
52
|
-
:param services: A list of services to advertise to clients.
|
|
53
|
-
:param asset_handler: A callback function that returns the asset for a given URI, or None if
|
|
54
|
-
it doesn't exist.
|
|
55
|
-
"""
|
|
56
|
-
return _foxglove.start_server(
|
|
57
|
-
name=name,
|
|
58
|
-
host=host,
|
|
59
|
-
port=port,
|
|
60
|
-
capabilities=capabilities,
|
|
61
|
-
server_listener=server_listener,
|
|
62
|
-
supported_encodings=supported_encodings,
|
|
63
|
-
services=services,
|
|
64
|
-
asset_handler=asset_handler,
|
|
35
|
+
try:
|
|
36
|
+
from ._foxglove_py.cloud import CloudSink
|
|
37
|
+
|
|
38
|
+
# from ._foxglove_py.cloud import start_cloud_sink as _start_cloud_sink
|
|
39
|
+
from .cloud import CloudSinkListener
|
|
40
|
+
from .websocket import (
|
|
41
|
+
AssetHandler,
|
|
42
|
+
Capability,
|
|
43
|
+
ServerListener,
|
|
44
|
+
Service,
|
|
45
|
+
WebSocketServer,
|
|
65
46
|
)
|
|
66
47
|
|
|
48
|
+
def start_server(
|
|
49
|
+
*,
|
|
50
|
+
name: str | None = None,
|
|
51
|
+
host: str | None = "127.0.0.1",
|
|
52
|
+
port: int | None = 8765,
|
|
53
|
+
capabilities: list[Capability] | None = None,
|
|
54
|
+
server_listener: ServerListener | None = None,
|
|
55
|
+
supported_encodings: list[str] | None = None,
|
|
56
|
+
services: list[Service] | None = None,
|
|
57
|
+
asset_handler: AssetHandler | None = None,
|
|
58
|
+
context: Context | None = None,
|
|
59
|
+
session_id: str | None = None,
|
|
60
|
+
channel_filter: SinkChannelFilter | None = None,
|
|
61
|
+
) -> WebSocketServer:
|
|
62
|
+
"""
|
|
63
|
+
Start a websocket server for live visualization.
|
|
64
|
+
|
|
65
|
+
:param name: The name of the server.
|
|
66
|
+
:param host: The host to bind to.
|
|
67
|
+
:param port: The port to bind to.
|
|
68
|
+
:param capabilities: A list of capabilities to advertise to clients.
|
|
69
|
+
:param server_listener: A Python object that implements the
|
|
70
|
+
:py:class:`websocket.ServerListener` protocol.
|
|
71
|
+
:param supported_encodings: A list of encodings to advertise to clients.
|
|
72
|
+
:param services: A list of services to advertise to clients.
|
|
73
|
+
:param asset_handler: A callback function that returns the asset for a given URI, or None if
|
|
74
|
+
it doesn't exist.
|
|
75
|
+
:param context: The context to use for logging. If None, the global context is used.
|
|
76
|
+
:param session_id: An ID which allows the client to understand if the connection is a
|
|
77
|
+
re-connection or a new server instance. If None, then an ID is generated based on the
|
|
78
|
+
current time.
|
|
79
|
+
:param channel_filter: A `Callable` that determines whether a channel should be logged to.
|
|
80
|
+
Return `True` to log the channel, or `False` to skip it. By default, all channels
|
|
81
|
+
will be logged.
|
|
82
|
+
"""
|
|
83
|
+
return _foxglove.start_server(
|
|
84
|
+
name=name,
|
|
85
|
+
host=host,
|
|
86
|
+
port=port,
|
|
87
|
+
capabilities=capabilities,
|
|
88
|
+
server_listener=server_listener,
|
|
89
|
+
supported_encodings=supported_encodings,
|
|
90
|
+
services=services,
|
|
91
|
+
asset_handler=asset_handler,
|
|
92
|
+
context=context,
|
|
93
|
+
session_id=session_id,
|
|
94
|
+
channel_filter=channel_filter,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
def start_cloud_sink(
|
|
98
|
+
*,
|
|
99
|
+
listener: CloudSinkListener | None = None,
|
|
100
|
+
supported_encodings: list[str] | None = None,
|
|
101
|
+
context: Context | None = None,
|
|
102
|
+
session_id: str | None = None,
|
|
103
|
+
) -> CloudSink:
|
|
104
|
+
"""
|
|
105
|
+
Connect to Foxglove Agent for live visualization and teleop.
|
|
106
|
+
|
|
107
|
+
Foxglove Agent must be running on the same host for this to work.
|
|
108
|
+
|
|
109
|
+
:param capabilities: A list of capabilities to advertise to the agent.
|
|
110
|
+
:param listener: A Python object that implements the
|
|
111
|
+
:py:class:`cloud.CloudSinkListener` protocol.
|
|
112
|
+
:param supported_encodings: A list of encodings to advertise to the agent.
|
|
113
|
+
:param context: The context to use for logging. If None, the global context is used.
|
|
114
|
+
:param session_id: An ID which allows the agent to understand if the connection is a
|
|
115
|
+
re-connection or a new connection instance. If None, then an ID is generated based on
|
|
116
|
+
the current time.
|
|
117
|
+
"""
|
|
118
|
+
return _foxglove.start_cloud_sink(
|
|
119
|
+
listener=listener,
|
|
120
|
+
supported_encodings=supported_encodings,
|
|
121
|
+
context=context,
|
|
122
|
+
session_id=session_id,
|
|
123
|
+
)
|
|
67
124
|
|
|
68
|
-
|
|
125
|
+
except ImportError:
|
|
126
|
+
pass
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def set_log_level(level: int | str = "INFO") -> None:
|
|
69
130
|
"""
|
|
70
131
|
Enable SDK logging.
|
|
71
132
|
|
|
@@ -109,12 +170,72 @@ def _level_names() -> dict[str, int]:
|
|
|
109
170
|
}
|
|
110
171
|
|
|
111
172
|
|
|
173
|
+
def init_notebook_buffer(context: Context | None = None) -> NotebookBuffer:
|
|
174
|
+
"""
|
|
175
|
+
Create a NotebookBuffer object to manage data buffering and visualization in Jupyter
|
|
176
|
+
notebooks.
|
|
177
|
+
|
|
178
|
+
The NotebookBuffer object will buffer all data logged to the provided context. When you
|
|
179
|
+
are ready to visualize the data, you can call the :meth:`show` method to display an embedded
|
|
180
|
+
Foxglove visualization widget. The widget provides a fully-featured Foxglove interface
|
|
181
|
+
directly within your Jupyter notebook, allowing you to explore multi-modal robotics data
|
|
182
|
+
including 3D scenes, plots, images, and more.
|
|
183
|
+
|
|
184
|
+
Args:
|
|
185
|
+
context: The Context used to log the messages. If no Context is provided, the global
|
|
186
|
+
context will be used. Logged messages will be buffered.
|
|
187
|
+
|
|
188
|
+
Returns:
|
|
189
|
+
NotebookBuffer: A NotebookBuffer object that can be used to manage the data buffering
|
|
190
|
+
and visualization.
|
|
191
|
+
|
|
192
|
+
Raises:
|
|
193
|
+
Exception: If the notebook extra package is not installed. Install it
|
|
194
|
+
with `pip install foxglove-sdk[notebook]`.
|
|
195
|
+
|
|
196
|
+
Note:
|
|
197
|
+
This function is only available when the `notebook` extra package
|
|
198
|
+
is installed. Install it with `pip install foxglove-sdk[notebook]`.
|
|
199
|
+
|
|
200
|
+
Example:
|
|
201
|
+
>>> import foxglove
|
|
202
|
+
>>>
|
|
203
|
+
>>> # Create a basic viewer using the default context
|
|
204
|
+
>>> nb_buffer = foxglove.init_notebook_buffer()
|
|
205
|
+
>>>
|
|
206
|
+
>>> # Or use a specific context
|
|
207
|
+
>>> nb_buffer = foxglove.init_notebook_buffer(context=my_ctx)
|
|
208
|
+
>>>
|
|
209
|
+
>>> # ... log data as usual ...
|
|
210
|
+
>>>
|
|
211
|
+
>>> # Display the widget in the notebook
|
|
212
|
+
>>> nb_buffer.show()
|
|
213
|
+
"""
|
|
214
|
+
try:
|
|
215
|
+
from .notebook.notebook_buffer import NotebookBuffer
|
|
216
|
+
|
|
217
|
+
except ImportError:
|
|
218
|
+
raise Exception(
|
|
219
|
+
"NotebookBuffer is not installed. "
|
|
220
|
+
'Please install it with `pip install "foxglove-sdk[notebook]"`'
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
return NotebookBuffer(context=context)
|
|
224
|
+
|
|
225
|
+
|
|
112
226
|
__all__ = [
|
|
113
227
|
"Channel",
|
|
228
|
+
"ChannelDescriptor",
|
|
229
|
+
"Context",
|
|
114
230
|
"MCAPWriter",
|
|
115
231
|
"Schema",
|
|
232
|
+
"SinkChannelFilter",
|
|
233
|
+
"CloudSink",
|
|
234
|
+
"CloudSinkListener",
|
|
235
|
+
"start_cloud_sink",
|
|
116
236
|
"log",
|
|
117
237
|
"open_mcap",
|
|
118
238
|
"set_log_level",
|
|
119
239
|
"start_server",
|
|
240
|
+
"init_notebook_buffer",
|
|
120
241
|
]
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
|
-
from typing import Any,
|
|
2
|
+
from typing import Any, Callable
|
|
3
3
|
|
|
4
|
+
from foxglove.websocket import AssetHandler
|
|
5
|
+
|
|
6
|
+
from .cloud import CloudSink
|
|
4
7
|
from .mcap import MCAPWriteOptions, MCAPWriter
|
|
5
|
-
from .websocket import
|
|
8
|
+
from .websocket import Capability, Service, WebSocketServer
|
|
6
9
|
|
|
7
10
|
class BaseChannel:
|
|
8
11
|
"""
|
|
9
12
|
A channel for logging messages.
|
|
10
13
|
"""
|
|
11
14
|
|
|
12
|
-
def
|
|
13
|
-
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
14
17
|
topic: str,
|
|
15
18
|
message_encoding: str,
|
|
16
|
-
schema:
|
|
17
|
-
metadata:
|
|
18
|
-
) ->
|
|
19
|
+
schema: "Schema" | None = None,
|
|
20
|
+
metadata: dict[str, str] | None = None,
|
|
21
|
+
) -> None: ...
|
|
19
22
|
def id(self) -> int:
|
|
20
23
|
"""The unique ID of the channel"""
|
|
21
24
|
...
|
|
@@ -24,20 +27,50 @@ class BaseChannel:
|
|
|
24
27
|
"""The topic name of the channel"""
|
|
25
28
|
...
|
|
26
29
|
|
|
27
|
-
|
|
30
|
+
@property
|
|
31
|
+
def message_encoding(self) -> str:
|
|
32
|
+
"""The message encoding for the channel"""
|
|
33
|
+
...
|
|
34
|
+
|
|
35
|
+
def metadata(self) -> dict[str, str]:
|
|
36
|
+
"""
|
|
37
|
+
Returns a copy of the channel's metadata.
|
|
38
|
+
|
|
39
|
+
Note that changes made to the returned dictionary will not be applied to
|
|
40
|
+
the channel's metadata.
|
|
41
|
+
"""
|
|
42
|
+
...
|
|
43
|
+
|
|
44
|
+
def schema(self) -> "Schema" | None:
|
|
45
|
+
"""
|
|
46
|
+
Returns a copy of the channel's schema.
|
|
47
|
+
|
|
48
|
+
Note that changes made to the returned object will not be applied to
|
|
49
|
+
the channel's schema.
|
|
50
|
+
"""
|
|
51
|
+
...
|
|
52
|
+
|
|
53
|
+
def schema_name(self) -> str | None:
|
|
28
54
|
"""The name of the schema for the channel"""
|
|
29
55
|
...
|
|
30
56
|
|
|
57
|
+
def has_sinks(self) -> bool:
|
|
58
|
+
"""Returns true if at least one sink is subscribed to this channel"""
|
|
59
|
+
...
|
|
60
|
+
|
|
31
61
|
def log(
|
|
32
62
|
self,
|
|
33
63
|
msg: bytes,
|
|
34
|
-
log_time:
|
|
64
|
+
log_time: int | None = None,
|
|
65
|
+
sink_id: int | None = None,
|
|
35
66
|
) -> None:
|
|
36
67
|
"""
|
|
37
68
|
Log a message to the channel.
|
|
38
69
|
|
|
39
70
|
:param msg: The message to log.
|
|
40
71
|
:param log_time: The optional time the message was logged.
|
|
72
|
+
:param sink_id: The sink ID to log the message to. If not provided, the message will be
|
|
73
|
+
sent to all sinks.
|
|
41
74
|
"""
|
|
42
75
|
...
|
|
43
76
|
|
|
@@ -52,30 +85,88 @@ class Schema:
|
|
|
52
85
|
encoding: str
|
|
53
86
|
data: bytes
|
|
54
87
|
|
|
55
|
-
def
|
|
56
|
-
|
|
88
|
+
def __init__(
|
|
89
|
+
self,
|
|
57
90
|
*,
|
|
58
91
|
name: str,
|
|
59
92
|
encoding: str,
|
|
60
93
|
data: bytes,
|
|
61
|
-
) ->
|
|
94
|
+
) -> None: ...
|
|
95
|
+
|
|
96
|
+
class Context:
|
|
97
|
+
"""
|
|
98
|
+
A context for logging messages.
|
|
99
|
+
|
|
100
|
+
A context is the binding between channels and sinks. By default, the SDK will use a single
|
|
101
|
+
global context for logging, but you can create multiple contexts in order to log to different
|
|
102
|
+
topics to different sinks or servers. To do so, associate the context by passing it to the
|
|
103
|
+
channel constructor and to :py:func:`open_mcap` or :py:func:`start_server`.
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
def __init__(self) -> None: ...
|
|
107
|
+
def _create_channel(
|
|
108
|
+
self,
|
|
109
|
+
topic: str,
|
|
110
|
+
message_encoding: str,
|
|
111
|
+
schema: Schema | None = None,
|
|
112
|
+
metadata: list[tuple[str, str]] | None = None,
|
|
113
|
+
) -> "BaseChannel":
|
|
114
|
+
"""
|
|
115
|
+
Instead of calling this method, pass a context to a channel constructor.
|
|
116
|
+
"""
|
|
117
|
+
...
|
|
118
|
+
|
|
119
|
+
@staticmethod
|
|
120
|
+
def default() -> "Context":
|
|
121
|
+
"""
|
|
122
|
+
Returns the default context.
|
|
123
|
+
"""
|
|
124
|
+
...
|
|
125
|
+
|
|
126
|
+
class ChannelDescriptor:
|
|
127
|
+
"""
|
|
128
|
+
Information about a channel
|
|
129
|
+
"""
|
|
130
|
+
|
|
131
|
+
id: int
|
|
132
|
+
topic: str
|
|
133
|
+
message_encoding: str
|
|
134
|
+
metadata: dict[str, str]
|
|
135
|
+
schema: "Schema" | None
|
|
136
|
+
|
|
137
|
+
SinkChannelFilter = Callable[[ChannelDescriptor], bool]
|
|
62
138
|
|
|
63
139
|
def start_server(
|
|
64
140
|
*,
|
|
65
|
-
name:
|
|
66
|
-
host:
|
|
67
|
-
port:
|
|
68
|
-
capabilities:
|
|
141
|
+
name: str | None = None,
|
|
142
|
+
host: str | None = "127.0.0.1",
|
|
143
|
+
port: int | None = 8765,
|
|
144
|
+
capabilities: list[Capability] | None = None,
|
|
69
145
|
server_listener: Any = None,
|
|
70
|
-
supported_encodings:
|
|
71
|
-
services:
|
|
72
|
-
asset_handler:
|
|
146
|
+
supported_encodings: list[str] | None = None,
|
|
147
|
+
services: list[Service] | None = None,
|
|
148
|
+
asset_handler: AssetHandler | None = None,
|
|
149
|
+
context: Context | None = None,
|
|
150
|
+
session_id: str | None = None,
|
|
151
|
+
channel_filter: SinkChannelFilter | None = None,
|
|
73
152
|
) -> WebSocketServer:
|
|
74
153
|
"""
|
|
75
154
|
Start a websocket server for live visualization.
|
|
76
155
|
"""
|
|
77
156
|
...
|
|
78
157
|
|
|
158
|
+
def start_cloud_sink(
|
|
159
|
+
*,
|
|
160
|
+
listener: Any = None,
|
|
161
|
+
supported_encodings: list[str] | None = None,
|
|
162
|
+
context: Context | None = None,
|
|
163
|
+
session_id: str | None = None,
|
|
164
|
+
) -> CloudSink:
|
|
165
|
+
"""
|
|
166
|
+
Connect to Foxglove Agent for remote visualization and teleop.
|
|
167
|
+
"""
|
|
168
|
+
...
|
|
169
|
+
|
|
79
170
|
def enable_logging(level: int) -> None:
|
|
80
171
|
"""
|
|
81
172
|
Forward SDK logs to python's logging facility.
|
|
@@ -98,19 +189,21 @@ def open_mcap(
|
|
|
98
189
|
path: str | Path,
|
|
99
190
|
*,
|
|
100
191
|
allow_overwrite: bool = False,
|
|
101
|
-
|
|
192
|
+
context: Context | None = None,
|
|
193
|
+
channel_filter: SinkChannelFilter | None = None,
|
|
194
|
+
writer_options: MCAPWriteOptions | None = None,
|
|
102
195
|
) -> MCAPWriter:
|
|
103
196
|
"""
|
|
104
197
|
Creates a new MCAP file for recording.
|
|
105
198
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
199
|
+
If a context is provided, the MCAP file will be associated with that context. Otherwise, the
|
|
200
|
+
global context will be used.
|
|
201
|
+
|
|
202
|
+
You must close the writer with close() or the with statement to ensure the file is correctly finished.
|
|
110
203
|
"""
|
|
111
204
|
...
|
|
112
205
|
|
|
113
|
-
def get_channel_for_topic(topic: str) -> BaseChannel:
|
|
206
|
+
def get_channel_for_topic(topic: str) -> BaseChannel | None:
|
|
114
207
|
"""
|
|
115
208
|
Get a previously-registered channel.
|
|
116
209
|
"""
|