|
| 1 | +# replit.object\_storage.client |
| 2 | + |
| 3 | +Client for interacting with Object Storage. This is the top-level interface. |
| 4 | + |
| 5 | +Note: this Client is a thin wrapper over the GCS Python Library. As a result, |
| 6 | +many docstrings are borrowed from the underlying library. |
| 7 | + |
| 8 | +## Class Client |
| 9 | + |
| 10 | +```python |
| 11 | +class Client() |
| 12 | +``` |
| 13 | + |
| 14 | +Client manages interactions with Replit Object Storage. |
| 15 | + |
| 16 | +If multiple buckets are used within an application, one Client should be used |
| 17 | +per bucket |
| 18 | + |
| 19 | +Any method may return one of the following errors: |
| 20 | +- `BucketNotFoundError`: If the bucket configured for the client could not be found. |
| 21 | +- `DefaultBucketError`: If no bucket was explicitly configured and an error occurred |
| 22 | + when resolving the default bucket. |
| 23 | +- `ForbiddenError`: If access to the requested resource is not allowed. |
| 24 | +- `TooManyRequestsError`: If rate limiting occurs. |
| 25 | +- `UnauthorizedError`: If the requested operation is not allowed. |
| 26 | + |
| 27 | +#### \_\_init\_\_ |
| 28 | + |
| 29 | +```python |
| 30 | +def __init__(bucket_id: Optional[str] = None) |
| 31 | +``` |
| 32 | + |
| 33 | +Creates a new Client. |
| 34 | + |
| 35 | +**Arguments**: |
| 36 | + |
| 37 | +- `bucket_id` - The ID of the bucket this Client should interface with. |
| 38 | + If no ID is defined, the Repl / Deployment's default bucket will be |
| 39 | + used. |
| 40 | + |
| 41 | +#### copy |
| 42 | + |
| 43 | +```python |
| 44 | +def copy(object_name: str, dest_object_name: str) -> None |
| 45 | +``` |
| 46 | + |
| 47 | +Copies the specified object within the same bucket. |
| 48 | + |
| 49 | +If an object exists in the same location, it will be overwritten. |
| 50 | + |
| 51 | +**Arguments**: |
| 52 | + |
| 53 | +- `object_name` - The full path of the object to be copied. |
| 54 | +- `dest_object_name` - The full path to copy the object to. |
| 55 | + |
| 56 | + |
| 57 | +**Raises**: |
| 58 | + |
| 59 | +- `ObjectNotFoundError` - If the source object could not be found. |
| 60 | + |
| 61 | +#### delete |
| 62 | + |
| 63 | +```python |
| 64 | +def delete(object_name: str, ignore_not_found: bool = False) -> None |
| 65 | +``` |
| 66 | + |
| 67 | +Deletes an object from Object Storage. |
| 68 | + |
| 69 | +**Arguments**: |
| 70 | + |
| 71 | +- `object_name` - The name of the object to be deleted. |
| 72 | +- `ignore_not_found` - Whether an error should be raised if the object does not |
| 73 | + exist. |
| 74 | + |
| 75 | + |
| 76 | +**Raises**: |
| 77 | + |
| 78 | +- `ObjectNotFoundError` - If the object could not be found. |
| 79 | + |
| 80 | +#### download\_as\_bytes |
| 81 | + |
| 82 | +```python |
| 83 | +def download_as_bytes(object_name: str) -> bytes |
| 84 | +``` |
| 85 | + |
| 86 | +Download the contents an object as a bytes object. |
| 87 | + |
| 88 | +**Arguments**: |
| 89 | + |
| 90 | +- `object_name` - The name of the object to be downloaded. |
| 91 | + |
| 92 | + |
| 93 | +**Returns**: |
| 94 | + |
| 95 | + The raw byte representation of the object's contents. |
| 96 | + |
| 97 | + |
| 98 | +**Raises**: |
| 99 | + |
| 100 | +- `ObjectNotFoundError` - If the object could not be found. |
| 101 | + |
| 102 | +#### download\_as\_text |
| 103 | + |
| 104 | +```python |
| 105 | +def download_as_text(object_name: str) -> str |
| 106 | +``` |
| 107 | + |
| 108 | +Download the contents an object as a string. |
| 109 | + |
| 110 | +**Arguments**: |
| 111 | + |
| 112 | +- `object_name` - The name of the object to be downloaded. |
| 113 | + |
| 114 | + |
| 115 | +**Returns**: |
| 116 | + |
| 117 | + The object's contents as a UTF-8 encoded string. |
| 118 | + |
| 119 | + |
| 120 | +**Raises**: |
| 121 | + |
| 122 | +- `ObjectNotFoundError` - If the object could not be found. |
| 123 | + |
| 124 | +#### download\_to\_filename |
| 125 | + |
| 126 | +```python |
| 127 | +def download_to_filename(object_name: str, dest_filename: str) -> None |
| 128 | +``` |
| 129 | + |
| 130 | +Download the contents an object into a file on the local disk. |
| 131 | + |
| 132 | +**Arguments**: |
| 133 | + |
| 134 | +- `object_name` - The name of the object to be downloaded. |
| 135 | +- `dest_filename` - The filename of the file on the local disk to be written. |
| 136 | + |
| 137 | + |
| 138 | +**Raises**: |
| 139 | + |
| 140 | +- `ObjectNotFoundError` - If the object could not be found. |
| 141 | + |
| 142 | +#### exists |
| 143 | + |
| 144 | +```python |
| 145 | +def exists(object_name: str) -> bool |
| 146 | +``` |
| 147 | + |
| 148 | +Checks if an object exist. |
| 149 | + |
| 150 | +**Arguments**: |
| 151 | + |
| 152 | +- `object_name` - The name of the object to be checked. |
| 153 | + |
| 154 | + |
| 155 | +**Returns**: |
| 156 | + |
| 157 | + Whether or not the object exists. |
| 158 | + |
| 159 | +#### list |
| 160 | + |
| 161 | +```python |
| 162 | +def list(end_offset: Optional[str] = None, |
| 163 | + match_glob: Optional[str] = None, |
| 164 | + max_results: Optional[int] = None, |
| 165 | + prefix: Optional[str] = None, |
| 166 | + start_offset: Optional[str] = None) -> List[Object] |
| 167 | +``` |
| 168 | + |
| 169 | +Lists objects in the bucket. |
| 170 | + |
| 171 | +**Arguments**: |
| 172 | + |
| 173 | +- `end_offset` - Filter results to objects whose names are lexicographically |
| 174 | + before end_offset. If start_offset is also set, the objects listed |
| 175 | + have names between start_offset (inclusive) and end_offset |
| 176 | + (exclusive). |
| 177 | +- `match_glob` - Glob pattern used to filter results, for example foo*bar. |
| 178 | +- `max_results` - The maximum number of results that can be returned in the |
| 179 | + response. |
| 180 | +- `prefix` - Filter results to objects who names have the specified prefix. |
| 181 | +- `start_offset` - Filter results to objects whose names are |
| 182 | + lexicographically equal to or after start_offset. If endOffset is |
| 183 | + also set, the objects listed have names between start_offset |
| 184 | + (inclusive) and end_offset (exclusive). |
| 185 | + |
| 186 | + |
| 187 | +**Returns**: |
| 188 | + |
| 189 | + A list of objects matching the given query parameters. |
| 190 | + |
| 191 | +#### upload\_from\_filename |
| 192 | + |
| 193 | +```python |
| 194 | +def upload_from_filename(dest_object_name: str, src_filename: str) -> None |
| 195 | +``` |
| 196 | + |
| 197 | +Upload an object from a file on the local disk. |
| 198 | + |
| 199 | +**Arguments**: |
| 200 | + |
| 201 | +- `dest_object_name` - The name of the object to be uploaded. |
| 202 | +- `src_filename` - The filename of a file on the local disk |
| 203 | + |
| 204 | +#### upload\_from\_bytes |
| 205 | + |
| 206 | +```python |
| 207 | +def upload_from_bytes(dest_object_name: str, src_data: bytes) -> None |
| 208 | +``` |
| 209 | + |
| 210 | +Upload an object from bytes. |
| 211 | + |
| 212 | +**Arguments**: |
| 213 | + |
| 214 | +- `dest_object_name` - The name of the object to be uploaded. |
| 215 | +- `src_data` - The bytes to be uploaded. |
| 216 | + |
| 217 | +#### upload\_from\_text |
| 218 | + |
| 219 | +```python |
| 220 | +def upload_from_text(dest_object_name: str, src_data: Union[bytes, |
| 221 | + str]) -> None |
| 222 | +``` |
| 223 | + |
| 224 | +Upload an object from a string. |
| 225 | + |
| 226 | +**Arguments**: |
| 227 | + |
| 228 | +- `dest_object_name` - The name of the object to be uploaded. |
| 229 | +- `src_data` - The text to be uploaded. |
| 230 | + |
0 commit comments