Skip to content

Commit 14f82e4

Browse files
committed
Add YepCode Storage sdk
1 parent 0dda9ba commit 14f82e4

2 files changed

Lines changed: 112 additions & 0 deletions

File tree

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,36 @@ api = YepCodeApi(
105105
processes = api.get_processes()
106106
```
107107

108+
### 6. YepCode Storage
109+
110+
You can manage files in your YepCode workspace using the `YepCodeStorage` class. This allows you to upload, list, download, and delete files easily.
111+
112+
```python
113+
from yepcode_run import YepCodeStorage, YepCodeApiConfig
114+
115+
storage = YepCodeStorage(
116+
YepCodeApiConfig(api_token='your-api-token')
117+
)
118+
119+
# Upload a file
120+
with open('myfile.txt', 'rb') as f:
121+
obj = storage.upload('myfile.txt', f)
122+
print('Uploaded:', obj.name, obj.size, obj.link)
123+
124+
# List all storage objects
125+
objects = storage.list()
126+
for obj in objects:
127+
print(obj.name, obj.size, obj.link)
128+
129+
# Download a file
130+
content = storage.download('myfile.txt')
131+
with open('downloaded.txt', 'wb') as f:
132+
f.write(content)
133+
134+
# Delete a file
135+
storage.delete('myfile.txt')
136+
```
137+
108138
## SDK API Reference
109139

110140
### YepCodeRun
@@ -237,6 +267,59 @@ class Process:
237267
created_at: str
238268
```
239269

270+
### YepCodeStorage
271+
272+
The main class for managing files in YepCode's cloud storage.
273+
274+
#### Methods
275+
276+
##### `upload(name: str, file: bytes) -> StorageObject`
277+
Uploads a file to YepCode storage.
278+
279+
**Parameters:**
280+
- `name`: Name of the file in storage
281+
- `file`: File content as bytes or a file-like object
282+
283+
**Returns:** StorageObject
284+
285+
##### `download(name: str) -> bytes`
286+
Downloads a file from YepCode storage.
287+
288+
**Parameters:**
289+
- `name`: Name of the file to download
290+
291+
**Returns:** File content as bytes
292+
293+
##### `delete(name: str) -> None`
294+
Deletes a file from YepCode storage.
295+
296+
**Parameters:**
297+
- `name`: Name of the file to delete
298+
299+
**Returns:** None
300+
301+
##### `list() -> List[StorageObject]`
302+
Lists all files in YepCode storage.
303+
304+
**Returns:** List of StorageObject
305+
306+
#### Types
307+
308+
```python
309+
class StorageObject:
310+
name: str # File name
311+
size: int # File size in bytes
312+
md5_hash: str # MD5 hash of the file
313+
content_type: str # MIME type
314+
created_at: str # Creation timestamp (ISO8601)
315+
updated_at: str # Last update timestamp (ISO8601)
316+
link: str # Download link
317+
318+
class CreateStorageObjectInput:
319+
name: str # File name
320+
file: Any # File content (bytes or file-like)
321+
```
322+
240323
## License
241324

242325
All rights reserved by YepCode. This package is part of the YepCode Platform and is subject to the [YepCode Terms of Service](https://yepcode.io/terms-of-use).
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from typing import List
2+
3+
from ..api.api_manager import YepCodeApiManager
4+
from ..api.types import CreateStorageObjectInput, StorageObject, YepCodeApiConfig
5+
6+
7+
class YepCodeStorage:
8+
def __init__(self, config: YepCodeApiConfig = None):
9+
"""
10+
Initialize YepCodeStorage with optional configuration.
11+
12+
Args:
13+
config: YepCodeApiConfig instance for API configuration
14+
"""
15+
self._api = YepCodeApiManager.get_instance(config)
16+
17+
def download(self, name: str) -> bytes:
18+
return self._api.get_object(name).content
19+
20+
def upload(self, name: str, file: bytes) -> StorageObject:
21+
return self._api.create_object(
22+
CreateStorageObjectInput(name=name, file=file)
23+
)
24+
25+
def delete(self, name: str) -> None:
26+
return self._api.delete_object(name)
27+
28+
def list(self) -> List[StorageObject]:
29+
return self._api.get_objects()

0 commit comments

Comments
 (0)