dataroom-client 0.0.0.post1.dev0__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.
@@ -0,0 +1,45 @@
1
+ import datetime
2
+ import zoneinfo
3
+
4
+ from .print_utils import print_success
5
+
6
+
7
+ class Counter:
8
+ def __init__(self, total, use_print=True, print_every=10):
9
+ self.total = total
10
+ self.count = 0
11
+ self.use_print = use_print
12
+ self.print_every = print_every
13
+ self.start_time = None
14
+ self.end_time = None
15
+
16
+ @property
17
+ def time_left(self):
18
+ elapsed = datetime.datetime.now(tz=zoneinfo.ZoneInfo('UTC')) - self.start_time
19
+ seconds_left = (self.total - self.count) * elapsed.total_seconds() / self.count
20
+ return datetime.timedelta(seconds=seconds_left)
21
+
22
+ @property
23
+ def time_took(self):
24
+ return self.end_time - self.start_time
25
+
26
+ @property
27
+ def percent(self):
28
+ return round(self.count / self.total * 100, 1)
29
+
30
+ def increment(self):
31
+ self.count += 1
32
+ if self.use_print and self.print_every and self.count % self.print_every == 0:
33
+ print_success(
34
+ f'Processed {self.percent}% - {self.count} out of {self.total}. Time left: {self.time_left}',
35
+ )
36
+
37
+ def start(self):
38
+ self.start_time = datetime.datetime.now(tz=zoneinfo.ZoneInfo('UTC'))
39
+
40
+ def end(self):
41
+ self.end_time = datetime.datetime.now(tz=zoneinfo.ZoneInfo('UTC'))
42
+ if self.use_print:
43
+ print_success(
44
+ f'Done! Took: {self.time_took}',
45
+ )
@@ -0,0 +1,61 @@
1
+ import asyncio
2
+ import os
3
+
4
+ from .client import DataRoomFile, DataRoomClient, DataRoomError
5
+ from .counter import Counter
6
+ from .print_utils import print_error, print_status
7
+
8
+
9
+ class DataRoomLoader:
10
+
11
+ def __init__(
12
+ self,
13
+ client: DataRoomClient,
14
+ folder_path: str,
15
+ concurrency: int = 2,
16
+ verbose=True,
17
+ image_source: str = 'loader',
18
+ image_id_prefix: str = None,
19
+ ):
20
+ self.client = client
21
+ self.concurrency = concurrency
22
+ self.folder_path = folder_path
23
+ self.counter = Counter(0)
24
+ self.verbose = verbose
25
+ self.image_source = image_source
26
+ self.image_id_prefix = image_id_prefix
27
+
28
+ async def run(self):
29
+ images = os.listdir(self.folder_path)
30
+
31
+ self.counter = Counter(len(images))
32
+ self.counter.start()
33
+
34
+ semaphore = asyncio.Semaphore(self.concurrency)
35
+ tasks = []
36
+ for image_path in images:
37
+ tasks.append(self._process_image(image_path=image_path, semaphore=semaphore))
38
+
39
+ await asyncio.gather(*tasks)
40
+
41
+ self.counter.end()
42
+
43
+ async def _process_image(self, image_path: str, semaphore: asyncio.Semaphore):
44
+ async with semaphore:
45
+ image_id = image_path.split('.')[0]
46
+ if self.image_id_prefix:
47
+ image_id = f"{self.image_id_prefix}{image_id}"
48
+ full_path = os.path.join(self.folder_path, image_path)
49
+ if self.verbose:
50
+ print_status(f"Processing image: {full_path}")
51
+ try:
52
+ image_file = DataRoomFile.from_path(full_path)
53
+ except DataRoomError as e:
54
+ print_error(f"Failed to read image: {image_path} - Error: {e}")
55
+ else:
56
+ try:
57
+ await self.client.create_image(image_id=image_id, image_file=image_file, source=self.image_source)
58
+ except DataRoomError as e:
59
+ print_error(f"Failed to create image: {image_path} - Error: {e}")
60
+ finally:
61
+ self.counter.increment()
@@ -0,0 +1,11 @@
1
+
2
+ def print_error(string):
3
+ print(f"\033[31m{string}\033[0m") # noqa
4
+
5
+
6
+ def print_success(string):
7
+ print(f"\033[32m{string}\033[0m") # noqa
8
+
9
+
10
+ def print_status(string):
11
+ print(string) # noqa
@@ -0,0 +1,41 @@
1
+ Metadata-Version: 2.3
2
+ Name: dataroom-client
3
+ Version: 0.0.0.post1.dev0
4
+ Summary: A python client to interface with the Dataroom backend API
5
+ Author: Ales Kocjancic
6
+ Author-email: hi@ales.io
7
+ Requires-Python: >=3.11,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Requires-Dist: httpx (>=0.24.1,<1)
13
+ Description-Content-Type: text/markdown
14
+
15
+
16
+ # Installation
17
+
18
+ ```
19
+ pip install dataroom-client
20
+ ```
21
+
22
+
23
+ # Usage
24
+
25
+ After getting an account you can find your API key on the settings page.
26
+
27
+ ```
28
+ from dataroom_client import DataRoomClient
29
+
30
+ DataRoom = DataRoomClient(api_key='YOUR_SECRET_API_KEY_HERE', api_url='YOUR_API_URL_HERE')
31
+
32
+ images = await DataRoom.get_images()
33
+ ```
34
+
35
+ For more examples see [client_example.ipynb](./notebooks/client_example.ipynb).
36
+
37
+
38
+ # Developing
39
+
40
+ Check out the `dataroom` repo and follow the instructions in the README.
41
+
@@ -0,0 +1,8 @@
1
+ dataroom_client/__init__.py,sha256=lDoFtI0GopBlcVyfsJxnSpScN3bqTr4zeSyTmAhfuCI,135
2
+ dataroom_client/client.py,sha256=6uK6HBinqXqJvZM3u7aX_E96Wv00hzaYaIgllxmsqps,58960
3
+ dataroom_client/counter.py,sha256=tQqLTtE2NHAguv0sPK-7RufZ9p2ZhF8GTRpdf4LEbcc,1386
4
+ dataroom_client/loader.py,sha256=hLNmmI-AcKnsgZmpH42Db5Nrj1Uokped7M2Uqz69Alo,2060
5
+ dataroom_client/print_utils.py,sha256=Aak26E5Bp9TAv1v8rRcPe-qcFObGyF_VlZI4GlxAmj8,201
6
+ dataroom_client-0.0.0.post1.dev0.dist-info/METADATA,sha256=ivnuxY5FcSYpAVfp8MBw_jjTxnw7lee89PRTyc12UGQ,982
7
+ dataroom_client-0.0.0.post1.dev0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
8
+ dataroom_client-0.0.0.post1.dev0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.1.3
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any