fallbacks3 0.4.0__tar.gz → 0.5.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fallbacks3
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: S3-compatible storage library with automatic fallback support
5
5
  Author-email: Mila de Oliveira <mila.oliveira@palver.com.br>
6
6
  Project-URL: Homepage, https://github.com/palverdata/fallbacks3
@@ -49,6 +49,15 @@ PROVIDERS="ps3://access_key:secret_key@ps3.palver.com,r2://access_key:secret_key
49
49
  FALLBACK_PROVIDER="r2"
50
50
  ```
51
51
 
52
+ `FALLBACK_PROVIDER` may also be set as a `<scheme>://<bucket>` URI to redirect fallback
53
+ uploads to a specific bucket instead of reusing the original request's bucket. The scheme
54
+ must still be one of the providers in `PROVIDERS`.
55
+
56
+ ```bash
57
+ # On fallback, upload to bucket "bucket-v2" on the r2 provider
58
+ FALLBACK_PROVIDER="r2://bucket-v2"
59
+ ```
60
+
52
61
 
53
62
  ### Provider URI Format
54
63
 
@@ -108,7 +117,7 @@ print(signed_url) # "https://ps3.palver.com/palver-whatsapp/audio.mp3?signature
108
117
 
109
118
  ### Upload with Automatic Fallback
110
119
 
111
- If the primary provider fails for the upload method, the library automatically retries with the fallback provider (using the same bucket and file path), as to ensure files are not lost.
120
+ If the primary provider fails for the upload method, the library automatically retries with the fallback provider (using the same bucket and file path, unless `FALLBACK_PROVIDER` specifies a bucket), as to ensure files are not lost.
112
121
 
113
122
  ```python
114
123
  # If ps3 fails, automatically falls back to r2
@@ -28,6 +28,15 @@ PROVIDERS="ps3://access_key:secret_key@ps3.palver.com,r2://access_key:secret_key
28
28
  FALLBACK_PROVIDER="r2"
29
29
  ```
30
30
 
31
+ `FALLBACK_PROVIDER` may also be set as a `<scheme>://<bucket>` URI to redirect fallback
32
+ uploads to a specific bucket instead of reusing the original request's bucket. The scheme
33
+ must still be one of the providers in `PROVIDERS`.
34
+
35
+ ```bash
36
+ # On fallback, upload to bucket "bucket-v2" on the r2 provider
37
+ FALLBACK_PROVIDER="r2://bucket-v2"
38
+ ```
39
+
31
40
 
32
41
  ### Provider URI Format
33
42
 
@@ -87,7 +96,7 @@ print(signed_url) # "https://ps3.palver.com/palver-whatsapp/audio.mp3?signature
87
96
 
88
97
  ### Upload with Automatic Fallback
89
98
 
90
- If the primary provider fails for the upload method, the library automatically retries with the fallback provider (using the same bucket and file path), as to ensure files are not lost.
99
+ If the primary provider fails for the upload method, the library automatically retries with the fallback provider (using the same bucket and file path, unless `FALLBACK_PROVIDER` specifies a bucket), as to ensure files are not lost.
91
100
 
92
101
  ```python
93
102
  # If ps3 fails, automatically falls back to r2
@@ -22,8 +22,11 @@ class Storage:
22
22
  <provider>://<access_key>:<secret_key>@<endpoint>
23
23
  Example: "ps3://key:secret@ps3.palver.com,s4://a:b@s4.mega.com"
24
24
  Defaults to PROVIDERS environment variable.
25
- fallback_provider: Provider scheme to use for fallback (e.g., "r2").
26
- Must be one of the providers in the providers string.
25
+ fallback_provider: Fallback provider to use on upload failure. Either
26
+ a bare scheme (e.g. "r2"), which reuses the original bucket, or a
27
+ "<scheme>://<bucket>" URI (e.g. "r2://bucket-v2"), which redirects
28
+ fallback uploads to <bucket>. The scheme must be one of the
29
+ providers in the providers string.
27
30
  Defaults to FALLBACK_PROVIDER environment variable.
28
31
  provider_configs: Optional per-provider kwargs keyed by provider scheme,
29
32
  merged into the S3Provider constructor for the matching provider.
@@ -47,11 +50,13 @@ class Storage:
47
50
  **(provider_configs or {}).get(creds.provider_scheme, {}),
48
51
  )
49
52
 
50
- self.fallback_provider: str = fallback_provider
53
+ scheme, _, bucket = fallback_provider.partition("://")
54
+ self.fallback_provider: str = scheme
55
+ self.fallback_bucket: str | None = bucket or None
51
56
 
52
- if fallback_provider not in self.providers:
57
+ if self.fallback_provider not in self.providers:
53
58
  raise ValueError(
54
- f"Fallback provider '{fallback_provider}' not found in providers"
59
+ f"Fallback provider '{self.fallback_provider}' not found in providers"
55
60
  )
56
61
 
57
62
  def upload_file(self, remote_file_uri: str, local_file_path: str) -> str:
@@ -82,11 +87,11 @@ class Storage:
82
87
  if self.fallback_provider != parsed_uri.scheme:
83
88
  try:
84
89
  fallback: S3Provider = self.providers[self.fallback_provider]
85
- # Use same bucket and key with fallback provider
90
+ # Use configured fallback bucket if set, else the same bucket
86
91
  return fallback.upload_file(
87
92
  file_name=parsed_uri.path.lstrip("/"),
88
93
  file_path=local_file_path,
89
- bucket=parsed_uri.netloc,
94
+ bucket=self.fallback_bucket or parsed_uri.netloc,
90
95
  )
91
96
  except Exception as fallback_error:
92
97
  raise Exception(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fallbacks3
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: S3-compatible storage library with automatic fallback support
5
5
  Author-email: Mila de Oliveira <mila.oliveira@palver.com.br>
6
6
  Project-URL: Homepage, https://github.com/palverdata/fallbacks3
@@ -49,6 +49,15 @@ PROVIDERS="ps3://access_key:secret_key@ps3.palver.com,r2://access_key:secret_key
49
49
  FALLBACK_PROVIDER="r2"
50
50
  ```
51
51
 
52
+ `FALLBACK_PROVIDER` may also be set as a `<scheme>://<bucket>` URI to redirect fallback
53
+ uploads to a specific bucket instead of reusing the original request's bucket. The scheme
54
+ must still be one of the providers in `PROVIDERS`.
55
+
56
+ ```bash
57
+ # On fallback, upload to bucket "bucket-v2" on the r2 provider
58
+ FALLBACK_PROVIDER="r2://bucket-v2"
59
+ ```
60
+
52
61
 
53
62
  ### Provider URI Format
54
63
 
@@ -108,7 +117,7 @@ print(signed_url) # "https://ps3.palver.com/palver-whatsapp/audio.mp3?signature
108
117
 
109
118
  ### Upload with Automatic Fallback
110
119
 
111
- If the primary provider fails for the upload method, the library automatically retries with the fallback provider (using the same bucket and file path), as to ensure files are not lost.
120
+ If the primary provider fails for the upload method, the library automatically retries with the fallback provider (using the same bucket and file path, unless `FALLBACK_PROVIDER` specifies a bucket), as to ensure files are not lost.
112
121
 
113
122
  ```python
114
123
  # If ps3 fails, automatically falls back to r2
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "fallbacks3"
7
- version = "0.4.0"
7
+ version = "0.5.0"
8
8
  description = "S3-compatible storage library with automatic fallback support"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
File without changes