slim-bindings 0.3.6__cp313-cp313-win_amd64.whl → 0.4.1__cp313-cp313-win_amd64.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 slim-bindings might be problematic. Click here for more details.

slim_bindings/__init__.py CHANGED
@@ -2,11 +2,14 @@
2
2
  # SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import asyncio
5
+ import datetime
5
6
  from typing import Optional
6
7
 
7
8
  from ._slim_bindings import ( # type: ignore[attr-defined]
8
9
  SESSION_UNSPECIFIED,
9
- PyAgentType,
10
+ PyIdentityProvider,
11
+ PyIdentityVerifier,
12
+ PyName,
10
13
  PyService,
11
14
  PySessionConfiguration,
12
15
  PySessionInfo,
@@ -21,6 +24,7 @@ from ._slim_bindings import ( # type: ignore[attr-defined]
21
24
  disconnect,
22
25
  get_default_session_config,
23
26
  get_session_config,
27
+ invite,
24
28
  publish,
25
29
  receive,
26
30
  remove_route,
@@ -32,6 +36,18 @@ from ._slim_bindings import ( # type: ignore[attr-defined]
32
36
  subscribe,
33
37
  unsubscribe,
34
38
  )
39
+ from ._slim_bindings import (
40
+ PyAlgorithm as PyAlgorithm,
41
+ )
42
+ from ._slim_bindings import (
43
+ PyKey as PyKey,
44
+ )
45
+ from ._slim_bindings import (
46
+ PyKeyData as PyKeyData,
47
+ )
48
+ from ._slim_bindings import (
49
+ PyKeyFormat as PyKeyFormat,
50
+ )
35
51
  from ._slim_bindings import (
36
52
  PySessionDirection as PySessionDirection,
37
53
  )
@@ -122,20 +138,18 @@ class Slim:
122
138
  def __init__(
123
139
  self,
124
140
  svc: PyService,
125
- organization: str,
126
- namespace: str,
127
- agent: str,
141
+ name: PyName,
128
142
  ):
129
143
  """
130
144
  Initialize a new SLIM instance. A SLIM instance is associated with a single
131
- local agent. The agent is identified by its organization, namespace, and name.
132
- The agent ID is determined by the provided service (svc).
145
+ local app. The app is identified by its organization, namespace, and name.
146
+ The unique ID is determined by the provided service (svc).
133
147
 
134
148
  Args:
135
149
  svc (PyService): The Python service instance for SLIM.
136
- organization (str): The organization of the agent.
137
- namespace (str): The namespace of the agent.
138
- agent (str): The name of the agent.
150
+ organization (str): The organization of the app.
151
+ namespace (str): The namespace of the app.
152
+ app (str): The name of the app.
139
153
  """
140
154
 
141
155
  # Initialize service
@@ -147,8 +161,8 @@ class Slim:
147
161
  }
148
162
 
149
163
  # Save local names
150
- self.local_name = PyAgentType(organization, namespace, agent)
151
- self.local_id = self.svc.id
164
+ name.id = svc.id
165
+ self.local_name = name
152
166
 
153
167
  # Create connection ID map
154
168
  self.conn_ids: dict[str, int] = {}
@@ -197,42 +211,39 @@ class Slim:
197
211
  @classmethod
198
212
  async def new(
199
213
  cls,
200
- organization: str,
201
- namespace: str,
202
- agent: str,
203
- agent_id: Optional[int] = None,
214
+ name: PyName,
215
+ provider: PyIdentityProvider,
216
+ verifier: PyIdentityVerifier,
204
217
  ) -> "Slim":
205
218
  """
206
- Create a new SLIM instance. A SLIM instamce is associated to one single
207
- local agent. The agent is identified by its organization, namespace and name.
208
- The agent ID is optional. If not provided, the agent will be created with a new ID.
219
+ Create a new SLIM instance. A SLIM instance is associated to one single
220
+ local app. The app is identified by its organization, namespace and name.
221
+ The app ID is optional. If not provided, the app will be created with a new ID.
209
222
 
210
223
  Args:
211
- organization (str): The organization of the agent.
212
- namespace (str): The namespace of the agent.
213
- agent (str): The name of the agent.
214
- agent_id (int): The ID of the agent. If not provided, a new ID will be created.
224
+ organization (str): The organization of the app.
225
+ namespace (str): The namespace of the app.
226
+ app (str): The name of the app.
227
+ app_id (int): The ID of the app. If not provided, a new ID will be created.
215
228
 
216
229
  Returns:
217
230
  Slim: A new SLIM instance
218
231
  """
219
232
 
220
233
  return cls(
221
- await create_pyservice(organization, namespace, agent, agent_id),
222
- organization,
223
- namespace,
224
- agent,
234
+ await create_pyservice(name, provider, verifier),
235
+ name,
225
236
  )
226
237
 
227
- def get_agent_id(self) -> int:
238
+ def get_id(self) -> int:
228
239
  """
229
- Get the ID of the agent.
240
+ Get the ID of the app.
230
241
 
231
242
  Args:
232
243
  None
233
244
 
234
245
  Returns:
235
- int: The ID of the agent.
246
+ int: The ID of the app.
236
247
  """
237
248
 
238
249
  return self.svc.id
@@ -416,7 +427,7 @@ class Slim:
416
427
  self.conn_id = conn_id
417
428
 
418
429
  # Subscribe to the local name
419
- await subscribe(self.svc, conn_id, self.local_name, self.local_id)
430
+ await subscribe(self.svc, conn_id, self.local_name)
420
431
 
421
432
  # return the connection ID
422
433
  return conn_id
@@ -438,103 +449,79 @@ class Slim:
438
449
 
439
450
  async def set_route(
440
451
  self,
441
- organization: str,
442
- namespace: str,
443
- agent: str,
444
- id: Optional[int] = None,
452
+ name: PyName,
445
453
  ):
446
454
  """
447
455
  Set route for outgoing messages via the connected SLIM instance.
448
456
 
449
457
  Args:
450
- organization (str): The organization of the agent.
451
- namespace (str): The namespace of the agent.
452
- agent (str): The name of the agent.
453
- id (int): Optional ID of the agent.
458
+ name (PyName): The name of the app or channel to route messages to.
454
459
 
455
460
  Returns:
456
461
  None
457
462
  """
458
463
 
459
- name = PyAgentType(organization, namespace, agent)
460
- await set_route(self.svc, self.conn_id, name, id)
464
+ await set_route(self.svc, self.conn_id, name)
461
465
 
462
466
  async def remove_route(
463
- self, organization: str, namespace: str, agent: str, id: Optional[int] = None
467
+ self,
468
+ name: PyName,
464
469
  ):
465
470
  """
466
471
  Remove route for outgoing messages via the connected SLIM instance.
467
472
 
468
473
  Args:
469
- organization (str): The organization of the agent.
470
- namespace (str): The namespace of the agent.
471
- agent (str): The name of the agent.
472
- id (int): Optional ID of the agent.
474
+ name (PyName): The name of the app or channel to remove the route for.
473
475
 
474
476
  Returns:
475
477
  None
476
478
  """
477
479
 
478
- name = PyAgentType(organization, namespace, agent)
479
- await remove_route(self.svc, self.conn_id, name, id)
480
+ await remove_route(self.svc, self.conn_id, name)
480
481
 
481
- async def subscribe(
482
- self, organization: str, namespace: str, agent: str, id: Optional[int] = None
483
- ):
482
+ async def subscribe(self, name: PyName):
484
483
  """
485
- Subscribe to receive messages for the given agent.
484
+ Subscribe to receive messages for the given name.
486
485
 
487
486
  Args:
488
- organization (str): The organization of the agent.
489
- namespace (str): The namespace of the agent.
490
- agent (str): The name of the agent.
491
- id (int): Optional ID of the agent.
487
+ name (PyName): The name to subscribe to. This can be an app or a channel.
492
488
 
493
489
  Returns:
494
490
  None
495
491
  """
496
492
 
497
- sub = PyAgentType(organization, namespace, agent)
498
- await subscribe(self.svc, self.conn_id, sub, id)
493
+ await subscribe(self.svc, self.conn_id, name)
499
494
 
500
- async def unsubscribe(
501
- self, organization: str, namespace: str, agent: str, id: Optional[int] = None
502
- ):
495
+ async def unsubscribe(self, name: PyName):
503
496
  """
504
- Unsubscribe from receiving messages for the given agent.
497
+ Unsubscribe from receiving messages for the given name.
505
498
 
506
499
  Args:
507
- organization (str): The organization of the agent.
508
- namespace (str): The namespace of the agent.
509
- agent (str): The name of the agent.
510
- id (int): Optional ID of the agent.
500
+ name (PyName): The name to unsubscribe from. This can be an app or a channel.
511
501
 
512
502
  Returns:
513
503
  None
514
504
  """
515
505
 
516
- unsub = PyAgentType(organization, namespace, agent)
517
- await unsubscribe(self.svc, self.conn_id, unsub, id)
506
+ await unsubscribe(self.svc, self.conn_id, name)
518
507
 
519
508
  async def publish(
520
509
  self,
521
510
  session: PySessionInfo,
522
511
  msg: bytes,
523
- organization: str,
524
- namespace: str,
525
- agent: str,
526
- agent_id: Optional[int] = None,
512
+ dest: PyName,
513
+ payload_type: Optional[str] = None,
514
+ metadata: Optional[dict] = None,
527
515
  ):
528
516
  """
529
- Publish a message to an agent via normal matching in subscription table.
517
+ Publish a message to an app or channel via normal matching in subscription table.
530
518
 
531
519
  Args:
532
520
  session (PySessionInfo): The session information.
533
521
  msg (str): The message to publish.
534
- organization (str): The organization of the agent.
535
- namespace (str): The namespace of the agent.
536
- agent (str): The name of the agent.
537
- agent_id (int): Optional ID of the agent.
522
+ dest (PyName): The destination name to publish the message to.
523
+ payload_type (str): The type of the message payload (optional)
524
+ metadata (dict): The metadata associated to the message (optional)
538
525
 
539
526
  Returns:
540
527
  None
@@ -544,28 +531,33 @@ class Slim:
544
531
  if session.id not in self.sessions:
545
532
  raise Exception("session not found", session.id)
546
533
 
547
- dest = PyAgentType(organization, namespace, agent)
548
- await publish(self.svc, session, 1, msg, dest, agent_id)
534
+ await publish(self.svc, session, 1, msg, dest, payload_type, metadata)
535
+
536
+ async def invite(
537
+ self,
538
+ session: PySessionInfo,
539
+ name: PyName,
540
+ ):
541
+ # Make sure the sessions exists
542
+ if session.id not in self.sessions:
543
+ raise Exception("session not found", session.id)
544
+
545
+ await invite(self.svc, session, name)
549
546
 
550
547
  async def request_reply(
551
548
  self,
552
549
  session: PySessionInfo,
553
550
  msg: bytes,
554
- organization: str,
555
- namespace: str,
556
- agent: str,
557
- agent_id: Optional[int] = None,
551
+ dest: PyName,
552
+ timeout: Optional[datetime.timedelta] = None,
558
553
  ) -> tuple[PySessionInfo, Optional[bytes]]:
559
554
  """
560
555
  Publish a message and wait for the first response.
561
556
 
562
557
  Args:
563
- msg (str): The message to publish.
564
558
  session (PySessionInfo): The session information.
565
- organization (str): The organization of the agent.
566
- namespace (str): The namespace of the agent.
567
- agent (str): The name of the agent.
568
- agent_id (int): Optional ID of the agent.
559
+ msg (str): The message to publish.
560
+ dest (PyName): The destination name to publish the message to.
569
561
 
570
562
  Returns:
571
563
  tuple: The PySessionInfo and the message.
@@ -575,18 +567,28 @@ class Slim:
575
567
  if session.id not in self.sessions:
576
568
  raise Exception("Session ID not found")
577
569
 
578
- dest = PyAgentType(organization, namespace, agent)
579
- await publish(self.svc, session, 1, msg, dest, agent_id)
570
+ await publish(self.svc, session, 1, msg, dest)
580
571
 
581
- # Wait for a reply in the corresponding session queue
582
- session_info, message = await self.receive(session.id)
572
+ # Wait for a reply in the corresponding session queue with timeout
573
+ if timeout is not None:
574
+ session_info, message = await asyncio.wait_for(
575
+ self.receive(session.id), timeout=timeout.total_seconds()
576
+ )
577
+ else:
578
+ session_info, message = await self.receive(session.id)
583
579
 
584
580
  return session_info, message
585
581
 
586
- async def publish_to(self, session, msg):
582
+ async def publish_to(
583
+ self,
584
+ session: PySessionInfo,
585
+ msg: bytes,
586
+ payload_type: Optional[str] = None,
587
+ metadata: Optional[dict] = None,
588
+ ):
587
589
  """
588
- Publish a message back to the agent that sent it.
589
- The information regarding the source agent is stored in the session.
590
+ Publish a message back to the application that sent it.
591
+ The information regarding the source app is stored in the session.
590
592
 
591
593
  Args:
592
594
  session (PySessionInfo): The session information.
@@ -596,7 +598,9 @@ class Slim:
596
598
  None
597
599
  """
598
600
 
599
- await publish(self.svc, session, 1, msg)
601
+ await publish(
602
+ self.svc, session, 1, msg, payload_type=payload_type, metadata=metadata
603
+ )
600
604
 
601
605
  async def receive(
602
606
  self, session: Optional[int] = None
@@ -623,7 +627,7 @@ class Slim:
623
627
  else:
624
628
  # Check if the session ID is in the sessions map
625
629
  if session not in self.sessions:
626
- raise Exception("Session ID not found")
630
+ raise Exception(f"Session ID not found: {session}")
627
631
 
628
632
  # Get the queue for the session
629
633
  queue = self.sessions[session][1]
@@ -5,31 +5,83 @@ import builtins
5
5
  import typing
6
6
  from enum import Enum, auto
7
7
 
8
- class PyAgentType:
9
- r"""
10
- agent class
11
- """
12
- organization: builtins.str
13
- namespace: builtins.str
14
- agent_type: builtins.str
15
- def __new__(cls,agent_org:builtins.str, agent_ns:builtins.str, agent_class:builtins.str): ...
8
+ class PyKey:
9
+ algorithm: PyAlgorithm
10
+ format: PyKeyFormat
11
+ key: PyKeyData
12
+ def __new__(cls,algorithm:PyAlgorithm, format:PyKeyFormat, key:PyKeyData): ...
16
13
 
17
- class PyRequestResponseConfiguration:
14
+ class PyName:
18
15
  r"""
19
- request response session config
16
+ name class
20
17
  """
21
- ...
18
+ id: builtins.int
19
+ def __new__(cls,component0:builtins.str, component1:builtins.str, component2:builtins.str, id:typing.Optional[builtins.int]=None): ...
20
+ def set_id(self, id:builtins.int) -> None:
21
+ ...
22
+
23
+ def components(self) -> builtins.list[builtins.int]:
24
+ ...
25
+
26
+ def components_strings(self) -> builtins.list[builtins.str]:
27
+ ...
28
+
29
+ def equal_without_id(self, name:PyName) -> builtins.bool:
30
+ ...
31
+
32
+ def __repr__(self) -> builtins.str:
33
+ ...
34
+
35
+ def __str__(self) -> builtins.str:
36
+ ...
37
+
22
38
 
23
39
  class PyService:
24
40
  id: builtins.int
41
+ name: PyName
25
42
 
26
43
  class PySessionInfo:
27
44
  id: builtins.int
45
+ source_name: PyName
46
+ destination_name: PyName
47
+ payload_type: builtins.str
48
+ metadata: builtins.dict[builtins.str, builtins.str]
28
49
  def __new__(cls,session_id:builtins.int): ...
29
50
 
51
+ class PyAlgorithm(Enum):
52
+ HS256 = auto()
53
+ HS384 = auto()
54
+ HS512 = auto()
55
+ RS256 = auto()
56
+ RS384 = auto()
57
+ RS512 = auto()
58
+ PS256 = auto()
59
+ PS384 = auto()
60
+ PS512 = auto()
61
+ ES256 = auto()
62
+ ES384 = auto()
63
+ EdDSA = auto()
64
+
65
+ class PyIdentityProvider(Enum):
66
+ StaticJwt = auto()
67
+ Jwt = auto()
68
+ SharedSecret = auto()
69
+
70
+ class PyIdentityVerifier(Enum):
71
+ Jwt = auto()
72
+ SharedSecret = auto()
73
+
74
+ class PyKeyData(Enum):
75
+ File = auto()
76
+ Content = auto()
77
+
78
+ class PyKeyFormat(Enum):
79
+ Pem = auto()
80
+ Jwk = auto()
81
+ Jwks = auto()
82
+
30
83
  class PySessionConfiguration(Enum):
31
84
  FireAndForget = auto()
32
- RequestResponse = auto()
33
85
  Streaming = auto()
34
86
 
35
87
  class PySessionDirection(Enum):
@@ -45,13 +97,12 @@ class PySessionType(Enum):
45
97
  session type
46
98
  """
47
99
  FIRE_AND_FORGET = auto()
48
- REQUEST_RESPONSE = auto()
49
100
  STREAMING = auto()
50
101
 
51
102
  def connect(svc:PyService, config:dict) -> typing.Any:
52
103
  ...
53
104
 
54
- def create_pyservice(organization:builtins.str, namespace:builtins.str, agent_type:builtins.str, id:typing.Optional[builtins.int]=None) -> typing.Any:
105
+ def create_pyservice(name:PyName, provider:PyIdentityProvider, verifier:PyIdentityVerifier) -> typing.Any:
55
106
  ...
56
107
 
57
108
  def create_session(svc:PyService, config:PySessionConfiguration) -> typing.Any:
@@ -72,13 +123,19 @@ def get_session_config(svc:PyService, session_id:builtins.int) -> typing.Any:
72
123
  def init_tracing(config:dict) -> typing.Any:
73
124
  ...
74
125
 
75
- def publish(svc:PyService, session_info:PySessionInfo, fanout:builtins.int, blob:typing.Sequence[builtins.int], name:typing.Optional[PyAgentType]=None, id:typing.Optional[builtins.int]=None) -> typing.Any:
126
+ def invite(svc:PyService, session_info:PySessionInfo, name:PyName) -> typing.Any:
127
+ ...
128
+
129
+ def publish(svc:PyService, session_info:PySessionInfo, fanout:builtins.int, blob:typing.Sequence[builtins.int], name:typing.Optional[PyName]=None, payload_type:typing.Optional[builtins.str]=None, metadata:typing.Optional[typing.Mapping[builtins.str, builtins.str]]=None) -> typing.Any:
76
130
  ...
77
131
 
78
132
  def receive(svc:PyService) -> typing.Any:
79
133
  ...
80
134
 
81
- def remove_route(svc:PyService, conn:builtins.int, name:PyAgentType, id:typing.Optional[builtins.int]=None) -> typing.Any:
135
+ def remove(svc:PyService, session_info:PySessionInfo, name:PyName) -> typing.Any:
136
+ ...
137
+
138
+ def remove_route(svc:PyService, conn:builtins.int, name:PyName) -> typing.Any:
82
139
  ...
83
140
 
84
141
  def run_server(svc:PyService, config:dict) -> typing.Any:
@@ -87,7 +144,7 @@ def run_server(svc:PyService, config:dict) -> typing.Any:
87
144
  def set_default_session_config(svc:PyService, config:PySessionConfiguration) -> typing.Any:
88
145
  ...
89
146
 
90
- def set_route(svc:PyService, conn:builtins.int, name:PyAgentType, id:typing.Optional[builtins.int]=None) -> typing.Any:
147
+ def set_route(svc:PyService, conn:builtins.int, name:PyName) -> typing.Any:
91
148
  ...
92
149
 
93
150
  def set_session_config(svc:PyService, session_id:builtins.int, config:PySessionConfiguration) -> typing.Any:
@@ -96,9 +153,9 @@ def set_session_config(svc:PyService, session_id:builtins.int, config:PySessionC
96
153
  def stop_server(svc:PyService, endpoint:builtins.str) -> typing.Any:
97
154
  ...
98
155
 
99
- def subscribe(svc:PyService, conn:builtins.int, name:PyAgentType, id:typing.Optional[builtins.int]=None) -> typing.Any:
156
+ def subscribe(svc:PyService, conn:builtins.int, name:PyName) -> typing.Any:
100
157
  ...
101
158
 
102
- def unsubscribe(svc:PyService, conn:builtins.int, name:PyAgentType, id:typing.Optional[builtins.int]=None) -> typing.Any:
159
+ def unsubscribe(svc:PyService, conn:builtins.int, name:PyName) -> typing.Any:
103
160
  ...
104
161
 
@@ -0,0 +1,61 @@
1
+ Metadata-Version: 2.4
2
+ Name: slim-bindings
3
+ Version: 0.4.1
4
+ Classifier: Development Status :: 3 - Alpha
5
+ Classifier: Intended Audience :: Developers
6
+ Classifier: Topic :: Software Development :: Libraries
7
+ Classifier: Programming Language :: Python :: 3.9
8
+ Classifier: Programming Language :: Python :: 3.10
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Summary: SLIM Rust bindings for Python
13
+ License: Apache-2.0
14
+ Requires-Python: >=3.9, <4.0
15
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
16
+ Project-URL: Repository, https://github.com/agntcy/slim
17
+ Project-URL: Issues, https://github.com/agntcy/slim/issues
18
+ Project-URL: Changelog, https://github.com/agntcy/slim/blob/main/data-plane/python-bindings/CHANGELOG.md
19
+
20
+ # SLIM Python Bindings
21
+
22
+ Bindings to call the SLIM APIs from a python program.
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ pip install slim-bindings
28
+ ```
29
+
30
+ ## Include as dependency
31
+
32
+ ### With pyproject.toml
33
+
34
+ ```toml
35
+ [project]
36
+ name = "slim-example"
37
+ version = "0.1.0"
38
+ description = "Python program using SLIM"
39
+ requires-python = ">=3.9"
40
+ dependencies = [
41
+ "slim-bindings>=0.1.0"
42
+ ]
43
+ ```
44
+
45
+ ### With poetry project
46
+
47
+ ```toml
48
+ [tool.poetry]
49
+ name = "slim-example"
50
+ version = "0.1.0"
51
+ description = "Python program using SLIM"
52
+
53
+ [tool.poetry.dependencies]
54
+ python = ">=3.9,<3.14"
55
+ slim-bindings = ">=0.1.0"
56
+ ```
57
+
58
+ ## Example programs
59
+
60
+ Example apps can be found in the [repo](https://github.com/agntcy/slim/tree/main/data-plane/python-bindings/examples/src/slim_bindings_examples)
61
+
@@ -0,0 +1,6 @@
1
+ slim_bindings-0.4.1.dist-info/METADATA,sha256=ns5vR5mH2RkfS4zNzxIicakzMqoVcsMZ1PPkrY1ZIgc,1613
2
+ slim_bindings-0.4.1.dist-info/WHEEL,sha256=oXe_QNnB5QbkkMcbfZh2d88Kje6edNs5JzpWke0-klE,96
3
+ slim_bindings/__init__.py,sha256=rbznLnV8PkidmL85t-CjH8goHZdk6u5dSRKQSFfSKyY,21082
4
+ slim_bindings/_slim_bindings.cp313-win_amd64.pyd,sha256=0JjFwzJ0AY60-lvsMLd8zyCMs3lkTJ6ZgVpSLNX9vPI,20797440
5
+ slim_bindings/_slim_bindings.pyi,sha256=xtYt9BVXAom8fNOUAwnYhRExECor_7IpRekM1SSwuX4,4166
6
+ slim_bindings-0.4.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: maturin (1.8.2)
2
+ Generator: maturin (1.9.1)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp313-cp313-win_amd64