lumera 0.9.7__py3-none-any.whl → 0.9.8__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.
lumera/storage.py CHANGED
@@ -23,7 +23,15 @@ Example:
23
23
  >>> print(result["url"])
24
24
  """
25
25
 
26
- __all__ = ["upload", "upload_file", "download_url", "list_files", "UploadResult"]
26
+ __all__ = [
27
+ "upload",
28
+ "upload_file",
29
+ "download_url",
30
+ "list_files",
31
+ "UploadResult",
32
+ "get_download_url",
33
+ "download",
34
+ ]
27
35
 
28
36
  import mimetypes
29
37
  import os
@@ -268,3 +276,76 @@ def list_files(prefix: str | None = None) -> list[dict[str, Any]]:
268
276
  files = [f for f in files if f.get("name", "").startswith(prefix)]
269
277
 
270
278
  return files
279
+
280
+
281
+ def get_download_url(object_key: str) -> str:
282
+ """Get a presigned download URL for a file by its object_key.
283
+
284
+ Use this to get download URLs for files stored in lumera_file fields on records.
285
+ The object_key is found in the file descriptor (e.g., record["file"]["object_key"]).
286
+
287
+ Args:
288
+ object_key: The storage object key from a lumera_file field descriptor
289
+
290
+ Returns:
291
+ Presigned download URL (valid for ~15 minutes)
292
+
293
+ Raises:
294
+ ValueError: If object_key is empty
295
+ requests.HTTPError: If the file doesn't exist or request fails
296
+
297
+ Example:
298
+ >>> record = pb.get("documents", "rec_123")
299
+ >>> url = storage.get_download_url(record["file"]["object_key"])
300
+ >>> # Use url to download the file
301
+ """
302
+ if not object_key or not object_key.strip():
303
+ raise ValueError("object_key is required and cannot be empty")
304
+
305
+ token = get_lumera_token()
306
+ headers = {"Authorization": f"token {token}", "Content-Type": "application/json"}
307
+
308
+ resp = requests.post(
309
+ f"{API_BASE}/pb/uploads/download",
310
+ json={"object_key": object_key.strip()},
311
+ headers=headers,
312
+ timeout=30,
313
+ )
314
+ resp.raise_for_status()
315
+
316
+ data = resp.json()
317
+ url = data.get("download_url")
318
+ if not url:
319
+ raise RuntimeError("uploads/download response missing download_url")
320
+
321
+ return url
322
+
323
+
324
+ def download(object_key: str) -> bytes:
325
+ """Download file content by its object_key.
326
+
327
+ Use this to download files stored in lumera_file fields on records.
328
+ The object_key is found in the file descriptor (e.g., record["file"]["object_key"]).
329
+
330
+ Args:
331
+ object_key: The storage object key from a lumera_file field descriptor
332
+
333
+ Returns:
334
+ File content as bytes
335
+
336
+ Raises:
337
+ ValueError: If object_key is empty
338
+ requests.HTTPError: If the file doesn't exist or download fails
339
+
340
+ Example:
341
+ >>> record = pb.get("documents", "rec_123")
342
+ >>> content = storage.download(record["file"]["object_key"])
343
+ >>> with open("local_copy.pdf", "wb") as f:
344
+ ... f.write(content)
345
+ """
346
+ url = get_download_url(object_key)
347
+
348
+ response = requests.get(url, timeout=300)
349
+ response.raise_for_status()
350
+
351
+ return response.content
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lumera
3
- Version: 0.9.7
3
+ Version: 0.9.8
4
4
  Summary: SDK for building on Lumera platform
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: requests
@@ -8,11 +8,11 @@ lumera/llm.py,sha256=pUTZK7t3GTK0vfxMI1PJgJwNendyuiJc5MB1pUj2vxE,14412
8
8
  lumera/locks.py,sha256=8l_qxb8nrxge7YJ-ApUTJ5MeYpIdxDeEa94Eim9O-YM,6806
9
9
  lumera/pb.py,sha256=Q_U1cKeB3YgI7bmTquzLYFWTRWcfUZkFSl7JXMBzV7M,20700
10
10
  lumera/sdk.py,sha256=Dw0yxlZ-ncjgPkCpVnAJQIURtIsbUA4RVu9VjXLayDc,34078
11
- lumera/storage.py,sha256=b0W6JNSGfmhJIcmK3vrATXAwxIr_bfrj-hPuQRVLTYU,8206
11
+ lumera/storage.py,sha256=fWkscTvKDzQ-5tsfA1lREO2qgtjJ4Yvxj3hvYNLKiW0,10527
12
12
  lumera/webhooks.py,sha256=L_Q5YHBJKQNpv7G9Nq0QqlGMRch6x9ptlwu1xD2qwUc,8661
13
13
  lumera/integrations/__init__.py,sha256=LnJmAnFB_p3YMKyeGVdDP4LYlJ85XFNQFAxGo6zF7CI,937
14
14
  lumera/integrations/google.py,sha256=QkbBbbDh3I_OToPDFqcivU6sWy2UieHBxZ_TPv5rqK0,11862
15
- lumera-0.9.7.dist-info/METADATA,sha256=J2PTXGwLHYXTtJpyMbRx1rIy1fdJcptgo6_ATt5XEIY,1611
16
- lumera-0.9.7.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
17
- lumera-0.9.7.dist-info/top_level.txt,sha256=HgfK4XQkpMTnM2E5iWM4kB711FnYqUY9dglzib3pWlE,7
18
- lumera-0.9.7.dist-info/RECORD,,
15
+ lumera-0.9.8.dist-info/METADATA,sha256=rAooBJr5-_9xpam1ctyqqB7C9jNpcXdf-KmzBuj8iGw,1611
16
+ lumera-0.9.8.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
17
+ lumera-0.9.8.dist-info/top_level.txt,sha256=HgfK4XQkpMTnM2E5iWM4kB711FnYqUY9dglzib3pWlE,7
18
+ lumera-0.9.8.dist-info/RECORD,,
File without changes