slim-bindings 0.3.6__cp39-cp39-win_amd64.whl → 0.4.0__cp39-cp39-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,75 @@ 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,
527
513
  ):
528
514
  """
529
- Publish a message to an agent via normal matching in subscription table.
515
+ Publish a message to an app or channel via normal matching in subscription table.
530
516
 
531
517
  Args:
532
518
  session (PySessionInfo): The session information.
533
519
  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.
520
+ dest (PyName): The destination name to publish the message to.
538
521
 
539
522
  Returns:
540
523
  None
@@ -544,28 +527,33 @@ class Slim:
544
527
  if session.id not in self.sessions:
545
528
  raise Exception("session not found", session.id)
546
529
 
547
- dest = PyAgentType(organization, namespace, agent)
548
- await publish(self.svc, session, 1, msg, dest, agent_id)
530
+ await publish(self.svc, session, 1, msg, dest)
531
+
532
+ async def invite(
533
+ self,
534
+ session: PySessionInfo,
535
+ name: PyName,
536
+ ):
537
+ # Make sure the sessions exists
538
+ if session.id not in self.sessions:
539
+ raise Exception("session not found", session.id)
540
+
541
+ await invite(self.svc, session, name)
549
542
 
550
543
  async def request_reply(
551
544
  self,
552
545
  session: PySessionInfo,
553
546
  msg: bytes,
554
- organization: str,
555
- namespace: str,
556
- agent: str,
557
- agent_id: Optional[int] = None,
547
+ dest: PyName,
548
+ timeout: Optional[datetime.timedelta] = None,
558
549
  ) -> tuple[PySessionInfo, Optional[bytes]]:
559
550
  """
560
551
  Publish a message and wait for the first response.
561
552
 
562
553
  Args:
563
- msg (str): The message to publish.
564
554
  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.
555
+ msg (str): The message to publish.
556
+ dest (PyName): The destination name to publish the message to.
569
557
 
570
558
  Returns:
571
559
  tuple: The PySessionInfo and the message.
@@ -575,18 +563,22 @@ class Slim:
575
563
  if session.id not in self.sessions:
576
564
  raise Exception("Session ID not found")
577
565
 
578
- dest = PyAgentType(organization, namespace, agent)
579
- await publish(self.svc, session, 1, msg, dest, agent_id)
566
+ await publish(self.svc, session, 1, msg, dest)
580
567
 
581
- # Wait for a reply in the corresponding session queue
582
- session_info, message = await self.receive(session.id)
568
+ # Wait for a reply in the corresponding session queue with timeout
569
+ if timeout is not None:
570
+ session_info, message = await asyncio.wait_for(
571
+ self.receive(session.id), timeout=timeout.total_seconds()
572
+ )
573
+ else:
574
+ session_info, message = await self.receive(session.id)
583
575
 
584
576
  return session_info, message
585
577
 
586
578
  async def publish_to(self, session, msg):
587
579
  """
588
- Publish a message back to the agent that sent it.
589
- The information regarding the source agent is stored in the session.
580
+ Publish a message back to the application that sent it.
581
+ The information regarding the source app is stored in the session.
590
582
 
591
583
  Args:
592
584
  session (PySessionInfo): The session information.
@@ -5,31 +5,78 @@ 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 equal_without_id(self, name:PyName) -> builtins.bool:
27
+ ...
28
+
29
+ def __repr__(self) -> builtins.str:
30
+ ...
31
+
32
+ def __str__(self) -> builtins.str:
33
+ ...
34
+
22
35
 
23
36
  class PyService:
24
37
  id: builtins.int
38
+ name: PyName
25
39
 
26
40
  class PySessionInfo:
27
41
  id: builtins.int
42
+ source_name: PyName
43
+ destination_name: PyName
28
44
  def __new__(cls,session_id:builtins.int): ...
29
45
 
46
+ class PyAlgorithm(Enum):
47
+ HS256 = auto()
48
+ HS384 = auto()
49
+ HS512 = auto()
50
+ RS256 = auto()
51
+ RS384 = auto()
52
+ RS512 = auto()
53
+ PS256 = auto()
54
+ PS384 = auto()
55
+ PS512 = auto()
56
+ ES256 = auto()
57
+ ES384 = auto()
58
+ EdDSA = auto()
59
+
60
+ class PyIdentityProvider(Enum):
61
+ StaticJwt = auto()
62
+ Jwt = auto()
63
+ SharedSecret = auto()
64
+
65
+ class PyIdentityVerifier(Enum):
66
+ Jwt = auto()
67
+ SharedSecret = auto()
68
+
69
+ class PyKeyData(Enum):
70
+ File = auto()
71
+ Content = auto()
72
+
73
+ class PyKeyFormat(Enum):
74
+ Pem = auto()
75
+ Jwk = auto()
76
+ Jwks = auto()
77
+
30
78
  class PySessionConfiguration(Enum):
31
79
  FireAndForget = auto()
32
- RequestResponse = auto()
33
80
  Streaming = auto()
34
81
 
35
82
  class PySessionDirection(Enum):
@@ -45,13 +92,12 @@ class PySessionType(Enum):
45
92
  session type
46
93
  """
47
94
  FIRE_AND_FORGET = auto()
48
- REQUEST_RESPONSE = auto()
49
95
  STREAMING = auto()
50
96
 
51
97
  def connect(svc:PyService, config:dict) -> typing.Any:
52
98
  ...
53
99
 
54
- def create_pyservice(organization:builtins.str, namespace:builtins.str, agent_type:builtins.str, id:typing.Optional[builtins.int]=None) -> typing.Any:
100
+ def create_pyservice(name:PyName, provider:PyIdentityProvider, verifier:PyIdentityVerifier) -> typing.Any:
55
101
  ...
56
102
 
57
103
  def create_session(svc:PyService, config:PySessionConfiguration) -> typing.Any:
@@ -72,13 +118,19 @@ def get_session_config(svc:PyService, session_id:builtins.int) -> typing.Any:
72
118
  def init_tracing(config:dict) -> typing.Any:
73
119
  ...
74
120
 
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:
121
+ def invite(svc:PyService, session_info:PySessionInfo, name:PyName) -> typing.Any:
122
+ ...
123
+
124
+ def publish(svc:PyService, session_info:PySessionInfo, fanout:builtins.int, blob:typing.Sequence[builtins.int], name:typing.Optional[PyName]=None) -> typing.Any:
76
125
  ...
77
126
 
78
127
  def receive(svc:PyService) -> typing.Any:
79
128
  ...
80
129
 
81
- def remove_route(svc:PyService, conn:builtins.int, name:PyAgentType, id:typing.Optional[builtins.int]=None) -> typing.Any:
130
+ def remove(svc:PyService, session_info:PySessionInfo, name:PyName) -> typing.Any:
131
+ ...
132
+
133
+ def remove_route(svc:PyService, conn:builtins.int, name:PyName) -> typing.Any:
82
134
  ...
83
135
 
84
136
  def run_server(svc:PyService, config:dict) -> typing.Any:
@@ -87,7 +139,7 @@ def run_server(svc:PyService, config:dict) -> typing.Any:
87
139
  def set_default_session_config(svc:PyService, config:PySessionConfiguration) -> typing.Any:
88
140
  ...
89
141
 
90
- def set_route(svc:PyService, conn:builtins.int, name:PyAgentType, id:typing.Optional[builtins.int]=None) -> typing.Any:
142
+ def set_route(svc:PyService, conn:builtins.int, name:PyName) -> typing.Any:
91
143
  ...
92
144
 
93
145
  def set_session_config(svc:PyService, session_id:builtins.int, config:PySessionConfiguration) -> typing.Any:
@@ -96,9 +148,9 @@ def set_session_config(svc:PyService, session_id:builtins.int, config:PySessionC
96
148
  def stop_server(svc:PyService, endpoint:builtins.str) -> typing.Any:
97
149
  ...
98
150
 
99
- def subscribe(svc:PyService, conn:builtins.int, name:PyAgentType, id:typing.Optional[builtins.int]=None) -> typing.Any:
151
+ def subscribe(svc:PyService, conn:builtins.int, name:PyName) -> typing.Any:
100
152
  ...
101
153
 
102
- def unsubscribe(svc:PyService, conn:builtins.int, name:PyAgentType, id:typing.Optional[builtins.int]=None) -> typing.Any:
154
+ def unsubscribe(svc:PyService, conn:builtins.int, name:PyName) -> typing.Any:
103
155
  ...
104
156
 
@@ -0,0 +1,61 @@
1
+ Metadata-Version: 2.4
2
+ Name: slim-bindings
3
+ Version: 0.4.0
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.0.dist-info/METADATA,sha256=hr4h8oq0wGStSM1DxOZMcLgLL0MKsTvoVO-68FLS4Ug,1613
2
+ slim_bindings-0.4.0.dist-info/WHEEL,sha256=xZ8SzCfbQYp83o2fyM7cU7vfL9QFqpx9fTDOTKg2VCE,94
3
+ slim_bindings/__init__.py,sha256=Fc4C_14UmMh7QBK6xUWyvhjx1jQuS1qI9gawq81LO54,20589
4
+ slim_bindings/_slim_bindings.cp39-win_amd64.pyd,sha256=nZZPV-p7TIWbq52hHKetD906wNtsE8-kKbyvIwiuyHQ,20284416
5
+ slim_bindings/_slim_bindings.pyi,sha256=9TAVKmDg8Htq_ml7eeUDpnJPkDMPFfV5e4O7QvdhP9w,3872
6
+ slim_bindings-0.4.0.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: cp39-cp39-win_amd64