forked from eclipse-zenoh/zenoh-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.pyi
More file actions
1154 lines (956 loc) · 38.2 KB
/
__init__.pyi
File metadata and controls
1154 lines (956 loc) · 38.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
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
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# Copyright (c) 2024 ZettaScale Technology
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# ZettaScale Zenoh Team, <zenoh@zettascale.tech>
#
from collections.abc import Callable
from datetime import datetime
from enum import Enum, auto
from pathlib import Path
from typing import Any, Generic, Never, Self, TypeVar, final, overload
from . import handlers as handlers
from .handlers import Handler as Handler
_T = TypeVar("_T")
_H = TypeVar("_H")
_RustHandler = (
handlers.DefaultHandler[_T] | handlers.FifoChannel[_T] | handlers.RingChannel[_T]
)
_PythonCallback = Callable[[_T], Any]
_PythonHandler = tuple[_PythonCallback[_T], _H]
def _unstable(item: _T) -> _T:
"""marker for unstable functionality"""
@final
class ZError(Exception): ...
@final
class Config:
"""The main configuration structure for Zenoh."""
def __new__(cls) -> Self: ...
@classmethod
def from_env(cls) -> Self: ...
@classmethod
def from_file(cls, path: str | Path) -> Self: ...
@classmethod
def from_json5(cls, json: str) -> Self: ...
def get_json(self, key: str) -> Any: ...
def insert_json5(self, key: str, value: Any): ...
def __str__(self) -> str: ...
@final
class CongestionControl(Enum):
"""The kind of congestion control."""
DROP = auto()
BLOCK = auto()
BLOCK_FIRST = _unstable(auto())
DEFAULT = DROP
@final
class ConsolidationMode(Enum):
"""The kind of consolidation."""
AUTO = auto()
NONE = auto()
MONOTONIC = auto()
LATEST = auto()
DEFAULT = AUTO
@final
class Encoding:
"""Default encoding values used by Zenoh.
An encoding has a similar role to Content-type in HTTP: it indicates, when present, how data should be interpreted by the application.
Please note the Zenoh protocol does not impose any encoding value nor it operates on it. It can be seen as some optional metadata that is carried over by Zenoh in such a way the application may perform different operations depending on the encoding value.
A set of associated constants are provided to cover the most common encodings for user convenience. This is parcticular useful in helping Zenoh to perform additional network optimizations.
"""
def __new__(cls, encoding: str | None = None) -> Self: ...
def with_schema(self, schema: str) -> Self:
"""Set a schema to this encoding. Zenoh does not define what a schema is and its semantics are left to the implementer. E.g. a common schema for text/plain encoding is utf-8."""
def __eq__(self, other: _IntoEncoding) -> bool: ...
def __hash__(self) -> int: ...
def __str__(self) -> str: ...
ZENOH_BYTES: Self
"""Just some bytes.
Constant alias for string: "zenoh/bytes"."""
ZENOH_STRING: Self
"""A UTF-8 string.
Constant alias for string: "zenoh/string"."""
ZENOH_SERIALIZED: Self
"""Zenoh serialized data.
Constant alias for string: "zenoh/serialized"."""
APPLICATION_OCTET_STREAM: Self
"""An application-specific stream of bytes.
Constant alias for string: "application/octet-stream"."""
TEXT_PLAIN: Self
"""A textual file.
Constant alias for string: "text/plain"."""
APPLICATION_JSON: Self
"""JSON data intended to be consumed by an application.
Constant alias for string: "application/json"."""
TEXT_JSON: Self
"""JSON data intended to be human readable.
Constant alias for string: "text/json"."""
APPLICATION_CDR: Self
"""A Common Data Representation (CDR)-encoded data.
Constant alias for string: "application/cdr"""
APPLICATION_CBOR: Self
"""A Concise Binary Object Representation (CBOR)-encoded data.
Constant alias for string: "application/cbor"."""
APPLICATION_YAML: Self
"""YAML data intended to be consumed by an application.
Constant alias for string: "application/yaml"."""
TEXT_YAML: Self
"""YAML data intended to be human readable.
Constant alias for string: "text/yaml"."""
TEXT_JSON5: Self
"""JSON5 encoded data intended to be human readable.
Constant alias for string: "text/json5"."""
APPLICATION_PYTHON_SERIALIZED_OBJECT: Self
"""A Python object serialized using pickle.
Constant alias for string: "application/python-serialized-object"."""
APPLICATION_PROTOBUF: Self
"""An application-specific protobuf-encoded data.
Constant alias for string: "application/protobuf"."""
APPLICATION_JAVA_SERIALIZED_OBJECT: Self
"""A Java serialized object.
Constant alias for string: "application/java-serialized-object"."""
APPLICATION_OPENMETRICS_TEXT: Self
"""An openmetrics text data representation, commonly used by Prometheus.
Constant alias for string: "application/openmetrics-text"."""
IMAGE_PNG: Self
"""A Portable Network Graphics (PNG) image.
Constant alias for string: "image/png"."""
IMAGE_JPEG: Self
"""A Joint Photographic Experts Group (JPEG) image.
Constant alias for string: "image/jpeg"."""
IMAGE_GIF: Self
"""A Graphics Interchange Format (GIF) image.
Constant alias for string: "image/gif"."""
IMAGE_BMP: Self
"""A BitMap (BMP) image.
Constant alias for string: "image/bmp"."""
IMAGE_WEBP: Self
"""A Web Protable (WebP) image.
Constant alias for string: "image/webp"""
APPLICATION_XML: Self
"""An XML file intended to be consumed by an application.
Constant alias for string: "application/xml"."""
APPLICATION_X_WWW_FORM_URLENCODED: Self
"""An encoded a list of tuples, each consisting of a name and a value.
Constant alias for string: "application/x-www-form-urlencoded"."""
TEXT_HTML: Self
"""An HTML file.
Constant alias for string: "text/html"."""
TEXT_XML: Self
"""An XML file that is human readable.
Constant alias for string: "text/xml"."""
TEXT_CSS: Self
"""A CSS file.
Constant alias for string: "text/css"."""
TEXT_JAVASCRIPT: Self
"""A JavaScript file.
Constant alias for string: "text/javascript"."""
TEXT_MARKDOWN: Self
"""A MarkDown file.
Constant alias for string: "text/markdown"."""
TEXT_CSV: Self
"""A CSV file.
Constant alias for string: "text/csv"."""
APPLICATION_SQL: Self
"""An application-specific SQL query.
Constant alias for string: "application/sql"."""
APPLICATION_COAP_PAYLOAD: Self
"""Constrained Application Protocol (CoAP) data intended for CoAP-to-HTTP and HTTP-to-CoAP proxies.
Constant alias for string: "application/coap-payload"."""
APPLICATION_JSON_PATCH_JSON: Self
"""Defines a JSON document structure for expressing a sequence of operations to apply to a JSON document.
Constant alias for string: "application/json-patch+json"."""
APPLICATION_JSON_SEQ: Self
"""A JSON text sequence consists of any number of JSON texts, all encoded in UTF-8.
Constant alias for string: "application/json-seq"."""
APPLICATION_JSONPATH: Self
"""A JSONPath defines a string syntax for selecting and extracting JSON values from within a given JSON value.
Constant alias for string: "application/jsonpath"."""
APPLICATION_JWT: Self
"""A JSON Web Token (JWT).
Constant alias for string: "application/jwt"."""
APPLICATION_MP4: Self
"""An application-specific MPEG-4 encoded data, either audio or video.
Constant alias for string: "application/mp4"."""
APPLICATION_SOAP_XML: Self
"""A SOAP 1.2 message serialized as XML 1.0.
Constant alias for string: "application/soap+xml"."""
APPLICATION_YANG: Self
"""A YANG-encoded data commonly used by the Network Configuration Protocol (NETCONF).
Constant alias for string: "application/yang"."""
AUDIO_AAC: Self
"""A MPEG-4 Advanced Audio Coding (AAC) media.
Constant alias for string: "audio/aac"."""
AUDIO_FLAC: Self
"""A Free Lossless Audio Codec (FLAC) media.
Constant alias for string: "audio/flac"."""
AUDIO_MP4: Self
"""An audio codec defined in MPEG-1, MPEG-2, MPEG-4, or registered at the MP4 registration authority.
Constant alias for string: "audio/mp4"."""
AUDIO_OGG: Self
"""An Ogg-encapsulated audio stream.
Constant alias for string: "audio/ogg"."""
AUDIO_VORBIS: Self
"""A Vorbis-encoded audio stream.
Constant alias for string: "audio/vorbis"."""
VIDEO_H261: Self
"""An h261-encoded video stream.
Constant alias for string: "video/h261"."""
VIDEO_H263: Self
"""An h263-encoded video stream.
Constant alias for string: "video/h263"."""
VIDEO_H264: Self
"""An h264-encoded video stream.
Constant alias for string: "video/h264"."""
VIDEO_H265: Self
"""An h265-encoded video stream.
Constant alias for string: "video/h265"."""
VIDEO_H266: Self
"""An h266-encoded video stream.
Constant alias for string: "video/h266"."""
VIDEO_MP4: Self
"""A video codec defined in MPEG-1, MPEG-2, MPEG-4, or registered at the MP4 registration authority.
Constant alias for string: "video/mp4"."""
VIDEO_OGG: Self
"""An Ogg-encapsulated video stream.
Constant alias for string: "video/ogg"."""
VIDEO_RAW: Self
"""An uncompressed, studio-quality video stream.
Constant alias for string: "video/raw"."""
VIDEO_VP8: Self
"""A VP8-encoded video stream.
Constant alias for string: "video/vp8"."""
VIDEO_VP9: Self
"""A VP9-encoded video stream.
Constant alias for string: "video/vp9"."""
_IntoEncoding = Encoding | str
EntityId = int
@_unstable
@final
class EntityGlobalId:
@property
def zid(self) -> ZenohId:
"""Returns the `ZenohId`, i.e. the Zenoh session, this ID is associated to."""
@property
def eid(self) -> EntityId:
"""Returns the `EntityId` used to identify the entity in a Zenoh session."""
@final
class Hello:
@property
def whatami(self) -> WhatAmI: ...
@property
def zid(self) -> ZenohId: ...
@property
def locators(self) -> list[str]: ...
def __str__(self) -> str: ...
@final
class KeyExpr:
"""A possibly-owned version of keyexpr that may carry optimisations for use with a Session that may have declared it.
Check keyexpr's documentation for detailed explainations of the Key Expression Language
"""
def __new__(cls, key_expr: str) -> Self: ...
@classmethod
def autocanonize(cls, key_expr: str) -> Self:
"""Canonizes the passed value before returning it as a KeyExpr.
Will return Err if the passed value isn't a valid key expression despite canonization.
"""
def intersects(self, other: _IntoKeyExpr) -> bool:
"""Returns true if the keyexprs intersect, i.e. there exists at least one key which is contained in both of the sets defined by self and other."""
def includes(self, other: _IntoKeyExpr) -> bool:
"""Returns true if self includes other, i.e. the set defined by self contains every key belonging to the set defined by other."""
@_unstable
def relation_to(self, other: _IntoKeyExpr) -> SetIntersectionLevel:
"""Returns the relation between self and other from self's point of view (SetIntersectionLevel::Includes signifies that self includes other).
Note that this is slower than keyexpr::intersects and keyexpr::includes, so you should favor these methods for most applications.
"""
def join(self, other: str) -> KeyExpr:
"""Joins both sides, inserting a / in between them.
This should be your prefered method when concatenating path segments."""
def concat(self, other: str) -> KeyExpr:
"""Performs string concatenation and returns the result as a KeyExpr if possible.
You should probably prefer KeyExpr::join as Zenoh may then take advantage of the hierachical separation it inserts.
"""
def __str__(self) -> str: ...
_IntoKeyExpr = KeyExpr | str
@final
class Liveliness:
def declare_token(self, key_expr: _IntoKeyExpr) -> LivelinessToken:
"""Create a LivelinessToken for the given key expression."""
@overload
def get(
self,
key_expr: _IntoKeyExpr,
handler: _RustHandler[Reply] | None = None,
*,
timeout: float | int | None = None,
) -> Handler[Reply]:
"""Query liveliness tokens with matching key expressions."""
@overload
def get(
self,
key_expr: _IntoKeyExpr,
handler: _PythonHandler[Reply, _H],
*,
timeout: float | int | None = None,
) -> _H:
"""Query liveliness tokens with matching key expressions."""
@overload
def get(
self,
key_expr: _IntoKeyExpr,
handler: _PythonCallback[Reply],
*,
timeout: float | int | None = None,
) -> None:
"""Query liveliness tokens with matching key expressions."""
@overload
def declare_subscriber(
self,
key_expr: _IntoKeyExpr,
handler: _RustHandler[Sample] | None = None,
*,
history: bool | None = None,
) -> Subscriber[Handler[Sample]]:
"""Create a Subscriber for liveliness changes matching the given key expression."""
@overload
def declare_subscriber(
self,
key_expr: _IntoKeyExpr,
handler: _PythonHandler[Sample, _H],
*,
history: bool | None = None,
) -> Subscriber[_H]:
"""Create a Subscriber for liveliness changes matching the given key expression."""
@overload
def declare_subscriber(
self,
key_expr: _IntoKeyExpr,
handler: _PythonCallback[Sample],
*,
history: bool | None = None,
) -> Subscriber[None]:
"""Create a Subscriber for liveliness changes matching the given key expression."""
@final
class LivelinessToken:
def __enter__(self) -> Self: ...
def __exit__(self, *_args, **_kwargs): ...
def undeclare(self):
"""Undeclare the LivelinessToken."""
@final
class Parameters:
def __new__(cls, parameters: dict[str, str] | str | None = None): ...
def is_empty(self) -> bool:
"""Returns true if properties does not contain anything."""
def get(self, key: str, default: str | None = None) -> str | None:
"""Returns the value corresponding to the key."""
def values(self, key: str) -> list[str]:
"""Returns the list of values corresponding to the key."""
def insert(self, key: str, value: str):
"""Inserts a key-value pair into the map. If the map did not have this key present, None` is returned. If the map did have this key present, the value is updated, and the old value is returned."""
def remove(self, key: str):
"""Removes a key from the map, returning the value at the key if the key was previously in the properties."""
def extend(self, parameters: _IntoParameters):
"""Extend these properties with other properties."""
def is_ordered(self) -> bool:
"""Returns `true` if all keys are sorted in alphabetical order."""
def __bool__(self) -> bool: ...
def __contains__(self, item: str) -> bool: ...
def __getitem__(self, item: str) -> str | None: ...
def __iter__(self) -> list[tuple[str, str]]: ...
def __str__(self) -> str: ...
_IntoParameters = Parameters | dict[str, str] | str
@final
class Priority(Enum):
"""The Priority of zenoh messages."""
REAL_TIME = auto()
INTERACTIVE_HIGH = auto()
INTERACTIVE_LOW = auto()
DATA_HIGH = auto()
DATA = auto()
DATA_LOW = auto()
BACKGROUND = auto()
DEFAULT = DATA
MIN = BACKGROUND
MAX = REAL_TIME
@final
class Publisher:
"""A publisher that allows to send data through a stream.
Publishers are automatically undeclared when dropped."""
def __enter__(self) -> Self: ...
def __exit__(self, *_args, **_kwargs): ...
@property
def key_expr(self) -> KeyExpr: ...
@property
def encoding(self) -> Encoding: ...
@property
def congestion_control(self) -> CongestionControl: ...
@property
def priority(self) -> Priority: ...
@property
@_unstable
def reliability(self) -> Reliability: ...
def put(
self,
payload: _IntoZBytes,
*,
encoding: _IntoEncoding | None = None,
attachment: _IntoZBytes | None = None,
):
"""Put data."""
def delete(self, *, attachment: _IntoZBytes | None = None):
"""Delete data."""
def undeclare(self):
"""Undeclares the Publisher, informing the network that it needn't optimize publications for its key expression anymore."""
@final
class Query:
"""Structs received by a Queryable."""
def __enter__(self) -> Self: ...
def __exit__(self, *_args, **_kwargs): ...
@property
def selector(self) -> Selector: ...
@property
def key_expr(self) -> KeyExpr: ...
@property
def parameters(self) -> Parameters: ...
@property
def payload(self) -> ZBytes | None: ...
@property
def encoding(self) -> Encoding | None: ...
@property
def attachment(self) -> ZBytes | None: ...
def reply(
self,
key_expr: _IntoKeyExpr,
payload: _IntoZBytes,
*,
encoding: _IntoEncoding | None = None,
congestion_control: CongestionControl | None = None,
priority: Priority | None = None,
express: bool | None = None,
attachment: _IntoZBytes | None = None,
):
"""Sends a reply to this Query.
By default, queries only accept replies whose key expression intersects with the query's. Unless the query has enabled disjoint replies (you can check this through Query::accepts_replies), replying on a disjoint key expression will result in an error when resolving the reply.
"""
def reply_err(self, payload: _IntoZBytes, *, encoding: _IntoEncoding | None = None):
"""Sends an error reply to this Query."""
def reply_del(
self,
key_expr: _IntoKeyExpr,
*,
congestion_control: CongestionControl | None = None,
priority: Priority | None = None,
express: bool | None = None,
attachment: _IntoZBytes | None = None,
):
"""Sends a delete reply to this Query.
By default, queries only accept replies whose key expression intersects with the query's. Unless the query has enabled disjoint replies (you can check this through Query::accepts_replies), replying on a disjoint key expression will result in an error when resolving the reply.
"""
def drop(self):
"""Drop the instance of a query.
The query will only be finalized when all query instances (one per queryable
matched) are dropped. Finalization is required to not have query hanging
on the querier side.
This method should be called after handling the query, as Python finalizers
are not reliable, especially when it comes to loop variables. It is also
possible, and advised, to use query context manager, which calls `drop` on
exit. Once a query is dropped, it's no more possible to use it, and its
methods will raise an exception.
"""
def __str__(self) -> str: ...
@final
class Queryable(Generic[_H]):
"""A queryable that provides data through a Handler.
Queryables can be created from a zenoh Session with the declare_queryable function and the with function of the resulting builder.
Queryables are automatically undeclared when dropped."""
def __enter__(self) -> Self: ...
def __exit__(self, *_args, **_kwargs): ...
@property
def key_expr(self) -> KeyExpr: ...
@property
def handler(self) -> _H: ...
def undeclare(self): ...
@overload
def try_recv(self: Queryable[handlers.Handler[Query]]) -> Query | None: ...
@overload
def try_recv(self) -> Never: ...
@overload
def recv(self: Queryable[handlers.Handler[Query]]) -> Query: ...
@overload
def recv(self) -> Never: ...
@overload
def __iter__(self: Queryable[Handler[Query]]) -> Handler[Query]: ...
@overload
def __iter__(self) -> Never: ...
@_unstable
@final
class Querier:
"""A querier that allows to send queries to a queryable.
Queriers are automatically undeclared when dropped."""
def __enter__(self) -> Self: ...
def __exit__(self, *_args, **_kwargs): ...
@property
def key_expr(self) -> KeyExpr: ...
@overload
def get(
self,
handler: _RustHandler[Reply] | None = None,
*,
parameters: _IntoParameters | None = None,
payload: _IntoZBytes | None = None,
encoding: _IntoEncoding | None = None,
attachment: _IntoZBytes | None = None,
) -> Handler[Reply]:
"""Sends a query."""
@overload
def get(
self,
handler: _PythonHandler[Reply, _H],
*,
parameters: _IntoParameters | None = None,
payload: _IntoZBytes | None = None,
encoding: _IntoEncoding | None = None,
attachment: _IntoZBytes | None = None,
) -> _H:
"""Sends a query."""
@overload
def get(
self,
handler: _PythonCallback[Reply],
*,
parameters: _IntoParameters | None = None,
payload: _IntoZBytes | None = None,
encoding: _IntoEncoding | None = None,
attachment: _IntoZBytes | None = None,
) -> None:
"""Send a query."""
def undeclare(self):
"""Undeclares the Querier, informing the network that it needn't optimize queries for its key expression anymore."""
@final
class QueryConsolidation:
AUTO: Self
DEFAULT: Self
def __new__(cls, mode: ConsolidationMode, /) -> Self: ...
@property
def mode(self) -> ConsolidationMode: ...
_IntoQueryConsolidation = ConsolidationMode
@final
class QueryTarget(Enum):
"""The kind of consolidation used."""
BEST_MATCHING = auto()
ALL = auto()
ALL_COMPLETE = auto()
DEFAULT = BEST_MATCHING
@final
@_unstable
class Reliability(Enum):
BEST_EFFORT = auto()
RELIABLE = auto()
@final
class Reply:
"""Structs returned by a get."""
@property
def result(self) -> Sample | ReplyError: ...
@property
def ok(self) -> Sample | None: ...
@property
def err(self) -> ReplyError | None: ...
@property
@_unstable
def replier_id(self) -> ZenohId | None: ...
@final
class ReplyError:
@property
def payload(self) -> ZBytes: ...
@property
def encoding(self) -> Encoding: ...
@final
class SampleKind(Enum):
PUT = auto()
DELETE = auto()
@final
class Sample:
@property
def key_expr(self) -> KeyExpr:
"""Gets the key expression on which this Sample was published."""
@property
def payload(self) -> ZBytes:
"""Gets the payload of this Sample."""
@property
def kind(self) -> SampleKind:
"""Gets the kind of this Sample."""
@property
def encoding(self) -> Encoding:
"""Gets the encoding of this sample."""
@property
def timestamp(self) -> Timestamp:
"""Gets the timestamp of this Sample."""
@property
def congestion_control(self) -> CongestionControl:
"""Gets the congestion control of this Sample."""
@property
def priority(self) -> Priority:
"""Gets the priority of this Sample."""
@property
def express(self) -> bool:
"""Gets the express flag value.
If true, the message is not batched during transmission, in order to reduce latency.
"""
@property
def attachment(self) -> ZBytes | None: ...
@final
class Scout(Generic[_H]):
def __enter__(self) -> Self: ...
def __exit__(self, *_args, **_kwargs): ...
@property
def handler(self) -> _H: ...
def stop(self): ...
@overload
def try_recv(self: Scout[Handler[Hello]]) -> Hello | None: ...
@overload
def try_recv(self: Scout[Any]) -> Never: ...
@overload
def recv(self: Scout[Handler[Hello]]) -> Hello: ...
@overload
def recv(self) -> Never: ...
@overload
def __iter__(self: Scout[Handler[Hello]]) -> Handler[Hello]: ...
@overload
def __iter__(self) -> Never: ...
@final
class Selector:
"""A selector is the combination of a Key Expression, which defines the set of keys that are relevant to an operation, and a set of parameters with a few intendend uses:
specifying arguments to a queryable, allowing the passing of Remote Procedure Call parameters
filtering by value,
filtering by metadata, such as the timestamp of a value,
specifying arguments to zenoh when using the REST API.
When in string form, selectors look a lot like a URI, with similar semantics:
the key_expr before the first ? must be a valid key expression.
the parameters after the first ? should be encoded like the query section of a URL:
parameters are separated by &,
the parameter name and value are separated by the first =,
in the absence of =, the parameter value is considered to be the empty string,
both name and value should use percent-encoding (URL-encoding) to escape characters,
defining a value for the same parameter name twice is considered undefined behavior, with the encouraged behaviour being to reject operations when a duplicate parameter is detected.
Zenoh intends to standardize the usage of a set of parameter names. To avoid conflicting with RPC parameters, the Zenoh team has settled on reserving the set of parameter names that start with non-alphanumeric characters.
The full specification for selectors is available here , it includes standardized parameters.
Queryable implementers are encouraged to prefer these standardized parameter names when implementing their associated features, and to prefix their own parameter names to avoid having conflicting parameter names with other queryables.
Here are the currently standardized parameters for Zenoh (check the specification page for the exhaustive list):
_time: used to express interest in only values dated within a certain time range, values for this parameter must be readable by the Zenoh Time DSL for the value to be considered valid.
[unstable] _anyke: used in queries to express interest in replies coming from any key expression. By default, only replies whose key expression match query's key expression are accepted. _anyke disables the query-reply key expression matching check.
"""
def __new__(
cls, arg: _IntoKeyExpr | str, /, parameters: _IntoParameters | None = None
): ...
@property
def key_expr(self) -> KeyExpr: ...
@key_expr.setter
def key_expr(self, key_expr: _IntoKeyExpr): ...
@property
def parameters(self) -> Parameters: ...
@parameters.setter
def parameters(self, parameters: _IntoParameters): ...
def __str__(self) -> str: ...
_IntoSelector = Selector | _IntoKeyExpr
@final
class Session:
"""A zenoh session."""
def __enter__(self) -> Self: ...
def __exit__(self, *_args, **_kwargs): ...
@property
def info(self) -> SessionInfo: ...
def zid(self) -> ZenohId:
"""Returns the identifier of the current session. zid() is a convenient shortcut."""
def close(self):
"""Close the zenoh Session.
Sessions are automatically closed when dropped, but you may want to use this function to handle errors or close the Session asynchronously.
"""
def is_closed(self) -> bool:
"""Check if the session has been closed."""
def undeclare(self, obj: KeyExpr): ...
def new_timestamp(self) -> Timestamp:
"""Get a new Timestamp from a Zenoh session.
The returned timestamp has the current time, with the session's runtime ZenohId.
"""
def declare_keyexpr(self, key_expr: _IntoKeyExpr):
"""Informs Zenoh that you intend to use the provided key_expr multiple times and that it should optimize its transmission.
The returned KeyExpr's internal structure may differ from what you would have obtained through a simple key_expr.try_into(), to save time on detecting the optimizations that have been associated with it.
"""
def put(
self,
key_expr: _IntoKeyExpr,
payload: _IntoZBytes,
*,
encoding: _IntoEncoding | None = None,
congestion_control: CongestionControl | None = None,
priority: Priority | None = None,
express: bool | None = None,
attachment: _IntoZBytes | None = None,
):
"""Put data on zenoh for a given key expression."""
def delete(
self,
key_expr: _IntoKeyExpr,
*,
congestion_control: CongestionControl | None = None,
priority: Priority | None = None,
express: bool | None = None,
attachment: _IntoZBytes | None = None,
):
"""Delete data for a given key expression."""
@overload
def get(
self,
selector: _IntoSelector,
handler: _RustHandler[Reply] | None = None,
*,
target: QueryTarget | None = None,
consolidation: _IntoQueryConsolidation | None = None,
timeout: float | int | None = None,
congestion_control: CongestionControl | None = None,
priority: Priority | None = None,
express: bool | None = None,
payload: _IntoZBytes = None,
encoding: _IntoEncoding | None = None,
attachment: _IntoZBytes | None = None,
) -> Handler[Reply]:
"""Query data from the matching queryables in the system.
Unless explicitly requested via GetBuilder::accept_replies, replies are guaranteed to have key expressions that match the requested selector.
"""
@overload
def get(
self,
selector: _IntoSelector,
handler: _PythonHandler[Reply, _H],
*,
target: QueryTarget | None = None,
consolidation: _IntoQueryConsolidation | None = None,
timeout: float | int | None = None,
congestion_control: CongestionControl | None = None,
priority: Priority | None = None,
express: bool | None = None,
payload: _IntoZBytes = None,
encoding: _IntoEncoding | None = None,
attachment: _IntoZBytes | None = None,
) -> _H:
"""Query data from the matching queryables in the system.
Unless explicitly requested via GetBuilder::accept_replies, replies are guaranteed to have key expressions that match the requested selector.
"""
@overload
def get(
self,
selector: _IntoSelector,
handler: _PythonCallback[Reply],
*,
target: QueryTarget | None = None,
consolidation: _IntoQueryConsolidation | None = None,
timeout: float | int | None = None,
congestion_control: CongestionControl | None = None,
priority: Priority | None = None,
express: bool | None = None,
payload: _IntoZBytes = None,
encoding: _IntoEncoding | None = None,
attachment: _IntoZBytes | None = None,
) -> None:
"""Query data from the matching queryables in the system.
Unless explicitly requested via GetBuilder::accept_replies, replies are guaranteed to have key expressions that match the requested selector.
"""
@overload
def declare_subscriber(
self, key_expr: _IntoKeyExpr, handler: _RustHandler[Sample] | None = None
) -> Subscriber[Handler[Sample]]:
"""Create a Subscriber for the given key expression."""
@overload
def declare_subscriber(
self, key_expr: _IntoKeyExpr, handler: _PythonHandler[Sample, _H]
) -> Subscriber[_H]:
"""Create a Subscriber for the given key expression."""
@overload
def declare_subscriber(
self, key_expr: _IntoKeyExpr, handler: _PythonCallback[Sample]
) -> Subscriber[None]:
"""Create a Subscriber for the given key expression."""
@overload
def declare_queryable(
self,
key_expr: _IntoKeyExpr,
handler: _RustHandler[Query] | None = None,
*,
complete: bool | None = None,
) -> Queryable[Handler[Query]]:
"""Create a Queryable for the given key expression."""
@overload
def declare_queryable(
self,
key_expr: _IntoKeyExpr,
handler: _PythonHandler[Query, _H],
*,
complete: bool | None = None,
) -> Queryable[_H]:
"""Create a Queryable for the given key expression."""
@overload
def declare_queryable(
self,
key_expr: _IntoKeyExpr,
handler: _PythonCallback[Query],
*,
complete: bool | None = None,
) -> Queryable[None]:
"""Create a Queryable for the given key expression."""
def declare_publisher(
self,
key_expr: _IntoKeyExpr,
*,
encoding: _IntoEncoding | None = None,
congestion_control: CongestionControl | None = None,
priority: Priority | None = None,
express: bool | None = None,
reliability: Reliability | None = None,
) -> Publisher:
"""Create a Publisher for the given key expression."""
@_unstable
def declare_querier(
self,
key_expr: _IntoKeyExpr,
*,
target: QueryTarget | None = None,
consolidation: _IntoQueryConsolidation | None = None,
timeout: float | int | None = None,
congestion_control: CongestionControl | None = None,
priority: Priority | None = None,
express: bool | None = None,
) -> Querier:
"""Create a Querier for the given key expression."""
def liveliness(self) -> Liveliness:
"""Obtain a Liveliness instance tied to this Zenoh session."""