tigerbeetle 0.16.56__py3-none-any.whl → 0.16.57__py3-none-any.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.
tigerbeetle/__init__.py CHANGED
@@ -1,5 +1,5 @@
1
1
  from .bindings import * # noqa
2
- from .client import ClientAsync, ClientSync, id, amount_max, configure_logging # noqa
2
+ from .client import ClientAsync, ClientSync, id, amount_max, configure_logging, PacketError # noqa
3
3
  from .lib import IntegerOverflowError, NativeError
4
4
 
5
5
  # Explicitly declare public exports:
tigerbeetle/client.py CHANGED
@@ -155,12 +155,6 @@ class Client:
155
155
  c_event_type=c_event_type,
156
156
  c_result_type=c_result_type)
157
157
 
158
- def close(self) -> None:
159
- bindings.tb_client_deinit(ctypes.byref(self._client))
160
- tb_assert(self._client is not None)
161
- tb_assert(len(self._inflight_packets) == 0)
162
- del Client._clients[self._client_key]
163
-
164
158
  @staticmethod
165
159
  @bindings.OnCompletion # type: ignore[misc]
166
160
  def _c_on_completion(completion_ctx: int, packet: Any, timestamp: int, bytes_ptr: Any, len_: int) -> None:
@@ -200,12 +194,6 @@ class Client:
200
194
 
201
195
  inflight_packet.on_completion(inflight_packet)
202
196
 
203
- def __enter__(self) -> Self:
204
- return self
205
-
206
- def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
207
- self.close()
208
-
209
197
 
210
198
  class ClientSync(Client, bindings.StateMachineMixin):
211
199
  def _on_completion(self, inflight_packet: InflightPacket) -> None:
@@ -235,6 +223,19 @@ class ClientSync(Client, bindings.StateMachineMixin):
235
223
 
236
224
  return inflight_packet.response
237
225
 
226
+ def close(self) -> None:
227
+ tb_assert(self._client is not None)
228
+ bindings.tb_client_deinit(ctypes.byref(self._client))
229
+
230
+ tb_assert(len(self._inflight_packets) == 0)
231
+ del Client._clients[self._client_key]
232
+
233
+ def __enter__(self) -> Self:
234
+ return self
235
+
236
+ def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
237
+ self.close()
238
+
238
239
 
239
240
  class ClientAsync(Client, bindings.AsyncStateMachineMixin):
240
241
  def _on_completion(self, inflight_packet: InflightPacket) -> None:
@@ -280,6 +281,32 @@ class ClientAsync(Client, bindings.AsyncStateMachineMixin):
280
281
 
281
282
  return inflight_packet.response
282
283
 
284
+ async def close(self) -> None:
285
+ tb_assert(self._client is not None)
286
+ bindings.tb_client_deinit(ctypes.byref(self._client))
287
+
288
+ # tb_client_deinit internally clears any inflight requests, and calls their callbacks, so
289
+ # the client needs to stick around until that's done.
290
+ #
291
+ # This isn't a problem for ClientSync, but ClientAsync invokes the callbacks using
292
+ # call_soon_threadsafe(), so wait for the event to fire on all pending packets.
293
+ all_events = []
294
+ for packet in self._inflight_packets.values():
295
+ if not isinstance(packet.on_completion_context, CompletionContextAsync):
296
+ raise AssertionError()
297
+ all_events.append(packet.on_completion_context.event.wait())
298
+
299
+ await asyncio.gather(*all_events)
300
+
301
+ tb_assert(len(self._inflight_packets) == 0)
302
+ del Client._clients[self._client_key]
303
+
304
+ async def __aenter__(self) -> Self:
305
+ return self
306
+
307
+ async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
308
+ await self.close()
309
+
283
310
 
284
311
  @bindings.LogHandler # type: ignore[misc]
285
312
  def log_handler(level_zig: bindings.LogLevel, message_ptr: Any, message_len: int) -> None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tigerbeetle
3
- Version: 0.16.56
3
+ Version: 0.16.57
4
4
  Summary: The TigerBeetle client for Python.
5
5
  Project-URL: Homepage, https://github.com/tigerbeetle/tigerbeetle
6
6
  Project-URL: Issues, https://github.com/tigerbeetle/tigerbeetle/issues
@@ -91,6 +91,11 @@ environment variable and defaults to port `3000`.
91
91
  with tb.ClientSync(cluster_id=0, replica_addresses=os.getenv("TB_ADDRESS", "3000")) as client:
92
92
  # Use the client.
93
93
  pass
94
+
95
+ # Alternatively:
96
+ async with tb.ClientAsync(cluster_id=0, replica_addresses=os.getenv("TB_ADDRESS", "3000")) as client:
97
+ # Use the client, async!
98
+ pass
94
99
  ```
95
100
 
96
101
  The following are valid addresses:
@@ -0,0 +1,15 @@
1
+ tigerbeetle/__init__.py,sha256=vrZ9rqFxHpXtACa9qDhwKwSkhv3CGhAvg7vF3Ges8c0,957
2
+ tigerbeetle/bindings.py,sha256=NSND7UuFpnd4TRBDA9aDJLRS115QNi3m0dVksekVlZg,28155
3
+ tigerbeetle/client.py,sha256=iLvRvUk-_YNip2ZIzPV3C5BbqjvlYa4vHDXbQpAoDnU,12048
4
+ tigerbeetle/lib.py,sha256=1Qln-Z4ZoCHJJ43sXlJJEs7-ZY5aZJjNNu7eISooAK8,2432
5
+ tigerbeetle/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ tigerbeetle/lib/aarch64-linux-gnu.2.27/libtb_client.so,sha256=9Ni-kr77uva3dIxwq6g89rxdbC0LuiDPbXYu7d8ZDrQ,693336
7
+ tigerbeetle/lib/aarch64-linux-musl/libtb_client.so,sha256=o3VknLRJjkZpBWlPO33KBclshNtrX7teHgvixKUiD1A,691616
8
+ tigerbeetle/lib/aarch64-macos/libtb_client.dylib,sha256=zqXLlUX1V2yJdG_8YbdVux7LsIFykZuuf2hjdgrsMBE,700224
9
+ tigerbeetle/lib/x86_64-linux-gnu.2.27/libtb_client.so,sha256=9WKWUV7QqmntjceqIu8-iD90zONv6Y2HW8riHYwyFyE,816808
10
+ tigerbeetle/lib/x86_64-linux-musl/libtb_client.so,sha256=6d7__mj4Vfc_WrHG6HuCBeCrE8g__awoQnlQvenG3b4,815256
11
+ tigerbeetle/lib/x86_64-macos/libtb_client.dylib,sha256=3MX0n9AdFfq3pjXgahavPiob6DEfEGA8-xz_pOoOYB4,792590
12
+ tigerbeetle/lib/x86_64-windows/tb_client.dll,sha256=R53xX0nn3hTgVoeR8jQLL8w7M5d00jbZf5IyaVoD_ek,664064
13
+ tigerbeetle-0.16.57.dist-info/METADATA,sha256=1EUIAa2ekf9x41mGf9dLHGaRIsu5ZW0b3ILqnK4Ac-E,23426
14
+ tigerbeetle-0.16.57.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
15
+ tigerbeetle-0.16.57.dist-info/RECORD,,
@@ -1,15 +0,0 @@
1
- tigerbeetle/__init__.py,sha256=L9lyq47kzyZO0uXR455LXZTXWrt7yxfs-pFs8Mfv-r4,944
2
- tigerbeetle/bindings.py,sha256=NSND7UuFpnd4TRBDA9aDJLRS115QNi3m0dVksekVlZg,28155
3
- tigerbeetle/client.py,sha256=QaHWXeDvLYGia1IOUArR5rNShka9y3GwveFELCcoXwY,10967
4
- tigerbeetle/lib.py,sha256=1Qln-Z4ZoCHJJ43sXlJJEs7-ZY5aZJjNNu7eISooAK8,2432
5
- tigerbeetle/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- tigerbeetle/lib/aarch64-linux-gnu.2.27/libtb_client.so,sha256=qPbLSTvbDH49ePtGNuxciy9QYrd_LGSsRkMeEJNNa98,692104
7
- tigerbeetle/lib/aarch64-linux-musl/libtb_client.so,sha256=BZ6a2nbclS4g0HU4495b9DipBefrLEMvZgUD0Jpi4Os,690384
8
- tigerbeetle/lib/aarch64-macos/libtb_client.dylib,sha256=zEAJLzDJjIBhSG2tgWww39zq7Rl-Qsf5Q4lmD6UX2M8,700224
9
- tigerbeetle/lib/x86_64-linux-gnu.2.27/libtb_client.so,sha256=EgoOoAELkFc-nHgHY-AlTViVO2Sx35EqF4RbFr5lMZY,815368
10
- tigerbeetle/lib/x86_64-linux-musl/libtb_client.so,sha256=zoxZYw_eH0l2GriVIGr1c8_hdNk33TyVCKhbttYnKGM,813816
11
- tigerbeetle/lib/x86_64-macos/libtb_client.dylib,sha256=KQaKRbtqzsIrzBcJxejIU0b8E9EaKzXgxz_MF7BpP98,792558
12
- tigerbeetle/lib/x86_64-windows/tb_client.dll,sha256=dtB6y1LLLrI9swXI98MS8kKxjuMf0rHUXBauqXhkjMc,663552
13
- tigerbeetle-0.16.56.dist-info/METADATA,sha256=70k1J6tzY0I04K4xqCKjDCAB8wYI3uict2-j79Ym3xg,23268
14
- tigerbeetle-0.16.56.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
15
- tigerbeetle-0.16.56.dist-info/RECORD,,