fal 1.23.0__py3-none-any.whl → 1.23.1__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 fal might be problematic. Click here for more details.
- fal/_fal_version.py +2 -2
- fal/toolkit/exceptions.py +6 -0
- fal/toolkit/kv.py +85 -0
- {fal-1.23.0.dist-info → fal-1.23.1.dist-info}/METADATA +1 -1
- {fal-1.23.0.dist-info → fal-1.23.1.dist-info}/RECORD +8 -7
- {fal-1.23.0.dist-info → fal-1.23.1.dist-info}/WHEEL +0 -0
- {fal-1.23.0.dist-info → fal-1.23.1.dist-info}/entry_points.txt +0 -0
- {fal-1.23.0.dist-info → fal-1.23.1.dist-info}/top_level.txt +0 -0
fal/_fal_version.py
CHANGED
fal/toolkit/exceptions.py
CHANGED
fal/toolkit/kv.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import Any, Dict, Optional
|
|
3
|
+
from urllib.error import HTTPError
|
|
4
|
+
from urllib.request import Request
|
|
5
|
+
|
|
6
|
+
from fal.toolkit.exceptions import KVStoreException
|
|
7
|
+
from fal.toolkit.file.providers.fal import _maybe_retry_request, fal_v3_token_manager
|
|
8
|
+
|
|
9
|
+
FAL_KV_HOST = "https://kv.fal.media"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class KVStore:
|
|
13
|
+
"""A key-value store client for interacting with the FAL KV service.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
db_name: The name of the database/namespace to use for this KV store.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def __init__(self, db_name: str):
|
|
20
|
+
self.db_name = db_name
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def auth_headers(self) -> Dict[str, str]:
|
|
24
|
+
token = fal_v3_token_manager.get_token()
|
|
25
|
+
return {
|
|
26
|
+
"Authorization": f"{token.token_type} {token.token}",
|
|
27
|
+
"User-Agent": "fal/0.1.0",
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def get(self, key: str) -> Optional[str]:
|
|
31
|
+
"""Retrieve a value from the key-value store.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
key: The key to retrieve the value for.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
The value associated with the key, or None if the key doesn't exist.
|
|
38
|
+
"""
|
|
39
|
+
response = self._send_request(
|
|
40
|
+
method="GET",
|
|
41
|
+
path=f"/get/{self.db_name}/{key}",
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
if response is None:
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
return response["value"]
|
|
48
|
+
|
|
49
|
+
def set(self, key: str, value: str) -> None:
|
|
50
|
+
"""Store a value in the key-value store.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
key: The key to store the value under.
|
|
54
|
+
value: The value to store.
|
|
55
|
+
"""
|
|
56
|
+
self._send_request(
|
|
57
|
+
method="PUT",
|
|
58
|
+
path=f"/set/{self.db_name}/{key}",
|
|
59
|
+
data=value.encode(),
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
def _send_request(
|
|
63
|
+
self,
|
|
64
|
+
method: str,
|
|
65
|
+
path: str,
|
|
66
|
+
data: Optional[bytes] = None,
|
|
67
|
+
) -> Optional[Dict[str, Any]]:
|
|
68
|
+
headers = {
|
|
69
|
+
**self.auth_headers,
|
|
70
|
+
"Accept": "application/json",
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
url = FAL_KV_HOST + path
|
|
74
|
+
request = Request(url, headers=headers, method=method, data=data)
|
|
75
|
+
try:
|
|
76
|
+
with _maybe_retry_request(request) as response:
|
|
77
|
+
result = json.load(response)
|
|
78
|
+
except HTTPError as e:
|
|
79
|
+
if e.status == 404:
|
|
80
|
+
return None
|
|
81
|
+
raise KVStoreException(
|
|
82
|
+
f"Error sending request. Status {e.status}: {e.reason}"
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
return result
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
fal/__init__.py,sha256=wXs1G0gSc7ZK60-bHe-B2m0l_sA6TrFk4BxY0tMoLe8,784
|
|
2
2
|
fal/__main__.py,sha256=4JMK66Wj4uLZTKbF-sT3LAxOsr6buig77PmOkJCRRxw,83
|
|
3
|
-
fal/_fal_version.py,sha256
|
|
3
|
+
fal/_fal_version.py,sha256=-TCybTpn5d1ogABxKp1Mlx4Oiz9LQCNVDc5ZmAiLfyE,513
|
|
4
4
|
fal/_serialization.py,sha256=npXNsFJ5G7jzBeBIyVMH01Ww34mGY4XWhHpRbSrTtnQ,7598
|
|
5
5
|
fal/_version.py,sha256=1BbTFnucNC_6ldKJ_ZoC722_UkW4S9aDBSW9L0fkKAw,2315
|
|
6
6
|
fal/api.py,sha256=vTYWeKnNg3japot1vOV_JSk812aeB6a2Y7lC1ed-VmM,47277
|
|
@@ -52,7 +52,8 @@ fal/logging/style.py,sha256=ckIgHzvF4DShM5kQh8F133X53z_vF46snuDHVmo_h9g,386
|
|
|
52
52
|
fal/logging/trace.py,sha256=OhzB6d4rQZimBc18WFLqH_9BGfqFFumKKTAGSsmWRMg,1904
|
|
53
53
|
fal/logging/user.py,sha256=H7Pg-nqhpzsUb5f6uXyZUeLWAsr3oImQEaYSCIIAlqo,818
|
|
54
54
|
fal/toolkit/__init__.py,sha256=GR5KxAsNODlhs-DTarJcb5raujActubn0afR7FPueWs,886
|
|
55
|
-
fal/toolkit/exceptions.py,sha256=
|
|
55
|
+
fal/toolkit/exceptions.py,sha256=8-EMuqDXEofPu-eVoWowc7WEM-ifusithyv6tnsm2MM,301
|
|
56
|
+
fal/toolkit/kv.py,sha256=5kMk-I5PMRORK4TYc0jqqowjqKkbk7zUIgz9rAIztxE,2364
|
|
56
57
|
fal/toolkit/optimize.py,sha256=p75sovF0SmRP6zxzpIaaOmqlxvXB_xEz3XPNf59EF7w,1339
|
|
57
58
|
fal/toolkit/types.py,sha256=kkbOsDKj1qPGb1UARTBp7yuJ5JUuyy7XQurYUBCdti8,4064
|
|
58
59
|
fal/toolkit/audio/__init__.py,sha256=sqNVfrKbppWlIGLoFTaaNTxLpVXsFHxOSHLA5VG547A,35
|
|
@@ -141,8 +142,8 @@ openapi_fal_rest/models/workflow_node_type.py,sha256=-FzyeY2bxcNmizKbJI8joG7byRi
|
|
|
141
142
|
openapi_fal_rest/models/workflow_schema.py,sha256=4K5gsv9u9pxx2ItkffoyHeNjBBYf6ur5bN4m_zePZNY,2019
|
|
142
143
|
openapi_fal_rest/models/workflow_schema_input.py,sha256=2OkOXWHTNsCXHWS6EGDFzcJKkW5FIap-2gfO233EvZQ,1191
|
|
143
144
|
openapi_fal_rest/models/workflow_schema_output.py,sha256=EblwSPAGfWfYVWw_WSSaBzQVju296is9o28rMBAd0mc,1196
|
|
144
|
-
fal-1.23.
|
|
145
|
-
fal-1.23.
|
|
146
|
-
fal-1.23.
|
|
147
|
-
fal-1.23.
|
|
148
|
-
fal-1.23.
|
|
145
|
+
fal-1.23.1.dist-info/METADATA,sha256=MvSJ1DBSdozdRvsUUw-9ycHm1yWWuZ--JvifArmgOMo,4085
|
|
146
|
+
fal-1.23.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
147
|
+
fal-1.23.1.dist-info/entry_points.txt,sha256=32zwTUC1U1E7nSTIGCoANQOQ3I7-qHG5wI6gsVz5pNU,37
|
|
148
|
+
fal-1.23.1.dist-info/top_level.txt,sha256=r257X1L57oJL8_lM0tRrfGuXFwm66i1huwQygbpLmHw,21
|
|
149
|
+
fal-1.23.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|