Skip to content

Commit 444097d

Browse files
authored
Add docstrings for _files/domain.py (#98)
1 parent b64efe3 commit 444097d

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

src/yandex_cloud_ml_sdk/_files/domain.py

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@
1212
from yandex_cloud_ml_sdk._types.domain import BaseDomain
1313
from yandex_cloud_ml_sdk._types.expiration import ExpirationConfig, ExpirationPolicyAlias
1414
from yandex_cloud_ml_sdk._types.misc import UNDEFINED, PathLike, UndefinedOr, coerce_path, get_defined_value, is_defined
15+
from yandex_cloud_ml_sdk._utils.doc import doc_from
1516
from yandex_cloud_ml_sdk._utils.sync import run_sync, run_sync_generator
1617

1718
from .file import AsyncFile, File, FileTypeT
1819

1920

2021
class BaseFiles(BaseDomain, Generic[FileTypeT]):
22+
"""Files domain, which contains API for working with files.
23+
24+
Files is a part of :ref:`Assistants API`, which is the only place you could use it.
25+
Provides upload, get and list methods that allow you to work with remote file objects you created earlier.
26+
"""
2127
_file_impl: type[FileTypeT]
2228

2329
async def _upload_bytes(
@@ -32,6 +38,20 @@ async def _upload_bytes(
3238
expiration_policy: UndefinedOr[ExpirationPolicyAlias] = UNDEFINED,
3339
timeout: float = 60,
3440
) -> FileTypeT:
41+
"""Uploads a byte array as a file.
42+
43+
:param data: The byte data to upload.
44+
:param name: The name of the file on the server.
45+
:param description: A description of the file.
46+
:param mime_type: The MIME type of the file.
47+
By default (i.e. when UNDEFINED) the server will try to auto-detect mime-type and you could override this file.
48+
:param labels: Labels associated with the file.
49+
:param ttl_days: Time-to-live in days for the file.
50+
:param expiration_policy: Expiration policy for the file.
51+
Assepts for passing :ref:`static` or :ref:`since_last_active` strings. Should be defined if :ref:`ttl_days` has been defined, otherwise both parameters should be undefined.
52+
:param timeout: Timeout for the operation in seconds.
53+
Defaults to 60 seconds.
54+
"""
3555
if is_defined(ttl_days) != is_defined(expiration_policy):
3656
raise ValueError("ttl_days and expiration policy must be both defined either undefined")
3757

@@ -69,6 +89,20 @@ async def _upload(
6989
expiration_policy: UndefinedOr[ExpirationPolicyAlias] = UNDEFINED,
7090
timeout: float = 60,
7191
) -> FileTypeT:
92+
"""Uploads a file from a specified path.
93+
94+
:param path: The path of the file to upload.
95+
:param name: The name of the file on the server.
96+
:param description: A description of the file.
97+
:param mime_type: The MIME type of the file.
98+
By default (i.e. when UNDEFINED) the server will try to auto-detect mime-type and you could override this file.
99+
:param labels: Labels associated with the file.
100+
:param ttl_days: Time-to-live in days for the file.
101+
:param expiration_policy: Expiration policy for the file.
102+
Assepts for passing :ref:`static` or :ref:`since_last_active` strings.
103+
:param timeout: Timeout for the operation in seconds.
104+
Defaults to 60.
105+
"""
72106
path = coerce_path(path)
73107
return await self._upload_bytes(
74108
data=path.read_bytes(),
@@ -87,6 +121,12 @@ async def _get(
87121
*,
88122
timeout: float = 60,
89123
) -> FileTypeT:
124+
"""Retrieves a file by its ID.
125+
126+
:param file_id: The unique identifier of the file to retrieve.
127+
:param timeout: Timeout for the operation in seconds.
128+
Defaults to 60.
129+
"""
90130
# TODO: we need a global per-sdk cache on file_ids to rule out
91131
# possibility we have two Files with same ids but different fields
92132
request = GetFileRequest(file_id=file_id)
@@ -107,6 +147,12 @@ async def _list(
107147
page_size: UndefinedOr[int] = UNDEFINED,
108148
timeout: float = 60
109149
) -> AsyncIterator[FileTypeT]:
150+
"""Lists Files in the SDK folder.
151+
152+
:param page_size: The maximum number of files to return per page.
153+
:param timeout: Timeout for the operation in seconds.
154+
Defaults to 60.
155+
"""
110156
page_token_ = ''
111157
page_size_ = get_defined_value(page_size, 0)
112158

@@ -132,10 +178,11 @@ async def _list(
132178

133179
page_token_ = response.next_page_token
134180

135-
181+
@doc_from(BaseFiles)
136182
class AsyncFiles(BaseFiles[AsyncFile]):
137183
_file_impl = AsyncFile
138184

185+
@doc_from(BaseFiles._upload_bytes)
139186
async def upload_bytes(
140187
self,
141188
data: bytes,
@@ -159,6 +206,7 @@ async def upload_bytes(
159206
timeout=timeout
160207
)
161208

209+
@doc_from(BaseFiles._upload)
162210
async def upload(
163211
self,
164212
path: PathLike,
@@ -182,6 +230,7 @@ async def upload(
182230
timeout=timeout
183231
)
184232

233+
@doc_from(BaseFiles._get)
185234
async def get(
186235
self,
187236
file_id: str,
@@ -193,6 +242,7 @@ async def get(
193242
timeout=timeout
194243
)
195244

245+
@doc_from(BaseFiles._list)
196246
async def list(
197247
self,
198248
*,
@@ -205,7 +255,7 @@ async def list(
205255
):
206256
yield file
207257

208-
258+
@doc_from(BaseFiles)
209259
class Files(BaseFiles[File]):
210260
_file_impl = File
211261

@@ -214,6 +264,7 @@ class Files(BaseFiles[File]):
214264
__get = run_sync(BaseFiles._get)
215265
__list = run_sync_generator(BaseFiles._list)
216266

267+
@doc_from(BaseFiles._upload_bytes)
217268
def upload_bytes(
218269
self,
219270
data: bytes,
@@ -237,6 +288,7 @@ def upload_bytes(
237288
timeout=timeout
238289
)
239290

291+
@doc_from(BaseFiles._upload)
240292
def upload(
241293
self,
242294
path: PathLike,
@@ -260,6 +312,7 @@ def upload(
260312
timeout=timeout
261313
)
262314

315+
@doc_from(BaseFiles._get)
263316
def get(
264317
self,
265318
file_id: str,
@@ -271,6 +324,7 @@ def get(
271324
timeout=timeout
272325
)
273326

327+
@doc_from(BaseFiles._list)
274328
def list(
275329
self,
276330
*,

0 commit comments

Comments
 (0)