fal 1.26.5__py3-none-any.whl → 1.26.6__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 CHANGED
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '1.26.5'
21
- __version_tuple__ = version_tuple = (1, 26, 5)
20
+ __version__ = version = '1.26.6'
21
+ __version_tuple__ = version_tuple = (1, 26, 6)
fal/toolkit/file/file.py CHANGED
@@ -73,6 +73,42 @@ def FileField(*args, **kwargs):
73
73
  return Field(*args, **kwargs)
74
74
 
75
75
 
76
+ def _try_with_fallback(
77
+ func: str,
78
+ args: list[Any],
79
+ repository: FileRepository | RepositoryId,
80
+ fallback_repository: Optional[
81
+ FileRepository | RepositoryId | list[FileRepository | RepositoryId]
82
+ ],
83
+ save_kwargs: dict,
84
+ fallback_save_kwargs: dict,
85
+ ) -> Any:
86
+ if fallback_repository is None:
87
+ fallback_repositories = []
88
+ elif isinstance(fallback_repository, list):
89
+ fallback_repositories = fallback_repository
90
+ else:
91
+ fallback_repositories = [fallback_repository]
92
+
93
+ attempts = [
94
+ (repository, save_kwargs),
95
+ *((fallback, fallback_save_kwargs) for fallback in fallback_repositories),
96
+ ]
97
+ for idx, (repo, kwargs) in enumerate(attempts):
98
+ repo_obj = get_builtin_repository(repo)
99
+ try:
100
+ return getattr(repo_obj, func)(*args, **kwargs)
101
+ except Exception as exc:
102
+ if idx >= len(attempts) - 1:
103
+ raise
104
+
105
+ traceback.print_exc()
106
+ print(
107
+ f"Failed to {func} to repository {repo}: {exc}, "
108
+ f"falling back to {attempts[idx + 1][0]}"
109
+ )
110
+
111
+
76
112
  class File(BaseModel):
77
113
  # public properties
78
114
  url: str = Field(
@@ -154,14 +190,12 @@ class File(BaseModel):
154
190
  file_name: Optional[str] = None,
155
191
  repository: FileRepository | RepositoryId = DEFAULT_REPOSITORY,
156
192
  fallback_repository: Optional[
157
- FileRepository | RepositoryId
193
+ FileRepository | RepositoryId | list[FileRepository | RepositoryId]
158
194
  ] = FALLBACK_REPOSITORY,
159
195
  request: Optional[Request] = None,
160
196
  save_kwargs: Optional[dict] = None,
161
197
  fallback_save_kwargs: Optional[dict] = None,
162
198
  ) -> File:
163
- repo = get_builtin_repository(repository)
164
-
165
199
  save_kwargs = save_kwargs or {}
166
200
  fallback_save_kwargs = fallback_save_kwargs or {}
167
201
 
@@ -177,21 +211,14 @@ class File(BaseModel):
177
211
  "object_lifecycle_preference", object_lifecycle_preference
178
212
  )
179
213
 
180
- try:
181
- url = repo.save(fdata, **save_kwargs)
182
- except Exception as exc:
183
- if not fallback_repository:
184
- raise
185
-
186
- traceback.print_exc()
187
- print(
188
- f"Failed to save bytes to repository {repository}: {exc}, "
189
- f"falling back to {fallback_repository}"
190
- )
191
-
192
- fallback_repo = get_builtin_repository(fallback_repository)
193
-
194
- url = fallback_repo.save(fdata, **fallback_save_kwargs)
214
+ url = _try_with_fallback(
215
+ "save",
216
+ [fdata],
217
+ repository=repository,
218
+ fallback_repository=fallback_repository,
219
+ save_kwargs=save_kwargs,
220
+ fallback_save_kwargs=fallback_save_kwargs,
221
+ )
195
222
 
196
223
  return cls(
197
224
  url=url,
@@ -209,7 +236,7 @@ class File(BaseModel):
209
236
  repository: FileRepository | RepositoryId = DEFAULT_REPOSITORY,
210
237
  multipart: bool | None = None,
211
238
  fallback_repository: Optional[
212
- FileRepository | RepositoryId
239
+ FileRepository | RepositoryId | list[FileRepository | RepositoryId]
213
240
  ] = FALLBACK_REPOSITORY,
214
241
  request: Optional[Request] = None,
215
242
  save_kwargs: Optional[dict] = None,
@@ -219,8 +246,6 @@ class File(BaseModel):
219
246
  if not file_path.exists():
220
247
  raise FileNotFoundError(f"File {file_path} does not exist")
221
248
 
222
- repo = get_builtin_repository(repository)
223
-
224
249
  save_kwargs = save_kwargs or {}
225
250
  fallback_save_kwargs = fallback_save_kwargs or {}
226
251
 
@@ -238,29 +263,17 @@ class File(BaseModel):
238
263
  save_kwargs.setdefault("multipart", multipart)
239
264
  fallback_save_kwargs.setdefault("multipart", multipart)
240
265
 
241
- try:
242
- url, data = repo.save_file(
243
- file_path,
244
- content_type=content_type,
245
- **save_kwargs,
246
- )
247
- except Exception as exc:
248
- if not fallback_repository:
249
- raise
250
-
251
- traceback.print_exc()
252
- print(
253
- f"Failed to save file to repository {repository}: {exc}, "
254
- f"falling back to {fallback_repository}"
255
- )
256
-
257
- fallback_repo = get_builtin_repository(fallback_repository)
266
+ save_kwargs.setdefault("content_type", content_type)
267
+ fallback_save_kwargs.setdefault("content_type", content_type)
258
268
 
259
- url, data = fallback_repo.save_file(
260
- file_path,
261
- content_type=content_type,
262
- **fallback_save_kwargs,
263
- )
269
+ url, data = _try_with_fallback(
270
+ "save_file",
271
+ [file_path],
272
+ repository=repository,
273
+ fallback_repository=fallback_repository,
274
+ save_kwargs=save_kwargs,
275
+ fallback_save_kwargs=fallback_save_kwargs,
276
+ )
264
277
 
265
278
  return cls(
266
279
  url=url,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fal
3
- Version: 1.26.5
3
+ Version: 1.26.6
4
4
  Summary: fal is an easy-to-use Serverless Python Framework
5
5
  Author: Features & Labels <support@fal.ai>
6
6
  Requires-Python: >=3.8
@@ -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=r8-mjCjV1nY6UT0cjXxBKSJyUs5zQ39PpwPh_7phUbA,513
3
+ fal/_fal_version.py,sha256=ki20SEr4F9ZxFRNziosQqt1wqRI1HwXbMEH1XL5Oq2M,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=wIEt21P1C7U-dYQEcyHUxxuuTnvzFyTpWDoHoaxq7tg,47385
@@ -59,7 +59,7 @@ fal/toolkit/types.py,sha256=kkbOsDKj1qPGb1UARTBp7yuJ5JUuyy7XQurYUBCdti8,4064
59
59
  fal/toolkit/audio/__init__.py,sha256=sqNVfrKbppWlIGLoFTaaNTxLpVXsFHxOSHLA5VG547A,35
60
60
  fal/toolkit/audio/audio.py,sha256=gt458h989iQ-EhQSH-mCuJuPBY4RneLJE05f_QWU1E0,572
61
61
  fal/toolkit/file/__init__.py,sha256=FbNl6wD-P0aSSTUwzHt4HujBXrbC3ABmaigPQA4hRfg,70
62
- fal/toolkit/file/file.py,sha256=4K28gr--5q0nmsm3P76SFoKQj3bPROVwxXrdoMjIiUE,10197
62
+ fal/toolkit/file/file.py,sha256=goiz5o3Wb7hcyFiolL4a4dANOmv3NJnet4Da50Pm6sI,10767
63
63
  fal/toolkit/file/types.py,sha256=MMAH_AyLOhowQPesOv1V25wB4qgbJ3vYNlnTPbdSv1M,2304
64
64
  fal/toolkit/file/providers/fal.py,sha256=Ph8v3Cm_eFu1b1AXiPKZQ5r8AWUALD3Wk18uw3z8RDQ,46910
65
65
  fal/toolkit/file/providers/gcp.py,sha256=DKeZpm1MjwbvEsYvkdXUtuLIJDr_UNbqXj_Mfv3NTeo,2437
@@ -142,8 +142,8 @@ openapi_fal_rest/models/workflow_node_type.py,sha256=-FzyeY2bxcNmizKbJI8joG7byRi
142
142
  openapi_fal_rest/models/workflow_schema.py,sha256=4K5gsv9u9pxx2ItkffoyHeNjBBYf6ur5bN4m_zePZNY,2019
143
143
  openapi_fal_rest/models/workflow_schema_input.py,sha256=2OkOXWHTNsCXHWS6EGDFzcJKkW5FIap-2gfO233EvZQ,1191
144
144
  openapi_fal_rest/models/workflow_schema_output.py,sha256=EblwSPAGfWfYVWw_WSSaBzQVju296is9o28rMBAd0mc,1196
145
- fal-1.26.5.dist-info/METADATA,sha256=Z8d49heaHBesij9BvdMX_P9rYafB7562kKIiUSZeH5M,4089
146
- fal-1.26.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
147
- fal-1.26.5.dist-info/entry_points.txt,sha256=32zwTUC1U1E7nSTIGCoANQOQ3I7-qHG5wI6gsVz5pNU,37
148
- fal-1.26.5.dist-info/top_level.txt,sha256=r257X1L57oJL8_lM0tRrfGuXFwm66i1huwQygbpLmHw,21
149
- fal-1.26.5.dist-info/RECORD,,
145
+ fal-1.26.6.dist-info/METADATA,sha256=g4I367Dy6AaujQfb-0jcU_YK-Vg1iTY-Jx0kMICfih4,4089
146
+ fal-1.26.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
147
+ fal-1.26.6.dist-info/entry_points.txt,sha256=32zwTUC1U1E7nSTIGCoANQOQ3I7-qHG5wI6gsVz5pNU,37
148
+ fal-1.26.6.dist-info/top_level.txt,sha256=r257X1L57oJL8_lM0tRrfGuXFwm66i1huwQygbpLmHw,21
149
+ fal-1.26.6.dist-info/RECORD,,
File without changes