sapiopycommons 2025.9.19a762__py3-none-any.whl → 2025.9.26a769__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.
Potentially problematic release.
This version of sapiopycommons might be problematic. Click here for more details.
- sapiopycommons/ai/server.py +7 -0
- sapiopycommons/files/file_util.py +128 -1
- {sapiopycommons-2025.9.19a762.dist-info → sapiopycommons-2025.9.26a769.dist-info}/METADATA +1 -1
- {sapiopycommons-2025.9.19a762.dist-info → sapiopycommons-2025.9.26a769.dist-info}/RECORD +6 -6
- {sapiopycommons-2025.9.19a762.dist-info → sapiopycommons-2025.9.26a769.dist-info}/WHEEL +0 -0
- {sapiopycommons-2025.9.19a762.dist-info → sapiopycommons-2025.9.26a769.dist-info}/licenses/LICENSE +0 -0
sapiopycommons/ai/server.py
CHANGED
|
@@ -127,6 +127,13 @@ class SapioGrpcServer:
|
|
|
127
127
|
print(f"Registering Tool service: {service.__class__.__name__}")
|
|
128
128
|
add_ToolServiceServicer_to_server(service, server)
|
|
129
129
|
|
|
130
|
+
from grpc_health.v1 import health_pb2, health_pb2_grpc
|
|
131
|
+
from grpc_health.v1.health import HealthServicer
|
|
132
|
+
health_servicer = HealthServicer()
|
|
133
|
+
health_servicer.set("", health_pb2.HealthCheckResponse.ServingStatus.SERVING)
|
|
134
|
+
health_servicer.set("ScriptService", health_pb2.HealthCheckResponse.ServingStatus.SERVING)
|
|
135
|
+
health_pb2_grpc.add_HealthServicer_to_server(health_servicer, server)
|
|
136
|
+
|
|
130
137
|
server.add_insecure_port(f"[::]:{self.port}")
|
|
131
138
|
await server.start()
|
|
132
139
|
print(f"Server started, listening on {self.port}")
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import gzip
|
|
1
2
|
import io
|
|
3
|
+
import tarfile
|
|
4
|
+
import time
|
|
2
5
|
import warnings
|
|
3
6
|
import zipfile
|
|
4
7
|
|
|
@@ -322,7 +325,7 @@ class FileUtil:
|
|
|
322
325
|
@staticmethod
|
|
323
326
|
def zip_files(files: dict[str, str | bytes]) -> bytes:
|
|
324
327
|
"""
|
|
325
|
-
Create a zip file for a collection of files.
|
|
328
|
+
Create a .zip file for a collection of files.
|
|
326
329
|
|
|
327
330
|
:param files: A dictionary of file name to file data as a string or bytes.
|
|
328
331
|
:return: The bytes for a zip file containing the input files.
|
|
@@ -335,6 +338,130 @@ class FileUtil:
|
|
|
335
338
|
# throws an I/O exception.
|
|
336
339
|
return zip_buffer.getvalue()
|
|
337
340
|
|
|
341
|
+
# FR-47422: Add a function for unzipping files that may have been zipped by the above function.
|
|
342
|
+
@staticmethod
|
|
343
|
+
def unzip_files(zip_file: bytes) -> dict[str, bytes]:
|
|
344
|
+
"""
|
|
345
|
+
Decompress a .zip file from an in-memory bytes object and extracts all files into a dictionary.
|
|
346
|
+
|
|
347
|
+
:param zip_file: The bytes of the zip file to be decompressed.
|
|
348
|
+
:return: A dictionary of file name to file bytes for each file in the zip.
|
|
349
|
+
"""
|
|
350
|
+
extracted_files: dict[str, bytes] = {}
|
|
351
|
+
with io.BytesIO(zip_file) as zip_buffer:
|
|
352
|
+
with zipfile.ZipFile(zip_buffer, "r") as zip_file:
|
|
353
|
+
for file_name in zip_file.namelist():
|
|
354
|
+
with zip_file.open(file_name) as file:
|
|
355
|
+
extracted_files[file_name] = file.read()
|
|
356
|
+
return extracted_files
|
|
357
|
+
|
|
358
|
+
# FR-47422: Add functions for compressing and decompressing .gz, .tar, and .tar.gz files.
|
|
359
|
+
@staticmethod
|
|
360
|
+
def gzip_file(file_data: bytes | str) -> bytes:
|
|
361
|
+
"""
|
|
362
|
+
Create a .gz file for a single file.
|
|
363
|
+
|
|
364
|
+
:param file_data: The file data to be compressed as bytes or a string.
|
|
365
|
+
:return: The bytes of the gzip-compressed file.
|
|
366
|
+
"""
|
|
367
|
+
return gzip.compress(file_data.encode() if isinstance(file_data, str) else file_data)
|
|
368
|
+
|
|
369
|
+
@staticmethod
|
|
370
|
+
def ungzip_file(gzip_file: bytes) -> bytes:
|
|
371
|
+
"""
|
|
372
|
+
Decompress a .gz file.
|
|
373
|
+
|
|
374
|
+
:param gzip_file: The bytes of the gzip-compressed file.
|
|
375
|
+
:return: The decompressed file data as bytes.
|
|
376
|
+
"""
|
|
377
|
+
return gzip.decompress(gzip_file)
|
|
378
|
+
|
|
379
|
+
@staticmethod
|
|
380
|
+
def tar_files(files: dict[str, str | bytes]) -> bytes:
|
|
381
|
+
"""
|
|
382
|
+
Create a .tar file for a collection of files.
|
|
383
|
+
|
|
384
|
+
:param files: A dictionary of file name to file data as a string or bytes.
|
|
385
|
+
:return: The bytes for a tar file containing the input files.
|
|
386
|
+
"""
|
|
387
|
+
with io.BytesIO() as tar_buffer:
|
|
388
|
+
with tarfile.open(fileobj=tar_buffer, mode="w") as tar:
|
|
389
|
+
for name, data in files.items():
|
|
390
|
+
if isinstance(data, str):
|
|
391
|
+
data: bytes = data.encode('utf-8')
|
|
392
|
+
|
|
393
|
+
tarinfo = tarfile.TarInfo(name=name)
|
|
394
|
+
tarinfo.size = len(data)
|
|
395
|
+
tarinfo.mtime = int(time.time())
|
|
396
|
+
|
|
397
|
+
with io.BytesIO(data) as file:
|
|
398
|
+
tar.addfile(tarinfo=tarinfo, fileobj=file)
|
|
399
|
+
|
|
400
|
+
tar_buffer.seek(0)
|
|
401
|
+
return tar_buffer.getvalue()
|
|
402
|
+
|
|
403
|
+
@staticmethod
|
|
404
|
+
def untar_files(tar_file: bytes) -> dict[str, bytes]:
|
|
405
|
+
"""
|
|
406
|
+
Decompress a .tar file from an in-memory bytes object and extracts all files into a dictionary.
|
|
407
|
+
|
|
408
|
+
:param tar_file: The bytes of the tar file to be decompressed.
|
|
409
|
+
:return: A dictionary of file name to file bytes for each file in the tar.
|
|
410
|
+
"""
|
|
411
|
+
extracted_files: dict[str, bytes] = {}
|
|
412
|
+
with io.BytesIO(tar_file) as tar_buffer:
|
|
413
|
+
with tarfile.open(fileobj=tar_buffer, mode="r") as tar:
|
|
414
|
+
for member in tar.getmembers():
|
|
415
|
+
if member.isfile():
|
|
416
|
+
file_obj = tar.extractfile(member)
|
|
417
|
+
if file_obj:
|
|
418
|
+
with file_obj:
|
|
419
|
+
extracted_files[member.name] = file_obj.read()
|
|
420
|
+
return extracted_files
|
|
421
|
+
|
|
422
|
+
@staticmethod
|
|
423
|
+
def tar_gzip_files(files: dict[str, str | bytes]) -> bytes:
|
|
424
|
+
"""
|
|
425
|
+
Create a .tar.gz file for a collection of files.
|
|
426
|
+
|
|
427
|
+
:param files: A dictionary of file name to file data as a string or bytes.
|
|
428
|
+
:return: The bytes for a tar.gz file containing the input files.
|
|
429
|
+
"""
|
|
430
|
+
with io.BytesIO() as tar_buffer:
|
|
431
|
+
with tarfile.open(fileobj=tar_buffer, mode="w:gz") as tar:
|
|
432
|
+
for name, data in files.items():
|
|
433
|
+
if isinstance(data, str):
|
|
434
|
+
data: bytes = data.encode('utf-8')
|
|
435
|
+
|
|
436
|
+
tarinfo = tarfile.TarInfo(name=name)
|
|
437
|
+
tarinfo.size = len(data)
|
|
438
|
+
tarinfo.mtime = int(time.time())
|
|
439
|
+
|
|
440
|
+
with io.BytesIO(data) as file:
|
|
441
|
+
tar.addfile(tarinfo=tarinfo, fileobj=file)
|
|
442
|
+
|
|
443
|
+
tar_buffer.seek(0)
|
|
444
|
+
return tar_buffer.getvalue()
|
|
445
|
+
|
|
446
|
+
@staticmethod
|
|
447
|
+
def untar_gzip_files(tar_gzip_file: bytes) -> dict[str, bytes]:
|
|
448
|
+
"""
|
|
449
|
+
Decompress a .tar.gz file from an in-memory bytes object and extracts all files into a dictionary.
|
|
450
|
+
|
|
451
|
+
:param tar_gzip_file: The bytes of the tar.gz file to be decompressed.
|
|
452
|
+
:return: A dictionary of file name to file bytes for each file in the tar.gz
|
|
453
|
+
"""
|
|
454
|
+
extracted_files: dict[str, bytes] = {}
|
|
455
|
+
with io.BytesIO(tar_gzip_file) as tar_buffer:
|
|
456
|
+
with tarfile.open(fileobj=tar_buffer, mode="r:gz") as tar:
|
|
457
|
+
for member in tar.getmembers():
|
|
458
|
+
if member.isfile():
|
|
459
|
+
file_obj = tar.extractfile(member)
|
|
460
|
+
if file_obj:
|
|
461
|
+
with file_obj:
|
|
462
|
+
extracted_files[member.name] = file_obj.read()
|
|
463
|
+
return extracted_files
|
|
464
|
+
|
|
338
465
|
# Deprecated functions:
|
|
339
466
|
|
|
340
467
|
# FR-46097 - Add write file request shorthand functions to FileUtil.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: sapiopycommons
|
|
3
|
-
Version: 2025.9.
|
|
3
|
+
Version: 2025.9.26a769
|
|
4
4
|
Summary: Official Sapio Python API Utilities Package
|
|
5
5
|
Project-URL: Homepage, https://github.com/sapiosciences
|
|
6
6
|
Author-email: Jonathan Steck <jsteck@sapiosciences.com>, Yechen Qiao <yqiao@sapiosciences.com>
|
|
@@ -2,7 +2,7 @@ sapiopycommons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
2
2
|
sapiopycommons/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
sapiopycommons/ai/converter_service_base.py,sha256=HiUXmwqv1STgyQeF9_eTFXzjIFXp5-NJ7sEhMpV3aAU,6351
|
|
4
4
|
sapiopycommons/ai/protobuf_utils.py,sha256=cBjbxoFAwU02kNUxEce95WnMU2CMuDD-qFaeWgvQJMQ,24599
|
|
5
|
-
sapiopycommons/ai/server.py,sha256=
|
|
5
|
+
sapiopycommons/ai/server.py,sha256=1ksOax2cab9MH7ESXQ5dwVNZcBKiWpNVhkzO4KkFTSg,6370
|
|
6
6
|
sapiopycommons/ai/test_client.py,sha256=Um93jXmIx0YaHf-YbV5NSamPTHveJ0kU_UaAfOApnZg,16342
|
|
7
7
|
sapiopycommons/ai/tool_of_tools.py,sha256=zYmQ4rNX-qYQnc-vNDnYZjtv9JgmQAmVVuHfVOdBF3w,46984
|
|
8
8
|
sapiopycommons/ai/tool_service_base.py,sha256=OmGUDsDj7sCNtjhJVohc1mUQ0PZsMhhgfG8BXAWujGs,53861
|
|
@@ -66,7 +66,7 @@ sapiopycommons/files/file_bridge.py,sha256=vKbqxPexi15epr_-_qLrEfYoxNxB031mXN92i
|
|
|
66
66
|
sapiopycommons/files/file_bridge_handler.py,sha256=SEYDIQhSCmjI6qyLdDJE8JVKSd0WYvF7JvAq_Ahp9Do,25503
|
|
67
67
|
sapiopycommons/files/file_data_handler.py,sha256=f96MlkMuQhUCi4oLnzJK5AiuElCp5jLI8_sJkZVwpws,36779
|
|
68
68
|
sapiopycommons/files/file_text_converter.py,sha256=Gaj_divTiKXWd6flDOgrxNXpcn9fDWqxX6LUG0joePk,7516
|
|
69
|
-
sapiopycommons/files/file_util.py,sha256=
|
|
69
|
+
sapiopycommons/files/file_util.py,sha256=WBA3FYG8R2HtfxjWSzQhZKW6_1s6JSxTo9lk3SeNDu8,37140
|
|
70
70
|
sapiopycommons/files/file_validator.py,sha256=ryg22-93csmRO_Pv0ZpWphNkB74xWZnHyJ23K56qLj0,28761
|
|
71
71
|
sapiopycommons/files/file_writer.py,sha256=hACVl0duCjP28gJ1NPljkjagNCLod0ygUlPbvUmRDNM,17605
|
|
72
72
|
sapiopycommons/files/temp_files.py,sha256=i-xgh4puYLtREI1ZtKq8y5q1lRWQX_UrVyJd2yQO0hw,3183
|
|
@@ -102,7 +102,7 @@ sapiopycommons/webhook/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
|
|
|
102
102
|
sapiopycommons/webhook/webhook_context.py,sha256=D793uLsb1691SalaPnBUk3rOSxn_hYLhdvkaIxjNXss,1909
|
|
103
103
|
sapiopycommons/webhook/webhook_handlers.py,sha256=7o_wXOruhT9auNh8OfhJAh4WhhiPKij67FMBSpGPICc,39939
|
|
104
104
|
sapiopycommons/webhook/webservice_handlers.py,sha256=cvW6Mk_110BzYqkbk63Kg7jWrltBCDALOlkJRu8h4VQ,14300
|
|
105
|
-
sapiopycommons-2025.9.
|
|
106
|
-
sapiopycommons-2025.9.
|
|
107
|
-
sapiopycommons-2025.9.
|
|
108
|
-
sapiopycommons-2025.9.
|
|
105
|
+
sapiopycommons-2025.9.26a769.dist-info/METADATA,sha256=cDYMXx-sBUR1wwz-ntiPUjtBJutj8RknIoZDK6kE9nA,3142
|
|
106
|
+
sapiopycommons-2025.9.26a769.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
107
|
+
sapiopycommons-2025.9.26a769.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
|
|
108
|
+
sapiopycommons-2025.9.26a769.dist-info/RECORD,,
|
|
File without changes
|
{sapiopycommons-2025.9.19a762.dist-info → sapiopycommons-2025.9.26a769.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|