Documentation
YaDisk object
- class yadisk_async.YaDisk(id: str = '', secret: str = '', token: str = '', default_args: dict[str, Any] | None = None)[source]
Implements access to Yandex.Disk REST API.
Note
Do not forget to call
YaDisk.close
or use the async with statement to close all the connections. Otherwise, you may get a warning.In the original library this is handled in the destructor, but since
aiohttp.ClientSession.close
is a coroutine function the same cannot be done here, so you have to do it explicitly.- Parameters:
id – application ID
secret – application secret password
token – application token
default_args – dict or None, default arguments for methods. Can be used to set the default timeout, headers, etc.
- Variables:
id – str, application ID
secret – str, application secret password
token – str, application token
default_args – dict, default arguments for methods. Can be used to set the default timeout, headers, etc.
The following exceptions may be raised by most API requests:
- Raises:
BadRequestError – server returned HTTP code 400
FieldValidationError – request contains fields with invalid data
UnauthorizedError – server returned HTTP code 401
ForbiddenError – server returned HTTP code 403
NotAcceptableError – server returned HTTP code 406
ConflictError – server returned HTTP code 409
PayloadTooLargeError – server returned code 413
UnsupportedMediaError – server returned HTTP code 415
LockedError – server returned HTTP code 423
TooManyRequestsError – server returned HTTP code 429
InternalServerError – server returned HTTP code 500
BadGatewayError – server returned HTTP code 502
UnavailableError – server returned HTTP code 503
GatewayTimeoutError – server returned HTTP code 504
InsufficientStorageError – server returned HTTP code 509
UnknownYaDiskError – other unknown error
- async check_token(token: str | None = None, /, **kwargs) bool [source]
Check whether the token is valid.
- Parameters:
token – token to check, equivalent to self.token if None
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Returns:
bool
- async close() None [source]
Closes all sessions and clears the session cache. Do not call this method while there are other active threads using this object.
This method can also be called implicitly by using the async with statement.
- async copy(src_path: str, dst_path: str, /, **kwargs) ResourceLinkObject | OperationLinkObject [source]
Copy src_path to dst_path. If the operation is performed asynchronously, returns the link to the operation, otherwise, returns the link to the newly created resource.
- Parameters:
src_path – source path
dst_path – destination path
overwrite – if True the destination path can be overwritten, otherwise, an error will be raised
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
InsufficientStorageError – cannot complete request due to lack of storage space
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
- async download(src_path: str, path_or_file: str | bytes | IO[bytes] | BinaryAsyncFileLike, /, **kwargs) ResourceLinkObject [source]
Download the file.
- Parameters:
src_path – source path
path_or_file – destination path or file-like object
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
ResourceLinkObject
, link to the source resource
- async download_by_link(link: str, file_or_path: str | bytes | IO[bytes] | BinaryAsyncFileLike, /, **kwargs) None [source]
Download the file from the link.
- Parameters:
link – download link
file_or_path – destination path or file-like object
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- async download_public(public_key: str, file_or_path: str | bytes | IO, /, **kwargs) PublicResourceLinkObject [source]
Download the public resource.
- Parameters:
public_key – public key or public URL of the resource
file_or_path – destination path or file-like object
path – relative path to the resource within the public folder
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async exists(path: str, /, **kwargs) bool [source]
Check whether path exists.
- Parameters:
path – path to the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
bool
- get_auth_url(**kwargs) str [source]
Get authentication URL for the user to go to.
- Parameters:
type – response type (“code” to get the confirmation code or “token” to get the token automatically)
device_id – unique device ID, must be between 6 and 50 characters
device_name – device name, should not be longer than 100 characters
display – indicates whether to use lightweight layout, values other than “popup” are ignored
login_hint – username or email for the account the token is being requested for
scope – list of permissions for the application
optional_scope – list of optional permissions for the application
force_confirm – if True, user will be required to confirm access to the account even if the user has already granted access for the application
state – The state string, which Yandex.OAuth returns without any changes (<= 1024 characters)
- Returns:
authentication URL
- get_code_url(**kwargs) str [source]
Get the URL for the user to get the confirmation code. The confirmation code can later be used to get the token.
- Parameters:
device_id – unique device ID, must be between 6 and 50 characters
device_name – device name, should not be longer than 100 characters
display – indicates whether to use lightweight layout, values other than “popup” are ignored
login_hint – username or email for the account the token is being requested for
scope – list of permissions for the application
optional_scope – list of optional permissions for the application
force_confirm – if True, user will be required to confirm access to the account even if the user has already granted access for the application
state – The state string, which Yandex.OAuth returns without any changes (<= 1024 characters)
- Returns:
authentication URL
- async get_disk_info(**kwargs) DiskInfoObject [source]
Get disk information.
- Parameters:
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_download_link(path: str, /, **kwargs) str [source]
Get a download link for a file (or a directory).
- Parameters:
path – path to the resource
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
str
- async get_files(**kwargs) AsyncGenerator[ResourceObject, None] [source]
Get a flat list of all files (that doesn’t include directories).
- Parameters:
offset – offset from the beginning of the list
limit – number of list elements to be included
media_type – type of files to include in the list
sort – str, field to be used as a key to sort children resources
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
generator of
ResourceObject
- async get_last_uploaded(**kwargs) AsyncGenerator[ResourceObject, None] [source]
Get the list of latest uploaded files sorted by upload date.
- Parameters:
limit – maximum number of elements in the list
media_type – type of files to include in the list
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
generator of
ResourceObject
- async get_meta(path: str, /, **kwargs) ResourceObject [source]
Get meta information about a file/directory.
- Parameters:
path – path to the resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_operation_status(operation_id, **kwargs)[source]
Get operation status.
- Parameters:
operation_id – ID of the operation or a link
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
OperationNotFoundError – requested operation was not found
- Returns:
str
- async get_public_download_link(public_key: str, /, **kwargs) str [source]
Get a download link for a public resource.
- Parameters:
public_key – public key or public URL of the resource
path – relative path to the resource within the public folder
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
str
- async get_public_meta(public_key: str, /, **kwargs) PublicResourceObject [source]
Get meta-information about a public resource.
- Parameters:
public_key – public key or public URL of the resource
path – relative path to a resource in a public folder. By specifying the key of the published folder in public_key, you can request metainformation for any resource in the folder.
offset – offset from the beginning of the list of nested resources
limit – maximum number of nested elements to be included in the list
sort – str, field to be used as a key to sort children resources
preview_size – file preview size
preview_crop – bool, allow preview crop
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_public_resources(**kwargs) PublicResourcesListObject [source]
Get a list of public resources.
- Parameters:
offset – offset from the beginning of the list
limit – maximum number of elements in the list
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
type – filter based on type of resources (“file” or “dir”)
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_public_type(public_key: str, /, **kwargs) str [source]
Get public resource type.
- Parameters:
public_key – public key or public URL of the resource
path – relative path to the resource within the public folder
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
“file” or “dir”
- get_session(token: str | None = None) SessionWithHeaders [source]
Like
YaDisk.make_session
but cached.- Returns:
aiohttp.ClientSession
, different instances for different threads
- async get_token(code: str, /, **kwargs) TokenObject [source]
Get a new token.
- Parameters:
code – confirmation code
device_id – unique device ID (between 6 and 50 characters)
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
BadRequestError – invalid or expired code, application ID or secret
- Returns:
- async get_trash_meta(path: str, /, **kwargs) TrashResourceObject [source]
Get meta information about a trash resource.
- Parameters:
path – path to the trash resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_trash_type(path: str, /, **kwargs) str [source]
Get trash resource type.
- Parameters:
path – path to the trash resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
“file” or “dir”
- async get_type(path: str, /, **kwargs) str [source]
Get resource type.
- Parameters:
path – path to the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
“file” or “dir”
- async get_upload_link(path: str, /, **kwargs) str [source]
Get a link to upload the file using the PUT request.
- Parameters:
path – destination path
overwrite – bool, determines whether to overwrite the destination
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
str
- async is_dir(path: str, /, **kwargs) bool [source]
Check whether path is a directory.
- Parameters:
path – path to the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a directory, False otherwise (even if it doesn’t exist)
- async is_file(path: str, /, **kwargs) bool [source]
Check whether path is a file.
- Parameters:
path – path to the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a file, False otherwise (even if it doesn’t exist)
- async is_public_dir(public_key: str, /, **kwargs) bool [source]
Check whether public_key is a public directory.
- Parameters:
public_key – public key or public URL of the resource
path – relative path to the resource within the public folder
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if public_key is a directory, False otherwise (even if it doesn’t exist)
- async is_public_file(public_key: str, /, **kwargs) bool [source]
Check whether public_key is a public file.
- Parameters:
public_key – public key or public URL of the resource
path – relative path to the resource within the public folder
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if public_key is a file, False otherwise (even if it doesn’t exist)
- async is_trash_dir(path: str, /, **kwargs) bool [source]
Check whether path is a trash directory.
- Parameters:
path – path to the trash resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a directory, False otherwise (even if it doesn’t exist)
- async is_trash_file(path: str, /, **kwargs) bool [source]
Check whether path is a trash file.
- Parameters:
path – path to the trash resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a directory, False otherwise (even if it doesn’t exist)
- async listdir(path: str, /, **kwargs) AsyncGenerator[ResourceObject, None] [source]
Get contents of path.
- Parameters:
path – path to the directory
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
ResourceObject
- make_session(token: str | None = None) SessionWithHeaders [source]
Prepares
aiohttp.ClientSession
object with headers needed for API.- Parameters:
token – application token, equivalent to self.token if None
- Returns:
aiohttp.ClientSession
- async mkdir(path: str, /, **kwargs) ResourceLinkObject [source]
Create a new directory.
- Parameters:
path – path to the directory to be created
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
DirectoryExistsError – destination path already exists
InsufficientStorageError – cannot create directory due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async move(src_path: str, dst_path: str, /, **kwargs) OperationLinkObject | ResourceLinkObject [source]
Move src_path to dst_path.
- Parameters:
src_path – source path to be moved
dst_path – destination path
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async patch(path: str, properties: dict, /, **kwargs) ResourceObject [source]
Update custom properties of a resource.
- Parameters:
path – path to the resource
properties – dict, custom properties to update
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async public_exists(public_key: str, /, **kwargs) bool [source]
Check whether the public resource exists.
- Parameters:
public_key – public key or public URL of the resource
path – relative path to the resource within the public folder
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
bool
- async public_listdir(public_key: str, /, **kwargs) AsyncGenerator[PublicResourceObject, None] [source]
Get contents of a public directory.
- Parameters:
public_key – public key or public URL of the resource
path – relative path to the resource in the public folder. By specifying the key of the published folder in public_key, you can request contents of any nested folder.
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
PublicResourceObject
- async publish(path: str, /, **kwargs) ResourceLinkObject [source]
Make a resource public.
- Parameters:
path – path to the resource to be published
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
ResourceLinkObject
, link to the resource
- async refresh_token(refresh_token: str, /, **kwargs) TokenObject [source]
Refresh an existing token.
- Parameters:
refresh_token – the refresh token that was received with the token
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
BadRequestError – invalid or expired refresh token, application ID or secret
- Returns:
- async remove(path: str, /, **kwargs) OperationLinkObject | None [source]
Remove the resource.
- Parameters:
path – path to the resource to be removed
permanently – if True, the resource will be removed permanently, otherwise, it will be just moved to the trash
md5 – str, MD5 hash of the file to remove
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
BadRequestError – MD5 check is only available for files
ResourceIsLockedError – resource is locked by another request
- Returns:
OperationLinkObject
if the operation is performed asynchronously, None otherwise
- async remove_trash(path: str, /, **kwargs) OperationLinkObject | None [source]
Remove a trash resource.
- Parameters:
path – path to the trash resource to be deleted
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
OperationLinkObject
if the operation is performed asynchronously, None otherwise
- async rename(src_path: str, new_name: str, /, **kwargs) ResourceLinkObject | OperationLinkObject [source]
Rename src_path to have filename new_name. Does the same as move() but changes only the filename.
- Parameters:
src_path – source path to be moved
new_name – target filename to rename to
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
ValueError – new_name is not a valid filename
- Returns:
- async restore_trash(path: str, dst_path: str | None = None, /, **kwargs) ResourceLinkObject | OperationLinkObject [source]
Restore a trash resource. Returns a link to the newly created resource or a link to the asynchronous operation.
- Parameters:
path – path to the trash resource to restore
dst_path – destination path
overwrite – bool, determines whether the destination can be overwritten
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async revoke_token(token: str | None = None, /, **kwargs) TokenRevokeStatusObject [source]
Revoke the token.
- Parameters:
token – token to revoke, equivalent to self.token if None
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
BadRequestError – token cannot be revoked (not bound to this application, etc.)
- Returns:
- async save_to_disk(public_key: str, /, **kwargs) ResourceLinkObject | OperationLinkObject [source]
Saves a public resource to the disk. Returns the link to the operation if it’s performed asynchronously, or a link to the resource otherwise.
- Parameters:
public_key – public key or public URL of the resource
name – filename of the saved resource
path – path to the copied resource in the public folder
save_path – path to the destination directory (downloads directory by default)
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
- async trash_exists(path: str, /, **kwargs) bool [source]
Check whether the trash resource at path exists.
- Parameters:
path – path to the trash resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
bool
- async trash_listdir(path: str, /, **kwargs) AsyncGenerator[TrashResourceObject, None] [source]
Get contents of a trash resource.
- Parameters:
path – path to the directory in the trash bin
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
TrashResourceObject
- async unpublish(path: str, /, **kwargs) ResourceLinkObject [source]
Make a public resource private.
- Parameters:
path – path to the resource to be unpublished
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async upload(path_or_file: str | bytes | IO | AsyncFileLike | Callable[[], AsyncIterable[bytes]], dst_path: str, /, **kwargs) ResourceLinkObject [source]
Upload a file to disk.
- Parameters:
path_or_file – path, file-like object or an async generator function to be uploaded
dst_path – destination path
overwrite – if True, the resource will be overwritten if it already exists, an error will be raised otherwise
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
InsufficientStorageError – cannot upload file due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
ResourceLinkObject
, link to the destination resource
- async upload_by_link(file_or_path: str | bytes | IO | AsyncFileLike | Callable[[], AsyncIterable[bytes]], link: str, /, **kwargs) None [source]
Upload a file to disk using an upload link.
- Parameters:
file_or_path – path, file-like object or an async generator function to be uploaded
link – upload link
overwrite – if True, the resource will be overwritten if it already exists, an error will be raised otherwise
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
InsufficientStorageError – cannot upload file due to lack of storage space
- async upload_url(url: str, path: str, /, **kwargs) OperationLinkObject [source]
Upload a file from URL.
- Parameters:
url – source URL
path – destination path
disable_redirects – bool, forbid redirects
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
InsufficientStorageError – cannot upload file due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
OperationLinkObject
, link to the asynchronous operation
General parameters
Almost all methods of YaDisk (the ones that accept **kwargs) accept some additional arguments:
n_retries - int, maximum number of retries for a request
retry_interval - float, delay between retries (in seconds)
headers - dict or None, additional request headers
aiohttp parameters like timeout, proxies, etc. are also accepted (see aiohttp.request()
).
This also applies to low-level functions and API request objects as well.
Settings
The following settings can be accessed and changed at runtime in yadisk_async.settings module:
DEFAULT_TIMEOUT -
aiohttp.ClientTimeout
, default timeout for requests.DEFAULT_N_RETRIES - int, default number of retries
DEFAULT_RETRY_INTERVAL - float, default retry interval
DEFAULT_UPLOAD_TIMEOUT - analogous to DEFAULT_TIMEOUT but for upload function
DEFAULT_UPLOAD_RETRY_INTERVAL - analogous to DEFAULT_RETRY_INTERVAL but for upload function
Exceptions
Aside from the exceptions listed below, API requests can also raise exceptions in aiohttp.
- exception yadisk_async.exceptions.BadGatewayError(error_type=None, msg='', response=None)[source]
Bases:
RetriableYaDiskError
Thrown when the server returns code 502
- exception yadisk_async.exceptions.BadRequestError(error_type=None, msg='', response=None)[source]
Bases:
YaDiskError
Thrown when the server returns code 400.
- exception yadisk_async.exceptions.ConflictError(error_type=None, msg='', response=None)[source]
Bases:
YaDiskError
Thrown when the server returns code 409.
- exception yadisk_async.exceptions.DirectoryExistsError(error_type=None, msg='', response=None)[source]
Bases:
PathExistsError
Thrown when the directory already exists.
- exception yadisk_async.exceptions.FieldValidationError(error_type=None, msg='', response=None)[source]
Bases:
BadRequestError
Thrown when the request contains fields with invalid data.
- exception yadisk_async.exceptions.ForbiddenError(error_type=None, msg='', response=None)[source]
Bases:
YaDiskError
Thrown when the server returns code 403.
- exception yadisk_async.exceptions.GatewayTimeoutError(error_type=None, msg='', response=None)[source]
Bases:
RetriableYaDiskError
Thrown when the server returns code 504
- exception yadisk_async.exceptions.InsufficientStorageError(error_type=None, msg='', response=None)[source]
Bases:
YaDiskError
Thrown when the server returns code 507.
- exception yadisk_async.exceptions.InternalServerError(error_type=None, msg='', response=None)[source]
Bases:
RetriableYaDiskError
Thrown when the server returns code 500.
- exception yadisk_async.exceptions.InvalidResponseError(error_type=None, msg='', response=None)[source]
Bases:
YaDiskError
Thrown when Yandex.Disk did not return a JSON response or if it’s invalid.
- exception yadisk_async.exceptions.LockedError(error_type=None, msg='', response=None)[source]
Bases:
YaDiskError
Thrown when the server returns code 423.
- exception yadisk_async.exceptions.MD5DifferError(error_type=None, msg='', response=None)[source]
Bases:
ConflictError
Thrown when the MD5 hash of the file to be deleted doesn’t match with the actual one.
- exception yadisk_async.exceptions.NotAcceptableError(error_type=None, msg='', response=None)[source]
Bases:
YaDiskError
Thrown when the server returns code 406.
- exception yadisk_async.exceptions.NotFoundError(error_type=None, msg='', response=None)[source]
Bases:
YaDiskError
Thrown when the server returns code 404.
- exception yadisk_async.exceptions.OperationNotFoundError(error_type=None, msg='', response=None)[source]
Bases:
NotFoundError
Thrown by get_operation_status() when the operation doesn’t exist.
- exception yadisk_async.exceptions.ParentNotFoundError(error_type=None, msg='', response=None)[source]
Bases:
ConflictError
Thrown by mkdir, upload, etc. when the parent directory doesn’t exist.
- exception yadisk_async.exceptions.PathExistsError(error_type=None, msg='', response=None)[source]
Bases:
ConflictError
Thrown when the requested path already exists.
- exception yadisk_async.exceptions.PathNotFoundError(error_type=None, msg='', response=None)[source]
Bases:
NotFoundError
Thrown when the requested path does not exist.
- exception yadisk_async.exceptions.PayloadTooLargeError(error_type=None, msg='', response=None)[source]
Bases:
YaDiskError
Thrown when the server returns code 413.
- exception yadisk_async.exceptions.ResourceIsLockedError(error_type=None, msg='', response=None)[source]
Bases:
LockedError
Thrown when the resource is locked by another operation.
- exception yadisk_async.exceptions.RetriableYaDiskError(error_type=None, msg='', response=None)[source]
Bases:
YaDiskError
Thrown when there was an error but it would make sense to retry the request.
- exception yadisk_async.exceptions.TooManyRequestsError(error_type=None, msg='', response=None)[source]
Bases:
YaDiskError
Thrown when the server returns code 429.
- exception yadisk_async.exceptions.UnauthorizedError(error_type=None, msg='', response=None)[source]
Bases:
YaDiskError
Thrown when the server returns code 401.
Bases:
RetriableYaDiskError
Thrown when the server returns code 503.
- exception yadisk_async.exceptions.UnknownYaDiskError(msg='', response=None)[source]
Bases:
RetriableYaDiskError
Thrown when the request failed but the response does not contain any error info.
- exception yadisk_async.exceptions.UnsupportedMediaError(error_type=None, msg='', response=None)[source]
Bases:
YaDiskError
Thrown when the server returns code 415.
- exception yadisk_async.exceptions.UploadTrafficLimitExceededError(error_type=None, msg='', response=None)[source]
Bases:
LockedError
Thrown when upload limit has been exceeded.
- exception yadisk_async.exceptions.WrongResourceTypeError(msg='')[source]
Bases:
YaDiskError
Thrown when the resource was expected to be of different type (e.g., file instead of directory).
- exception yadisk_async.exceptions.YaDiskError(error_type=None, msg='', response=None)[source]
Bases:
Exception
Base class for all exceptions in this library.
- Variables:
error_type – str, unique error code as returned by API
response – an instance of
aiohttp.ClientResponse
- Parameters:
error_type – str, unique error code as returned by API
msg – str, exception message
response – an instance of
aiohttp.ClientResponse
Objects
- class yadisk_async.objects.YaDiskObject(field_types: dict | None = None, yadisk: YaDisk | None = None)[source]
Base class for all objects mirroring the ones returned by Yandex.Disk REST API. It must have a fixed number of fields, each field must have a type. It also supports subscripting and access of fields through the . operator.
- Parameters:
field_types – dict or None
yadisk –
YaDisk
or None, YaDisk object
- import_fields(source_dict: dict | None) None [source]
Set all the fields of the object to the values in source_dict. All the other fields are ignored
- Parameters:
source_dict – dict or None (nothing will be done in that case)
- set_alias(alias: str, name: str) None [source]
Set an alias.
- Parameters:
alias – str, alias to add
name – str, field name
- class yadisk_async.objects.ErrorObject(error=None)[source]
Bases:
YaDiskObject
Mirrors Yandex.Disk REST API error object.
- Parameters:
error – dict or None
- Variables:
message – str, human-readable error message
description – str, technical error description
error – str, error code
- class yadisk_async.objects.auth.TokenObject(token: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
YaDiskObject
Token object.
- Parameters:
token – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
access_token – str, token string
refresh_token – str, the refresh-token
token_type – str, type of the token
expires_in – int, amount of time before the token expires
- class yadisk_async.objects.auth.TokenRevokeStatusObject(token_revoke_status: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
YaDiskObject
Result of token revocation request.
- Parameters:
token_revoke_status – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
status – str, status of the operation
- class yadisk_async.objects.disk.DiskInfoObject(disk_info: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
YaDiskObject
Disk information object.
- Parameters:
disk_info – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
max_file_size – int, maximum supported file size (bytes)
paid_max_file_size – int, maximum supported file size for a paid account (bytes)
unlimited_autoupload_enabled – bool, tells whether unlimited autoupload from mobile devices is enabled
total_space – int, total disk size (bytes)
trash_size – int, amount of space used by trash (bytes), part of used_space
is_paid – bool, tells if the account is paid or not
used_space – int, amount of space used (bytes)
system_folders –
SystemFoldersObject
, paths to the system foldersuser –
UserObject
, owner of the diskrevision – int, current revision of Yandex.Disk
- class yadisk_async.objects.disk.SystemFoldersObject(system_folders: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
YaDiskObject
Object, containing paths to system folders.
- Parameters:
system_folders – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
odnoklassniki – str, path to the Odnoklassniki folder
google – str, path to the Google+ folder
instagram – str, path to the Instagram folder
vkontakte – str, path to the VKontakte folder
attach – str, path to the mail attachments folder
mailru – str, path to the My World folder
downloads – str, path to the Downloads folder
applications – str path to the Applications folder
facebook – str, path to the Facebook folder
social – str, path to the social networks folder
messenger – str, path to the Messenger Files folder
calendar – str, path to the Meeting Materials folder
photostream – str, path to the camera folder
screenshots – str, path to the screenshot folder
scans – str, path to the Scans folder
- class yadisk_async.objects.disk.UserObject(user: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
YaDiskObject
User object.
- Parameters:
user – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
country – str, user’s country
login – str, user’s login
display_name – str, user’s display name
uid – str, user’s UID
- class yadisk_async.objects.disk.UserPublicInfoObject(public_user_info: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
UserObject
Public user information object. Inherits from
UserObject
for compatibility.- Parameters:
public_user_info – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
login – str, user’s login
display_name – str, user’s display name
uid – str, user’s UID
- class yadisk_async.objects.resources.CommentIDsObject(comment_ids: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
YaDiskObject
Comment IDs object.
- Parameters:
comment_ids – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
private_resource – str, comment ID for private resources
public_resource – str, comment ID for public resources
- class yadisk_async.objects.resources.EXIFObject(exif: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
YaDiskObject
EXIF metadata object.
- Parameters:
exif – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
date_time –
datetime.datetime
, capture date
- class yadisk_async.objects.resources.FilesResourceListObject(files_resource_list: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
YaDiskObject
Flat list of files.
- Parameters:
files_resource_list – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
items – list, flat list of files (
ResourceObject
)limit – int, maximum number of elements in the list
offset – int, offset from the beginning of the list
- class yadisk_async.objects.resources.LastUploadedResourceListObject(last_uploaded_resources_list: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
YaDiskObject
List of last uploaded resources.
- Parameters:
last_uploaded_resources_list – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
items – list, list of resources (
ResourceObject
)limit – int, maximum number of elements in the list
- class yadisk_async.objects.resources.LinkObject(link: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
YaDiskObject
Link object.
- Parameters:
link – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
href – str, link URL
method – str, HTTP method
templated – bool, tells whether the URL is templated
- class yadisk_async.objects.resources.OperationLinkObject(link: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
LinkObject
Operation link object.
- Parameters:
link – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
href – str, link URL
method – str, HTTP method
templated – bool, tells whether the URL is templated
- async get_status(**kwargs) str [source]
Get operation status.
- Parameters:
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
OperationNotFoundError – requested operation was not found
- Returns:
str
- class yadisk_async.objects.resources.PublicResourceLinkObject(link: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
LinkObject
,ResourceObjectMethodsMixin
Public resource link object.
- Parameters:
link – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
href – str, link URL
method – str, HTTP method
templated – bool, tells whether the URL is templated
public_key – str, public key of the resource
public_url – str, public URL of the resource
- async copy(*args, **kwargs) ResourceLinkObject | OperationLinkObject
Copy resource to dst_path. If the operation is performed asynchronously, returns the link to the operation, otherwise, returns the link to the newly created resource.
This method takes 1 or 2 positional arguments:
copy(dst_path, /, **kwargs)
copy(relative_path, dst_path, /, **kwargs)
- Parameters:
src_path – str or None, source path relative to the resource
dst_path – destination path
overwrite – if True the destination path can be overwritten, otherwise, an error will be raised
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
InsufficientStorageError – cannot complete request due to lack of storage space
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
- async download(*args, **kwargs) ResourceLinkObject
Download the file. This method takes 1 or 2 positional arguments:
download(dst_path_or_file, /, **kwargs)
download(relative_path, dst_path_or_file, /, **kwargs)
If relative_path is empty or None (or not specified) this method will try to use the file attribute as a download link.
- Parameters:
relative_path – str or None, source path relative to the resource
dst_path_or_file – destination path or file-like object
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
ResourceLinkObject
, link to the source resource
- async exists(relative_path: str | None = None, /, **kwargs) bool
Check whether resource exists.
- Parameters:
relative_path – str or None, relative path from the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
bool
- async get_download_link(relative_path: str | None = None, /, **kwargs) str
Get a download link for a file (or a directory).
- Parameters:
relative_path – str or None, path relative to the resource
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
str
- async get_meta(relative_path: str | None = None, /, **kwargs) ResourceObject
Get meta information about a file/directory.
- Parameters:
relative_path – str or None, relative path from resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_public_meta(**kwargs) PublicResourceObject
Get meta-information about a public resource.
- Parameters:
path – relative path to a resource in a public folder.
offset – offset from the beginning of the list of nested resources
limit – maximum number of nested elements to be included in the list
sort – str, field to be used as a key to sort children resources
preview_size – file preview size
preview_crop – bool, allow preview crop
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_type(relative_path: str | None = None, /, **kwargs) str
Get resource type.
- Parameters:
relative_path – relative path from the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
“file” or “dir”
- async get_upload_link(relative_path: str | None = None, /, **kwargs) str
Get a link to upload the file using the PUT request.
- Parameters:
relative_path – str or None, relative path to the resource
overwrite – bool, determines whether to overwrite the destination
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
str
- async is_dir(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a directory.
- Parameters:
relative_path – relative path from the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a directory, False otherwise (even if it doesn’t exist)
- async is_file(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a file.
- Parameters:
relative_path – relative path from the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a file, False otherwise (even if it doesn’t exist)
- async listdir(relative_path: str | None = None, /, **kwargs) AsyncGenerator[ResourceObject, None]
Get contents of the resource.
- Parameters:
relative_path – relative path from resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
ResourceObject
- async mkdir(relative_path: str | None = None, /, **kwargs) ResourceLinkObject
Create a new directory.
- Parameters:
relative_path – str or None, relative path to the directory to be created
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
DirectoryExistsError – destination path already exists
InsufficientStorageError – cannot create directory due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async move(*args, **kwargs) ResourceLinkObject | OperationLinkObject
Move resource to dst_path. This method takes 1 or 2 positional arguments:
move(dst_path, /, **kwargs)
move(relative_path, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, source path to be moved relative to the resource
dst_path – destination path
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async patch(*args, **kwargs) ResourceObject
Update custom properties of a resource. This method takes 1 or 2 positional arguments:
patch(properties, /, **kwargs)
patch(relative_path, properties, /, **kwargs)
- Parameters:
relative_path – str or None, path relative to the resource
properties – dict, custom properties to update
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async public_listdir(**kwargs) AsyncGenerator[PublicResourceObject, None]
Get contents of a public directory.
- Parameters:
path – relative path to the resource in the public folder.
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
PublicResourceObject
- async publish(relative_path: str | None = None, /, **kwargs) ResourceLinkObject
Make a resource public.
- Parameters:
relative_path – str or None, relative path to the resource to be published
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
ResourceLinkObject
, link to the resource
- async remove(relative_path: str | None = None, /, **kwargs) OperationLinkObject | None
Remove the resource.
- Parameters:
relative_path – str or None, relative path to the resource to be removed
permanently – if True, the resource will be removed permanently, otherwise, it will be just moved to the trash
md5 – str, MD5 hash of the file to remove
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
BadRequestError – MD5 check is only available for files
ResourceIsLockedError – resource is locked by another request
- Returns:
OperationLinkObject
if the operation is performed asynchronously, None otherwise
- async rename(*args, **kwargs) ResourceLinkObject | OperationLinkObject
Rename src_path to have filename new_name. Does the same as move() but changes only the filename.
- Parameters:
relative_path – str or None, source path to be renamed relative to the resource
new_name – target filename to rename to
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
ValueError – new_name is not a valid filename
- Returns:
- async unpublish(relative_path: str | None = None, /, **kwargs) ResourceLinkObject
Make a public resource private.
- Parameters:
relative_path – str or None, relative path to the resource to be unpublished
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async upload(path_or_file: str | bytes | IO | AsyncFileLike | Callable[[], AsyncIterable[bytes]], relative_path: str | None = None, /, **kwargs) ResourceLinkObject
Upload a file to disk.
- Parameters:
path_or_file – path, file-like object or an async generator function to be uploaded
relative_path – str or None, destination path relative to the resource
overwrite – if True, the resource will be overwritten if it already exists, an error will be raised otherwise
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
ResourceLinkObject
, link to the destination resource
- async upload_url(url: str, relative_path: str | None = None, /, **kwargs) OperationLinkObject
Upload a file from URL.
- Parameters:
url – source URL
relative_path – str or None, destination path relative to the resource
disable_redirects – bool, forbid redirects
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
InsufficientStorageError – cannot upload file due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
OperationLinkObject
, link to the asynchronous operation
- class yadisk_async.objects.resources.PublicResourceListObject(public_resource_list: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
ResourceListObject
List of public resources.
- Parameters:
public_resource_list – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
sort – str, sort type
items – list, list of resources (
ResourceObject
)limit – int, maximum number of elements in the list
offset – int, offset from the beginning of the list
path – str, path to the directory that contains the elements of the list
total – int, number of elements in the list
public_key – str, public key of the resource
- class yadisk_async.objects.resources.PublicResourceObject(public_resource=None, yadisk=None)[source]
Bases:
ResourceObject
Public resource object.
- Parameters:
resource – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
antivirus_status – str, antivirus check status
file – str, download URL
size – int, file size
public_key – str, public resource key
sha256 – str, SHA256 hash
md5 – str, MD5 hash
embedded –
PublicResourceObject
, list of nested resourcesname – str, filename
exif –
EXIFObject
, EXIF metadataresource_id – str, resource ID
custom_properties – dict, custom resource properties
public_url – str, public URL
share –
ShareInfoObject
, shared folder informationmodified –
datetime.datetime
, date of last modificationcreated –
datetime.datetime
, date of creationphotoslice_time –
datetime.datetime
, photo/video creation datemime_type – str, MIME type
path – str, path to the resource
preview – str, file preview URL
comment_ids –
CommentIDsObject
, comment IDstype – str, type (“file” or “dir”)
media_type – str, file type as determined by Yandex.Disk
revision – int, Yandex.Disk revision at the time of last modification
view_count – int, number of times the public resource was viewed
owner –
UserPublicInfoObject
, owner of the public resource
- async copy(*args, **kwargs) ResourceLinkObject | OperationLinkObject
Copy resource to dst_path. If the operation is performed asynchronously, returns the link to the operation, otherwise, returns the link to the newly created resource.
This method takes 1 or 2 positional arguments:
copy(dst_path, /, **kwargs)
copy(relative_path, dst_path, /, **kwargs)
- Parameters:
src_path – str or None, source path relative to the resource
dst_path – destination path
overwrite – if True the destination path can be overwritten, otherwise, an error will be raised
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
InsufficientStorageError – cannot complete request due to lack of storage space
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
- async download(*args, **kwargs) ResourceLinkObject
Download the file. This method takes 1 or 2 positional arguments:
download(dst_path_or_file, /, **kwargs)
download(relative_path, dst_path_or_file, /, **kwargs)
If relative_path is empty or None (or not specified) this method will try to use the file attribute as a download link.
- Parameters:
relative_path – str or None, source path relative to the resource
dst_path_or_file – destination path or file-like object
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
ResourceLinkObject
, link to the source resource
- async exists(relative_path: str | None = None, /, **kwargs) bool
Check whether resource exists.
- Parameters:
relative_path – str or None, relative path from the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
bool
- async get_download_link(relative_path: str | None = None, /, **kwargs) str
Get a download link for a file (or a directory).
- Parameters:
relative_path – str or None, path relative to the resource
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
str
- async get_meta(relative_path: str | None = None, /, **kwargs) ResourceObject
Get meta information about a file/directory.
- Parameters:
relative_path – str or None, relative path from resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_public_meta(**kwargs) PublicResourceObject
Get meta-information about a public resource.
- Parameters:
path – relative path to a resource in a public folder.
offset – offset from the beginning of the list of nested resources
limit – maximum number of nested elements to be included in the list
sort – str, field to be used as a key to sort children resources
preview_size – file preview size
preview_crop – bool, allow preview crop
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_type(relative_path: str | None = None, /, **kwargs) str
Get resource type.
- Parameters:
relative_path – relative path from the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
“file” or “dir”
- async get_upload_link(relative_path: str | None = None, /, **kwargs) str
Get a link to upload the file using the PUT request.
- Parameters:
relative_path – str or None, relative path to the resource
overwrite – bool, determines whether to overwrite the destination
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
str
- async is_dir(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a directory.
- Parameters:
relative_path – relative path from the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a directory, False otherwise (even if it doesn’t exist)
- async is_file(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a file.
- Parameters:
relative_path – relative path from the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a file, False otherwise (even if it doesn’t exist)
- async listdir(relative_path: str | None = None, /, **kwargs) AsyncGenerator[ResourceObject, None]
Get contents of the resource.
- Parameters:
relative_path – relative path from resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
ResourceObject
- async mkdir(relative_path: str | None = None, /, **kwargs) ResourceLinkObject
Create a new directory.
- Parameters:
relative_path – str or None, relative path to the directory to be created
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
DirectoryExistsError – destination path already exists
InsufficientStorageError – cannot create directory due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async move(*args, **kwargs) ResourceLinkObject | OperationLinkObject
Move resource to dst_path. This method takes 1 or 2 positional arguments:
move(dst_path, /, **kwargs)
move(relative_path, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, source path to be moved relative to the resource
dst_path – destination path
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async patch(*args, **kwargs) ResourceObject
Update custom properties of a resource. This method takes 1 or 2 positional arguments:
patch(properties, /, **kwargs)
patch(relative_path, properties, /, **kwargs)
- Parameters:
relative_path – str or None, path relative to the resource
properties – dict, custom properties to update
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async public_listdir(**kwargs) AsyncGenerator[PublicResourceObject, None]
Get contents of a public directory.
- Parameters:
path – relative path to the resource in the public folder.
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
PublicResourceObject
- async publish(relative_path: str | None = None, /, **kwargs) ResourceLinkObject
Make a resource public.
- Parameters:
relative_path – str or None, relative path to the resource to be published
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
ResourceLinkObject
, link to the resource
- async remove(relative_path: str | None = None, /, **kwargs) OperationLinkObject | None
Remove the resource.
- Parameters:
relative_path – str or None, relative path to the resource to be removed
permanently – if True, the resource will be removed permanently, otherwise, it will be just moved to the trash
md5 – str, MD5 hash of the file to remove
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
BadRequestError – MD5 check is only available for files
ResourceIsLockedError – resource is locked by another request
- Returns:
OperationLinkObject
if the operation is performed asynchronously, None otherwise
- async rename(*args, **kwargs) ResourceLinkObject | OperationLinkObject
Rename src_path to have filename new_name. Does the same as move() but changes only the filename.
- Parameters:
relative_path – str or None, source path to be renamed relative to the resource
new_name – target filename to rename to
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
ValueError – new_name is not a valid filename
- Returns:
- async unpublish(relative_path: str | None = None, /, **kwargs) ResourceLinkObject
Make a public resource private.
- Parameters:
relative_path – str or None, relative path to the resource to be unpublished
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async upload(path_or_file: str | bytes | IO | AsyncFileLike | Callable[[], AsyncIterable[bytes]], relative_path: str | None = None, /, **kwargs) ResourceLinkObject
Upload a file to disk.
- Parameters:
path_or_file – path, file-like object or an async generator function to be uploaded
relative_path – str or None, destination path relative to the resource
overwrite – if True, the resource will be overwritten if it already exists, an error will be raised otherwise
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
ResourceLinkObject
, link to the destination resource
- async upload_url(url: str, relative_path: str | None = None, /, **kwargs) OperationLinkObject
Upload a file from URL.
- Parameters:
url – source URL
relative_path – str or None, destination path relative to the resource
disable_redirects – bool, forbid redirects
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
InsufficientStorageError – cannot upload file due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
OperationLinkObject
, link to the asynchronous operation
- class yadisk_async.objects.resources.PublicResourcesListObject(public_resources_list: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
YaDiskObject
List of public resources.
- Parameters:
public_resources_list – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
items – list, list of public resources (
PublicResourceObject
)type – str, resource type to filter by
limit – int, maximum number of elements in the list
offset – int, offset from the beginning of the list
- class yadisk_async.objects.resources.ResourceDownloadLinkObject(link: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
LinkObject
Resource download link.
- Parameters:
link – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
href – str, link URL
method – str, HTTP method
templated – bool, tells whether the URL is templated
- class yadisk_async.objects.resources.ResourceLinkObject(link: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
LinkObject
,ResourceObjectMethodsMixin
Resource link object.
- Parameters:
link – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
href – str, link URL
method – str, HTTP method
templated – bool, tells whether the URL is templated
path – str, path to the resource
- async copy(*args, **kwargs) ResourceLinkObject | OperationLinkObject
Copy resource to dst_path. If the operation is performed asynchronously, returns the link to the operation, otherwise, returns the link to the newly created resource.
This method takes 1 or 2 positional arguments:
copy(dst_path, /, **kwargs)
copy(relative_path, dst_path, /, **kwargs)
- Parameters:
src_path – str or None, source path relative to the resource
dst_path – destination path
overwrite – if True the destination path can be overwritten, otherwise, an error will be raised
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
InsufficientStorageError – cannot complete request due to lack of storage space
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
- async download(*args, **kwargs) ResourceLinkObject
Download the file. This method takes 1 or 2 positional arguments:
download(dst_path_or_file, /, **kwargs)
download(relative_path, dst_path_or_file, /, **kwargs)
If relative_path is empty or None (or not specified) this method will try to use the file attribute as a download link.
- Parameters:
relative_path – str or None, source path relative to the resource
dst_path_or_file – destination path or file-like object
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
ResourceLinkObject
, link to the source resource
- async exists(relative_path: str | None = None, /, **kwargs) bool
Check whether resource exists.
- Parameters:
relative_path – str or None, relative path from the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
bool
- async get_download_link(relative_path: str | None = None, /, **kwargs) str
Get a download link for a file (or a directory).
- Parameters:
relative_path – str or None, path relative to the resource
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
str
- async get_meta(relative_path: str | None = None, /, **kwargs) ResourceObject
Get meta information about a file/directory.
- Parameters:
relative_path – str or None, relative path from resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_public_meta(**kwargs) PublicResourceObject
Get meta-information about a public resource.
- Parameters:
path – relative path to a resource in a public folder.
offset – offset from the beginning of the list of nested resources
limit – maximum number of nested elements to be included in the list
sort – str, field to be used as a key to sort children resources
preview_size – file preview size
preview_crop – bool, allow preview crop
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_type(relative_path: str | None = None, /, **kwargs) str
Get resource type.
- Parameters:
relative_path – relative path from the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
“file” or “dir”
- async get_upload_link(relative_path: str | None = None, /, **kwargs) str
Get a link to upload the file using the PUT request.
- Parameters:
relative_path – str or None, relative path to the resource
overwrite – bool, determines whether to overwrite the destination
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
str
- async is_dir(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a directory.
- Parameters:
relative_path – relative path from the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a directory, False otherwise (even if it doesn’t exist)
- async is_file(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a file.
- Parameters:
relative_path – relative path from the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a file, False otherwise (even if it doesn’t exist)
- async listdir(relative_path: str | None = None, /, **kwargs) AsyncGenerator[ResourceObject, None]
Get contents of the resource.
- Parameters:
relative_path – relative path from resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
ResourceObject
- async mkdir(relative_path: str | None = None, /, **kwargs) ResourceLinkObject
Create a new directory.
- Parameters:
relative_path – str or None, relative path to the directory to be created
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
DirectoryExistsError – destination path already exists
InsufficientStorageError – cannot create directory due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async move(*args, **kwargs) ResourceLinkObject | OperationLinkObject
Move resource to dst_path. This method takes 1 or 2 positional arguments:
move(dst_path, /, **kwargs)
move(relative_path, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, source path to be moved relative to the resource
dst_path – destination path
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async patch(*args, **kwargs) ResourceObject
Update custom properties of a resource. This method takes 1 or 2 positional arguments:
patch(properties, /, **kwargs)
patch(relative_path, properties, /, **kwargs)
- Parameters:
relative_path – str or None, path relative to the resource
properties – dict, custom properties to update
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async public_listdir(**kwargs) AsyncGenerator[PublicResourceObject, None]
Get contents of a public directory.
- Parameters:
path – relative path to the resource in the public folder.
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
PublicResourceObject
- async publish(relative_path: str | None = None, /, **kwargs) ResourceLinkObject
Make a resource public.
- Parameters:
relative_path – str or None, relative path to the resource to be published
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
ResourceLinkObject
, link to the resource
- async remove(relative_path: str | None = None, /, **kwargs) OperationLinkObject | None
Remove the resource.
- Parameters:
relative_path – str or None, relative path to the resource to be removed
permanently – if True, the resource will be removed permanently, otherwise, it will be just moved to the trash
md5 – str, MD5 hash of the file to remove
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
BadRequestError – MD5 check is only available for files
ResourceIsLockedError – resource is locked by another request
- Returns:
OperationLinkObject
if the operation is performed asynchronously, None otherwise
- async rename(*args, **kwargs) ResourceLinkObject | OperationLinkObject
Rename src_path to have filename new_name. Does the same as move() but changes only the filename.
- Parameters:
relative_path – str or None, source path to be renamed relative to the resource
new_name – target filename to rename to
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
ValueError – new_name is not a valid filename
- Returns:
- async unpublish(relative_path: str | None = None, /, **kwargs) ResourceLinkObject
Make a public resource private.
- Parameters:
relative_path – str or None, relative path to the resource to be unpublished
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async upload(path_or_file: str | bytes | IO | AsyncFileLike | Callable[[], AsyncIterable[bytes]], relative_path: str | None = None, /, **kwargs) ResourceLinkObject
Upload a file to disk.
- Parameters:
path_or_file – path, file-like object or an async generator function to be uploaded
relative_path – str or None, destination path relative to the resource
overwrite – if True, the resource will be overwritten if it already exists, an error will be raised otherwise
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
ResourceLinkObject
, link to the destination resource
- async upload_url(url: str, relative_path: str | None = None, /, **kwargs) OperationLinkObject
Upload a file from URL.
- Parameters:
url – source URL
relative_path – str or None, destination path relative to the resource
disable_redirects – bool, forbid redirects
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
InsufficientStorageError – cannot upload file due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
OperationLinkObject
, link to the asynchronous operation
- class yadisk_async.objects.resources.ResourceListObject(resource_list: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
YaDiskObject
List of resources.
- Parameters:
resource_list – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
sort – str, sort type
items – list, list of resources (
ResourceObject
)limit – int, maximum number of elements in the list
offset – int, offset from the beginning of the list
path – str, path to the directory that contains the elements of the list
total – int, number of elements in the list
- class yadisk_async.objects.resources.ResourceObject(resource: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
YaDiskObject
,ResourceObjectMethodsMixin
Resource object.
- Parameters:
resource – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
antivirus_status – str, antivirus check status
file – str, download URL
size – int, file size
public_key – str, public resource key
sha256 – str, SHA256 hash
md5 – str, MD5 hash
embedded –
ResourceListObject
, list of nested resourcesname – str, filename
exif –
EXIFObject
, EXIF metadataresource_id – str, resource ID
custom_properties – dict, custom resource properties
public_url – str, public URL
share –
ShareInfoObject
, shared folder informationmodified –
datetime.datetime
, date of last modificationcreated –
datetime.datetime
, date of creationphotoslice_time –
datetime.datetime
, photo/video creation datemime_type – str, MIME type
path – str, path to the resource
preview – str, file preview URL
comment_ids –
CommentIDsObject
, comment IDstype – str, type (“file” or “dir”)
media_type – str, file type as determined by Yandex.Disk
revision – int, Yandex.Disk revision at the time of last modification
- async copy(*args, **kwargs) ResourceLinkObject | OperationLinkObject
Copy resource to dst_path. If the operation is performed asynchronously, returns the link to the operation, otherwise, returns the link to the newly created resource.
This method takes 1 or 2 positional arguments:
copy(dst_path, /, **kwargs)
copy(relative_path, dst_path, /, **kwargs)
- Parameters:
src_path – str or None, source path relative to the resource
dst_path – destination path
overwrite – if True the destination path can be overwritten, otherwise, an error will be raised
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
InsufficientStorageError – cannot complete request due to lack of storage space
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
- async download(*args, **kwargs) ResourceLinkObject
Download the file. This method takes 1 or 2 positional arguments:
download(dst_path_or_file, /, **kwargs)
download(relative_path, dst_path_or_file, /, **kwargs)
If relative_path is empty or None (or not specified) this method will try to use the file attribute as a download link.
- Parameters:
relative_path – str or None, source path relative to the resource
dst_path_or_file – destination path or file-like object
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
ResourceLinkObject
, link to the source resource
- async exists(relative_path: str | None = None, /, **kwargs) bool
Check whether resource exists.
- Parameters:
relative_path – str or None, relative path from the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
bool
- async get_download_link(relative_path: str | None = None, /, **kwargs) str
Get a download link for a file (or a directory).
- Parameters:
relative_path – str or None, path relative to the resource
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
str
- async get_meta(relative_path: str | None = None, /, **kwargs) ResourceObject
Get meta information about a file/directory.
- Parameters:
relative_path – str or None, relative path from resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_public_meta(**kwargs) PublicResourceObject
Get meta-information about a public resource.
- Parameters:
path – relative path to a resource in a public folder.
offset – offset from the beginning of the list of nested resources
limit – maximum number of nested elements to be included in the list
sort – str, field to be used as a key to sort children resources
preview_size – file preview size
preview_crop – bool, allow preview crop
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_type(relative_path: str | None = None, /, **kwargs) str
Get resource type.
- Parameters:
relative_path – relative path from the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
“file” or “dir”
- async get_upload_link(relative_path: str | None = None, /, **kwargs) str
Get a link to upload the file using the PUT request.
- Parameters:
relative_path – str or None, relative path to the resource
overwrite – bool, determines whether to overwrite the destination
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
str
- async is_dir(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a directory.
- Parameters:
relative_path – relative path from the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a directory, False otherwise (even if it doesn’t exist)
- async is_file(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a file.
- Parameters:
relative_path – relative path from the resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a file, False otherwise (even if it doesn’t exist)
- async listdir(relative_path: str | None = None, /, **kwargs) AsyncGenerator[ResourceObject, None]
Get contents of the resource.
- Parameters:
relative_path – relative path from resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
ResourceObject
- async mkdir(relative_path: str | None = None, /, **kwargs) ResourceLinkObject
Create a new directory.
- Parameters:
relative_path – str or None, relative path to the directory to be created
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
DirectoryExistsError – destination path already exists
InsufficientStorageError – cannot create directory due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async move(*args, **kwargs) ResourceLinkObject | OperationLinkObject
Move resource to dst_path. This method takes 1 or 2 positional arguments:
move(dst_path, /, **kwargs)
move(relative_path, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, source path to be moved relative to the resource
dst_path – destination path
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async patch(*args, **kwargs) ResourceObject
Update custom properties of a resource. This method takes 1 or 2 positional arguments:
patch(properties, /, **kwargs)
patch(relative_path, properties, /, **kwargs)
- Parameters:
relative_path – str or None, path relative to the resource
properties – dict, custom properties to update
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async public_listdir(**kwargs) AsyncGenerator[PublicResourceObject, None]
Get contents of a public directory.
- Parameters:
path – relative path to the resource in the public folder.
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
PublicResourceObject
- async publish(relative_path: str | None = None, /, **kwargs) ResourceLinkObject
Make a resource public.
- Parameters:
relative_path – str or None, relative path to the resource to be published
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
ResourceLinkObject
, link to the resource
- async remove(relative_path: str | None = None, /, **kwargs) OperationLinkObject | None
Remove the resource.
- Parameters:
relative_path – str or None, relative path to the resource to be removed
permanently – if True, the resource will be removed permanently, otherwise, it will be just moved to the trash
md5 – str, MD5 hash of the file to remove
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
BadRequestError – MD5 check is only available for files
ResourceIsLockedError – resource is locked by another request
- Returns:
OperationLinkObject
if the operation is performed asynchronously, None otherwise
- async rename(*args, **kwargs) ResourceLinkObject | OperationLinkObject
Rename src_path to have filename new_name. Does the same as move() but changes only the filename.
- Parameters:
relative_path – str or None, source path to be renamed relative to the resource
new_name – target filename to rename to
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
ValueError – new_name is not a valid filename
- Returns:
- async unpublish(relative_path: str | None = None, /, **kwargs) ResourceLinkObject
Make a public resource private.
- Parameters:
relative_path – str or None, relative path to the resource to be unpublished
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async upload(path_or_file: str | bytes | IO | AsyncFileLike | Callable[[], AsyncIterable[bytes]], relative_path: str | None = None, /, **kwargs) ResourceLinkObject
Upload a file to disk.
- Parameters:
path_or_file – path, file-like object or an async generator function to be uploaded
relative_path – str or None, destination path relative to the resource
overwrite – if True, the resource will be overwritten if it already exists, an error will be raised otherwise
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
ResourceLinkObject
, link to the destination resource
- async upload_url(url: str, relative_path: str | None = None, /, **kwargs) OperationLinkObject
Upload a file from URL.
- Parameters:
url – source URL
relative_path – str or None, destination path relative to the resource
disable_redirects – bool, forbid redirects
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
InsufficientStorageError – cannot upload file due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
OperationLinkObject
, link to the asynchronous operation
- class yadisk_async.objects.resources.ResourceUploadLinkObject(resource_upload_link: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
LinkObject
Resource upload link.
- Parameters:
resource_upload_link – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
operation_id – str, ID of the upload operation
href – str, link URL
method – str, HTTP method
templated – bool, tells whether the URL is templated
Bases:
YaDiskObject
Shared folder information object.
- Parameters:
share_info – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
is_root – bool, tells whether the folder is root
is_owned – bool, tells whether the user is the owner of this directory
rights – str, access rights
- class yadisk_async.objects.resources.TrashResourceListObject(trash_resource_list: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
ResourceListObject
List of trash resources.
- Parameters:
trash_resource_list – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
sort – str, sort type
items – list, list of resources (
TrashResourceObject
)limit – int, maximum number of elements in the list
offset – int, offset from the beginning of the list
path – str, path to the directory that contains the elements of the list
total – int, number of elements in the list
- class yadisk_async.objects.resources.TrashResourceObject(trash_resource: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
ResourceObject
Trash resource object.
- Parameters:
trash_resource – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
antivirus_status – str, antivirus check status
file – str, download URL
size – int, file size
public_key – str, public resource key
sha256 – str, SHA256 hash
md5 – str, MD5 hash
embedded –
TrashResourceListObject
, list of nested resourcesname – str, filename
exif –
EXIFObject
, EXIF metadataresource_id – str, resource ID
custom_properties – dict, custom resource properties
public_url – str, public URL
share –
ShareInfoObject
, shared folder informationmodified –
datetime.datetime
, date of last modificationcreated –
datetime.datetime
, date of creationphotoslice_time –
datetime.datetime
, photo/video creation datemime_type – str, MIME type
path – str, path to the resource
preview – str, file preview URL
comment_ids –
CommentIDsObject
, comment IDstype – str, type (“file” or “dir”)
media_type – str, file type as determined by Yandex.Disk
revision – int, Yandex.Disk revision at the time of last modification
origin_path – str, original path
deleted –
datetime.datetime
, date of deletion
- async exists(relative_path: str | None = None, /, **kwargs) bool [source]
Check whether the trash resource exists.
- Parameters:
relative_path – str or None, relative path to the trash resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
bool
- async get_meta(relative_path: str | None = None, /, **kwargs) TrashResourceObject [source]
Get meta information about a trash resource.
- Parameters:
relative_path – str or None, relative path to the trash resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_type(relative_path: str | None = None, /, **kwargs) str [source]
Get trash resource type.
- Parameters:
relative_path – str or None, relative path to the trash resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
“file” or “dir”
- async is_dir(relative_path: str | None = None, /, **kwargs) bool [source]
Check whether resource is a trash directory.
- Parameters:
relative_path – str or None, relative path to the trash resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a directory, False otherwise (even if it doesn’t exist)
- async is_file(relative_path: str | None = None, /, **kwargs) bool [source]
Check whether resource is a trash file.
- Parameters:
relative_path – str or None, relative path to the trash resource
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a file, False otherwise (even if it doesn’t exist)
- async listdir(relative_path: str | None = None, /, **kwargs) AsyncGenerator[TrashResourceObject, None] [source]
Get contents of a trash resource.
- Parameters:
relative_path – str or None, relative path to the directory in the trash bin
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
TrashResourceObject
- async patch(*args, **kwargs)[source]
Update custom properties of a resource. This method takes 1 or 2 positional arguments:
patch(properties, /, **kwargs)
patch(relative_path, properties, /, **kwargs)
- Parameters:
relative_path – str or None, path relative to the resource
properties – dict, custom properties to update
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async remove(relative_path: str | None = None, /, **kwargs) OperationLinkObject | None [source]
Remove a trash resource.
- Parameters:
relative_path – str or None, relative path to the trash resource to be deleted
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
OperationLinkObject
if the operation is performed asynchronously, None otherwise
- async restore(dst_path: str, /, **kwargs) ResourceLinkObject | OperationLinkObject [source]
- async restore(relative_path: str | None, dst_path: str, /, **kwargs) ResourceLinkObject | OperationLinkObject
Restore a trash resource. Returns a link to the newly created resource or a link to the asynchronous operation.
This method takes 1 or 2 positional arguments:
restore(dst_path, /, **kwargs)
restore(relative_path=None, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, relative path to the trash resource to be restored
dst_path – destination path
overwrite – bool, determines whether the destination can be overwritten
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- class yadisk_async.objects.operations.OperationStatusObject(operation_status: dict | None = None, yadisk: YaDisk | None = None)[source]
Bases:
YaDiskObject
Operation status object.
- Parameters:
operation_status – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
type – str, type of the operation
status – str, status of the operation
operation_id – str, ID of the operation
link –
LinkObject
, link to the operationdata – dict, other information about the operation
Low-level API
Utilities
- async yadisk_async.utils.auto_retry(func: Callable[[], T | Awaitable[T]], n_retries: int | None = None, retry_interval: int | float | None = None) T [source]
Attempt to perform a request with automatic retries. A retry is triggered by
aiohttp.ClientError
orRetriableYaDiskError
.- Parameters:
func – function to run, must not require any arguments
n_retries – int, maximum number of retries
retry_interval – int or float, delay between retries (in seconds)
- Returns:
return value of func()
- async yadisk_async.utils.get_exception(response: ClientResponse) YaDiskError [source]
Get an exception instance based on response, assuming the request has failed.
- Parameters:
response – an instance of
aiohttp.ClientResponse
- Returns:
an exception instance, subclass of
YaDiskError
API request objects
- class yadisk_async.api.APIRequest(session: ClientSession, args: dict, **kwargs)[source]
Base class for all API requests.
- Parameters:
session – an instance of
aiohttp.ClientSession
args – dict of arguments, that will be passed to process_args
timeout – float or
aiohttp.ClientTimeout
, request timeoutheaders – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
kwargs – other arguments for
aiohttp.ClientSession.request
- Variables:
url – str, request URL
method – str, request method
content_type – str, Content-Type header (“application/x-www-form-urlencoded” by default)
timeout – float or
aiohttp.ClientTimeout
, request timeoutn_retries – int, maximum number of retries
success_codes – list-like, list of response codes that indicate request’s success
retry_interval – float, delay between retries in seconds
- process_json(js: dict | None, **kwargs) T [source]
Process the JSON response.
- Parameters:
js – dict, JSON response
kwargs – extra arguments (optional)
- Returns:
processed response, can be anything
- async send() ClientResponse [source]
Actually send the request
- Returns:
aiohttp.ClientResponse
(self.response)
- class yadisk_async.api.auth.GetTokenRequest(session: aiohttp.ClientSession, code: str, client_id: str, client_secret: str, device_id: str | None = None, device_name: str | None = None, **kwargs)[source]
Bases:
APIRequest
A request to get the token.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headerscode – confirmation code
client_id – application ID
client_secret – application secret password
device_id – unique device ID (between 6 and 50 characters)
- Returns:
- process_json(js: dict | None) TokenObject [source]
Process the JSON response.
- Parameters:
js – dict, JSON response
kwargs – extra arguments (optional)
- Returns:
processed response, can be anything
- class yadisk_async.api.auth.RefreshTokenRequest(session: aiohttp.ClientSession, refresh_token: str, client_id: str, client_secret: str, **kwargs)[source]
Bases:
APIRequest
A request to refresh an existing token.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headersrefresh_token – the refresh token that was received with the original token
client_id – application ID
client_secret – application secret password
- Returns:
- process_json(js: dict | None) TokenObject [source]
Process the JSON response.
- Parameters:
js – dict, JSON response
kwargs – extra arguments (optional)
- Returns:
processed response, can be anything
- class yadisk_async.api.auth.RevokeTokenRequest(session: aiohttp.ClientSession, token: str, client_id: str, client_secret: str, **kwargs)[source]
Bases:
APIRequest
A request to revoke the token.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headerstoken – the token to be revoked
client_id – application ID
client_secret – application secret password
- Returns:
- process_json(js: dict | None) TokenRevokeStatusObject [source]
Process the JSON response.
- Parameters:
js – dict, JSON response
kwargs – extra arguments (optional)
- Returns:
processed response, can be anything
- class yadisk_async.api.disk.DiskInfoRequest(session: aiohttp.ClientSession, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to get disk information.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headersfields – list of keys to be included in the response
- Returns:
- process_json(js: dict | None) DiskInfoObject [source]
Process the JSON response.
- Parameters:
js – dict, JSON response
kwargs – extra arguments (optional)
- Returns:
processed response, can be anything
- class yadisk_async.api.resources.CopyRequest(session: aiohttp.ClientSession, src_path: str, dst_path: str, overwrite: bool = False, force_async: bool = False, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to copy a file or a directory.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headerssrc_path – source path
dst_path – destination path
overwrite – if True the destination path can be overwritten, otherwise, an error will be raised
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
- Returns:
- process_json(js: dict | None, yadisk: YaDisk | None = None) OperationLinkObject | ResourceLinkObject [source]
Process the JSON response.
- Parameters:
js – dict, JSON response
kwargs – extra arguments (optional)
- Returns:
processed response, can be anything
- class yadisk_async.api.resources.DeleteRequest(session: aiohttp.ClientSession, path: str, permanently: bool = False, md5: str | None = None, force_async: bool = False, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to delete a file or a directory.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headerspath – path to the resource to be removed
permanently – if True, the resource will be removed permanently, otherwise, it will be just moved to the trash
force_async – forces the operation to be executed asynchronously
md5 – str, MD5 hash of the file to remove
fields – list of keys to be included in the response
- Returns:
OperationLinkObject
or None
- class yadisk_async.api.resources.DeleteTrashRequest(session: aiohttp.ClientSession, path: str | None = None, force_async: bool = False, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to delete a trash resource.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headerspath – path to the trash resource to be deleted
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
- Returns:
OperationLinkObject
or None
- class yadisk_async.api.resources.FilesRequest(session: aiohttp.ClientSession, offset: int = 0, limit: int = 20, media_type: str | Iterable[str] | None = None, preview_size: str | None = None, preview_crop: bool | None = None, sort: str | None = None, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to get a flat list of all files (that doesn’t include directories).
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headersoffset – offset from the beginning of the list
limit – number of list elements to be included
media_type – type of files to include in the list
sort – str, field to be used as a key to sort children resources
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
- Returns:
- class yadisk_async.api.resources.GetDownloadLinkRequest(session: aiohttp.ClientSession, path: str, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to get a download link to a resource.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headerspath – path to the resource to be downloaded
fields – list of keys to be included in the response
- Returns:
- class yadisk_async.api.resources.GetMetaRequest(session: aiohttp.ClientSession, path: str, limit: int | None = None, offset: int | None = None, preview_size: str | None = None, preview_crop: bool | None = None, sort: str | None = None, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to get meta-information about a resource.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headerspath – path to the resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
- Returns:
- class yadisk_async.api.resources.GetPublicDownloadLinkRequest(session: aiohttp.ClientSession, public_key: str, path: str | None = None, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to get a download link for a public resource.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headerspublic_key – public key or public URL of the resource
path – relative path to the resource within the public folder
fields – list of keys to be included in the response
- Returns:
- class yadisk_async.api.resources.GetPublicMetaRequest(session: aiohttp.ClientSession, public_key: str, offset: int = 0, limit: int = 20, path: str | None = None, sort: str | None = None, preview_size: str | None = None, preview_crop: bool | None = None, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to get meta-information about a public resource.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headerspublic_key – public key or public URL of the resource
path – relative path to a resource in a public folder. By specifying the key of the published folder in public_key, you can request metainformation for any resource in the folder.
offset – offset from the beginning of the list of nested resources
limit – maximum number of nested elements to be included in the list
sort – str, field to be used as a key to sort children resources
preview_size – file preview size
preview_crop – bool, allow preview crop
fields – list of keys to be included in the response
- Returns:
- class yadisk_async.api.resources.GetPublicResourcesRequest(session: aiohttp.ClientSession, offset: int = 0, limit: int = 20, preview_size: str | None = None, preview_crop: bool | None = None, type: str | None = None, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to get a list of public resources.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headersoffset – offset from the beginning of the list
limit – maximum number of elements in the list
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
type – filter based on type of resources (“file” or “dir”)
fields – list of keys to be included in the response
- Returns:
- class yadisk_async.api.resources.GetTrashRequest(session: aiohttp.ClientSession, path: str, offset: int = 0, limit: int = 20, sort: str | None = None, preview_size: str | None = None, preview_crop: bool | None = None, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to get meta-information about a trash resource.
- Parameters:
path – path to the trash resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
- Returns:
- class yadisk_async.api.resources.GetUploadLinkRequest(session: aiohttp.ClientSession, path: str, overwrite: bool = False, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to get an upload link.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headerspath – path to be uploaded at
overwrite – bool, determines whether to overwrite the destination
fields – list of keys to be included in the response
- Returns:
- class yadisk_async.api.resources.LastUploadedRequest(session: aiohttp.ClientSession, limit: int = 20, media_type: str | Iterable[str] | None = None, preview_size: str | None = None, preview_crop: bool | None = None, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to get the list of latest uploaded files sorted by upload date.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headerslimit – maximum number of elements in the list
media_type – type of files to include in the list
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
- Returns:
- class yadisk_async.api.resources.MkdirRequest(session: aiohttp.ClientSession, path: str, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to create a new directory.
- Parameters:
path – path to the directory to be created
fields – list of keys to be included in the response
- Returns:
- class yadisk_async.api.resources.MoveRequest(session: aiohttp.ClientSession, src_path: str, dst_path: str, force_async: bool = False, overwrite: bool = False, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to move a resource.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headerssrc_path – source path to be moved
dst_path – destination path
force_async – forces the operation to be executed asynchronously
overwrite – bool, determines whether to overwrite the destination
fields – list of keys to be included in the response
- Returns:
- process_json(js: dict | None, yadisk: YaDisk | None = None) OperationLinkObject | ResourceLinkObject [source]
Process the JSON response.
- Parameters:
js – dict, JSON response
kwargs – extra arguments (optional)
- Returns:
processed response, can be anything
- class yadisk_async.api.resources.PatchRequest(session: aiohttp.ClientSession, path: str, properties: dict, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to update custom properties of a resource.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headerspath – path to the resource
properties – dict, custom properties to update
fields – list of keys to be included in the response
- Returns:
- class yadisk_async.api.resources.PublishRequest(session: aiohttp.ClientSession, path: str, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to make a resource public.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headerspath – path to the resource to be published
fields – list of keys to be included in the response
- Returns:
- class yadisk_async.api.resources.RestoreTrashRequest(session: aiohttp.ClientSession, path: str, dst_path: str | None = None, force_async: bool = False, overwrite: bool = False, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to restore trash.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headerspath – path to the trash resource to be restored
dst_path – destination path
force_async – forces the operation to be executed asynchronously
overwrite – bool, determines whether the destination can be overwritten
fields – list of keys to be included in the response
- Returns:
- process_json(js: dict | None, yadisk: YaDisk | None = None) OperationLinkObject | ResourceLinkObject [source]
Process the JSON response.
- Parameters:
js – dict, JSON response
kwargs – extra arguments (optional)
- Returns:
processed response, can be anything
- class yadisk_async.api.resources.SaveToDiskRequest(session: aiohttp.ClientSession, public_key: str, name: str | None = None, path: str | None = None, save_path: str | None = None, force_async: bool = False, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to save a public resource to the disk.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headerspublic_key – public key or public URL of the resource
name – filename of the saved resource
path – path to the copied resource in the public folder
save_path – path to the destination directory (downloads directory by default)
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
- Returns:
- process_json(js: dict | None, yadisk: YaDisk | None = None) OperationLinkObject | ResourceLinkObject [source]
Process the JSON response.
- Parameters:
js – dict, JSON response
kwargs – extra arguments (optional)
- Returns:
processed response, can be anything
- class yadisk_async.api.resources.UnpublishRequest(session: aiohttp.ClientSession, path: str, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to make a public resource private.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headerspath – path to the resource to be unpublished
fields – list of keys to be included in the response
- Returns:
- class yadisk_async.api.resources.UploadURLRequest(session: aiohttp.ClientSession, url: str, path: str, disable_redirects: bool = False, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to upload a file from URL.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headersurl – source URL
path – destination path
disable_redirects – bool, forbid redirects
fields – list of keys to be included in the response
- Returns:
- class yadisk_async.api.operations.GetOperationStatusRequest(session: aiohttp.ClientSession, operation_id: str, fields: Iterable[str] | None = None, **kwargs)[source]
Bases:
APIRequest
A request to get operation status.
- Parameters:
session – an instance of
aiohttp.ClientSession
with prepared headersoperation_id – operation ID or link
fields – list of keys to be included in the response
- Returns:
- process_json(js: dict | None) OperationStatusObject [source]
Process the JSON response.
- Parameters:
js – dict, JSON response
kwargs – extra arguments (optional)
- Returns:
processed response, can be anything