Response Objects

class yadisk.objects.YaDiskObject(field_types: dict | None = None, yadisk: Any | 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_typesdict or None

  • yadiskYaDisk 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_dictdict or None (nothing will be done in that case)

remove_alias(alias: str) None[source]

Remove an alias.

Parameters:

aliasstr

remove_field(field: str) None[source]

Remove field.

Parameters:

fieldstr

set_alias(alias: str, name: str) None[source]

Set an alias.

Parameters:
  • aliasstr, alias to add

  • namestr, field name

set_field_type(field: str, type: Callable) None[source]

Set field type.

Parameters:
  • fieldstr

  • type – type or factory

set_field_types(field_types: dict) None[source]

Set the field types of the object

Parameters:

field_typesdict, where keys are the field names and values are types (or factories)

class yadisk.objects.ErrorObject(error=None, yadisk=None)[source]

Bases: YaDiskObject

Mirrors Yandex.Disk REST API error object.

Parameters:
  • errordict or None

  • yadiskYaDisk or None, YaDisk object

Variables:
  • messagestr, human-readable error message

  • descriptionstr, technical error description

  • errorstr, error code

class yadisk.objects.auth.DeviceCodeObject(device_code_object: dict | None = None, yadisk: Any | None = None)[source]

Bases: YaDiskObject

Result of Client.get_device_code() / AsyncClient.get_device_code().

Parameters:
  • device_code_objectdict or None

  • yadiskYaDisk or None, YaDisk object

Variables:
  • device_codestr, device code that can be used for obtaining the token

  • user_codestr, code that the user should enter on the OAuth page

  • verification_urlstr, URL of the OAuth page where user is expected to enter the user_code

  • intervalint, the minimum interval (in seconds) with which the app must request an OAuth token. If requests come more often, Yandex OAuth may respond with an error

  • expires_inint, amount of time before the codes expire

class yadisk.objects.auth.TokenObject(token: dict | None = None, yadisk: Any | None = None)[source]

Bases: YaDiskObject

Token object.

Parameters:
  • tokendict or None

  • yadiskYaDisk or None, YaDisk object

Variables:
  • access_tokenstr, token string

  • refresh_tokenstr, the refresh-token

  • token_typestr, type of the token

  • expires_inint, amount of time before the token expires

  • scopestr, list of rights requested by the application, returned only if the token has a smaller set of rights than requested

class yadisk.objects.auth.TokenRevokeStatusObject(token_revoke_status: dict | None = None, yadisk: Any | None = None)[source]

Bases: YaDiskObject

Result of token revocation request.

Parameters:
  • token_revoke_statusdict or None

  • yadiskYaDisk or None, YaDisk object

Variables:

statusstr, status of the operation

class yadisk.objects.disk.DiskInfoObject(disk_info: dict | None = None, yadisk: Any | None = None)[source]

Bases: YaDiskObject

Disk information object.

Parameters:
  • disk_infodict or None

  • yadiskYaDisk or None, YaDisk object

Variables:
  • max_file_sizeint, maximum supported file size (bytes)

  • paid_max_file_sizeint, maximum supported file size for a paid account (bytes)

  • unlimited_autoupload_enabledbool, tells whether unlimited autoupload from mobile devices is enabled

  • total_spaceint, total disk size (bytes)

  • trash_sizeint, amount of space used by trash (bytes), part of used_space

  • is_paidbool, tells if the account is paid or not

  • used_spaceint, amount of space used (bytes)

  • system_foldersSystemFoldersObject, paths to the system folders

  • userUserObject, owner of the disk

  • revisionint, current revision of Yandex.Disk

class yadisk.objects.disk.SystemFoldersObject(system_folders: dict | None = None, yadisk: Any | None = None)[source]

Bases: YaDiskObject

Object, containing paths to system folders.

Parameters:
  • system_foldersdict or None

  • yadiskYaDisk or None, YaDisk object

Variables:
  • odnoklassnikistr, path to the Odnoklassniki folder

  • googlestr, path to the Google+ folder

  • instagramstr, path to the Instagram folder

  • vkontaktestr, path to the VKontakte folder

  • attachstr, path to the mail attachments folder

  • mailrustr, path to the My World folder

  • downloadsstr, path to the Downloads folder

  • applicationsstr path to the Applications folder

  • facebookstr, path to the Facebook folder

  • socialstr, path to the social networks folder

  • messengerstr, path to the Messenger Files folder

  • calendarstr, path to the Meeting Materials folder

  • photostreamstr, path to the camera folder

  • screenshotsstr, path to the screenshot folder

  • scansstr, path to the Scans folder

class yadisk.objects.disk.UserObject(user: dict | None = None, yadisk: Any | None = None)[source]

Bases: YaDiskObject

User object.

Parameters:
  • userdict or None

  • yadiskYaDisk or None, YaDisk object

Variables:
  • countrystr, user’s country

  • loginstr, user’s login

  • display_namestr, user’s display name

  • uidstr, user’s UID

class yadisk.objects.disk.UserPublicInfoObject(public_user_info: dict | None = None, yadisk: Any | None = None)[source]

Bases: UserObject

Public user information object. Inherits from UserObject for compatibility.

Parameters:
  • public_user_infodict or None

  • yadiskYaDisk or None, YaDisk object

Variables:
  • loginstr, user’s login

  • display_namestr, user’s display name

  • uidstr, user’s UID

class yadisk.objects.resources.AsyncFilesResourceListObject(files_resource_list: dict | None = None, yadisk: Any | None = None)[source]

Bases: FilesResourceListObject

Flat list of files.

Parameters:
  • files_resource_listdict or None

  • yadiskAsyncClient or None, YaDisk object

Variables:
  • itemslist, flat list of files (AsyncResourceObject)

  • limitint, maximum number of elements in the list

  • offsetint, offset from the beginning of the list

class yadisk.objects.resources.AsyncLastUploadedResourceListObject(last_uploaded_resources_list: dict | None = None, yadisk: Any | None = None)[source]

Bases: LastUploadedResourceListObject

List of last uploaded resources.

Parameters:
  • last_uploaded_resources_listdict or None

  • yadiskAsyncClient or None, YaDisk object

Variables:
  • itemslist, list of resources (AsyncResourceObject)

  • limitint, maximum number of elements in the list

class yadisk.objects.resources.AsyncPublicResourceLinkObject(link: dict | None = None, yadisk: Any | None = None)[source]

Bases: PublicResourceLinkObject, AsyncResourceObjectMethodsMixin

Public resource link object.

Parameters:
  • linkdict or None

  • yadiskAsyncClient or None, YaDisk object

Variables:
  • hrefstr, link URL

  • methodstr, HTTP method

  • templatedbool, tells whether the URL is templated

  • public_keystr, public key of the resource

  • public_urlstr, public URL of the resource

async copy(*args, **kwargs) AsyncResourceLinkObject | AsyncOperationLinkObject

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:

  1. copy(dst_path, /, **kwargs)

  2. copy(relative_path, dst_path, /, **kwargs)

Parameters:
  • relative_pathstr 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject or AsyncOperationLinkObject

async download(*args, **kwargs) AsyncResourceLinkObject

Download the file. This method takes 1 or 2 positional arguments:

  1. download(dst_path_or_file, /, **kwargs)

  2. 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_pathstr or None, source path relative to the resource

  • dst_path_or_file – destination path or file-like object

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject, link to the source resource

async exists(relative_path: str | None = None, /, **kwargs) bool

Check whether resource exists.

Parameters:
  • relative_pathstr or None, relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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 a download link for a file (or a directory).

Parameters:
  • relative_pathstr or None, path relative to the resource

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

str

async get_meta(relative_path: str | None = None, /, **kwargs) AsyncResourceObject

Get meta information about a file/directory.

Parameters:
  • relative_pathstr 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_cropbool, cut the preview to the size specified in the preview_size

  • sortstr, field to be used as a key to sort children resources

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceObject

async get_public_meta(**kwargs) AsyncPublicResourceObject

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

  • sortstr, field to be used as a key to sort children resources

  • preview_size – file preview size

  • preview_cropbool, allow preview crop

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncPublicResourceObject

async get_type(relative_path: str | None = None, /, **kwargs) str

Get resource type.

Parameters:
  • relative_path – relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

“file” or “dir”

Get a link to upload the file using the PUT request.

Parameters:
  • relative_pathstr or None, relative path to the resource

  • overwritebool, determines whether to overwrite the destination

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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[AsyncResourceObject, 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_cropbool, cut the preview to the size specified in the preview_size

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

generator of AsyncResourceObject

async mkdir(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject

Create a new directory.

Parameters:
  • relative_pathstr or None, relative path to the directory to be created

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject

async move(*args, **kwargs) AsyncResourceLinkObject | AsyncOperationLinkObject

Move resource to dst_path. This method takes 1 or 2 positional arguments:

  1. move(dst_path, /, **kwargs)

  2. move(relative_path, dst_path, /, **kwargs)

Parameters:
  • relative_pathstr or None, source path to be moved relative to the resource

  • dst_path – destination path

  • overwritebool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject or AsyncOperationLinkObject

async patch(*args, **kwargs) AsyncResourceObject

Update custom properties of a resource. This method takes 1 or 2 positional arguments:

  1. patch(properties, /, **kwargs)

  2. patch(relative_path, properties, /, **kwargs)

Parameters:
  • relative_pathstr or None, path relative to the resource

  • propertiesdict, custom properties to update

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceObject

async public_listdir(**kwargs) AsyncGenerator[AsyncPublicResourceObject, 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_cropbool, cut the preview to the size specified in the preview_size

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

generator of AsyncPublicResourceObject

async publish(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject

Make a resource public.

Parameters:
  • relative_pathstr or None, relative path to the resource to be published

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject, link to the resource

async remove(relative_path: str | None = None, /, **kwargs) AsyncOperationLinkObject | None

Remove the resource.

Parameters:
  • relative_pathstr 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

  • md5str, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncOperationLinkObject if the operation is performed asynchronously, None otherwise

async rename(*args, **kwargs) AsyncResourceLinkObject | AsyncOperationLinkObject

Rename src_path to have filename new_name. Does the same as move() but changes only the filename.

Parameters:
  • relative_pathstr or None, source path to be renamed relative to the resource

  • new_name – target filename to rename to

  • overwritebool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject or AsyncOperationLinkObject

async unpublish(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject

Make a public resource private.

Parameters:
  • relative_pathstr or None, relative path to the resource to be unpublished

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

ResourceLinkObject

async upload(path_or_file: str | IO, relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject

Upload a file to disk.

Parameters:
  • path_or_file – path or file-like object to be uploaded

  • relative_pathstr 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject, link to the destination resource

async upload_url(url: str, relative_path: str | None = None, /, **kwargs) AsyncOperationLinkObject

Upload a file from URL.

Parameters:
  • url – source URL

  • relative_pathstr or None, destination path relative to the resource

  • disable_redirectsbool, forbid redirects

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncOperationLinkObject, link to the asynchronous operation

class yadisk.objects.resources.AsyncPublicResourceListObject(public_resource_list: dict | None = None, yadisk: Any | None = None)[source]

Bases: PublicResourceListObject

List of public resources.

Parameters:
  • public_resource_listdict or None

  • yadiskAsyncClient or None, YaDisk object

Variables:
  • sortstr, sort type

  • itemslist, list of resources (AsyncResourceObject)

  • limitint, maximum number of elements in the list

  • offsetint, offset from the beginning of the list

  • pathstr, path to the directory that contains the elements of the list

  • totalint, number of elements in the list

  • public_keystr, public key of the resource

class yadisk.objects.resources.AsyncPublicResourceObject(public_resource: dict | None = None, yadisk: Any | None = None)[source]

Bases: PublicResourceObject, AsyncResourceObjectMethodsMixin

Public resource object.

Parameters:
  • resourcedict or None

  • yadiskAsyncClient or None, YaDisk object

Variables:
  • antivirus_statusstr, antivirus check status

  • filestr, download URL

  • sizeint, file size

  • public_keystr, public resource key

  • sha256str, SHA256 hash

  • md5str, MD5 hash

  • embeddedAsyncPublicResourceObject, list of nested resources

  • namestr, filename

  • exifEXIFObject, EXIF metadata

  • resource_idstr, resource ID

  • custom_propertiesdict, custom resource properties

  • public_urlstr, public URL

  • shareShareInfoObject, shared folder information

  • modifieddatetime.datetime, date of last modification

  • createddatetime.datetime, date of creation

  • photoslice_timedatetime.datetime, photo/video creation date

  • mime_typestr, MIME type

  • pathstr, path to the resource

  • previewstr, file preview URL

  • comment_idsCommentIDsObject, comment IDs

  • typestr, type (“file” or “dir”)

  • media_typestr, file type as determined by Yandex.Disk

  • revisionint, Yandex.Disk revision at the time of last modification

  • view_countint, number of times the public resource was viewed

  • ownerUserPublicInfoObject, owner of the public resource

async copy(*args, **kwargs) AsyncResourceLinkObject | AsyncOperationLinkObject

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:

  1. copy(dst_path, /, **kwargs)

  2. copy(relative_path, dst_path, /, **kwargs)

Parameters:
  • relative_pathstr 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject or AsyncOperationLinkObject

async download(*args, **kwargs) AsyncResourceLinkObject

Download the file. This method takes 1 or 2 positional arguments:

  1. download(dst_path_or_file, /, **kwargs)

  2. 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_pathstr or None, source path relative to the resource

  • dst_path_or_file – destination path or file-like object

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject, link to the source resource

async exists(relative_path: str | None = None, /, **kwargs) bool

Check whether resource exists.

Parameters:
  • relative_pathstr or None, relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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 a download link for a file (or a directory).

Parameters:
  • relative_pathstr or None, path relative to the resource

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

str

async get_meta(relative_path: str | None = None, /, **kwargs) AsyncResourceObject

Get meta information about a file/directory.

Parameters:
  • relative_pathstr 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_cropbool, cut the preview to the size specified in the preview_size

  • sortstr, field to be used as a key to sort children resources

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceObject

async get_public_meta(**kwargs) AsyncPublicResourceObject

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

  • sortstr, field to be used as a key to sort children resources

  • preview_size – file preview size

  • preview_cropbool, allow preview crop

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncPublicResourceObject

async get_type(relative_path: str | None = None, /, **kwargs) str

Get resource type.

Parameters:
  • relative_path – relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

“file” or “dir”

Get a link to upload the file using the PUT request.

Parameters:
  • relative_pathstr or None, relative path to the resource

  • overwritebool, determines whether to overwrite the destination

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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[AsyncResourceObject, 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_cropbool, cut the preview to the size specified in the preview_size

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

generator of AsyncResourceObject

async mkdir(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject

Create a new directory.

Parameters:
  • relative_pathstr or None, relative path to the directory to be created

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject

async move(*args, **kwargs) AsyncResourceLinkObject | AsyncOperationLinkObject

Move resource to dst_path. This method takes 1 or 2 positional arguments:

  1. move(dst_path, /, **kwargs)

  2. move(relative_path, dst_path, /, **kwargs)

Parameters:
  • relative_pathstr or None, source path to be moved relative to the resource

  • dst_path – destination path

  • overwritebool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject or AsyncOperationLinkObject

async patch(*args, **kwargs) AsyncResourceObject

Update custom properties of a resource. This method takes 1 or 2 positional arguments:

  1. patch(properties, /, **kwargs)

  2. patch(relative_path, properties, /, **kwargs)

Parameters:
  • relative_pathstr or None, path relative to the resource

  • propertiesdict, custom properties to update

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceObject

async public_listdir(**kwargs) AsyncGenerator[AsyncPublicResourceObject, 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_cropbool, cut the preview to the size specified in the preview_size

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

generator of AsyncPublicResourceObject

async publish(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject

Make a resource public.

Parameters:
  • relative_pathstr or None, relative path to the resource to be published

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject, link to the resource

async remove(relative_path: str | None = None, /, **kwargs) AsyncOperationLinkObject | None

Remove the resource.

Parameters:
  • relative_pathstr 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

  • md5str, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncOperationLinkObject if the operation is performed asynchronously, None otherwise

async rename(*args, **kwargs) AsyncResourceLinkObject | AsyncOperationLinkObject

Rename src_path to have filename new_name. Does the same as move() but changes only the filename.

Parameters:
  • relative_pathstr or None, source path to be renamed relative to the resource

  • new_name – target filename to rename to

  • overwritebool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject or AsyncOperationLinkObject

async unpublish(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject

Make a public resource private.

Parameters:
  • relative_pathstr or None, relative path to the resource to be unpublished

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

ResourceLinkObject

async upload(path_or_file: str | IO, relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject

Upload a file to disk.

Parameters:
  • path_or_file – path or file-like object to be uploaded

  • relative_pathstr 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject, link to the destination resource

async upload_url(url: str, relative_path: str | None = None, /, **kwargs) AsyncOperationLinkObject

Upload a file from URL.

Parameters:
  • url – source URL

  • relative_pathstr or None, destination path relative to the resource

  • disable_redirectsbool, forbid redirects

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncOperationLinkObject, link to the asynchronous operation

class yadisk.objects.resources.AsyncPublicResourcesListObject(public_resources_list: dict | None = None, yadisk: Any | None = None)[source]

Bases: PublicResourcesListObject

List of public resources.

Parameters:
  • public_resources_listdict or None

  • yadiskAsyncClient or None, YaDisk object

Variables:
  • itemslist, list of public resources (AsyncPublicResourceObject)

  • typestr, resource type to filter by

  • limitint, maximum number of elements in the list

  • offsetint, offset from the beginning of the list

class yadisk.objects.resources.AsyncResourceLinkObject(link: dict | None = None, yadisk: Any | None = None)[source]

Bases: ResourceLinkObject, AsyncResourceObjectMethodsMixin

Resource link object.

Parameters:
  • linkdict or None

  • yadiskAsyncClient or None, YaDisk object

Variables:
  • hrefstr, link URL

  • methodstr, HTTP method

  • templatedbool, tells whether the URL is templated

  • pathstr, path to the resource

async copy(*args, **kwargs) AsyncResourceLinkObject | AsyncOperationLinkObject

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:

  1. copy(dst_path, /, **kwargs)

  2. copy(relative_path, dst_path, /, **kwargs)

Parameters:
  • relative_pathstr 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject or AsyncOperationLinkObject

async download(*args, **kwargs) AsyncResourceLinkObject

Download the file. This method takes 1 or 2 positional arguments:

  1. download(dst_path_or_file, /, **kwargs)

  2. 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_pathstr or None, source path relative to the resource

  • dst_path_or_file – destination path or file-like object

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject, link to the source resource

async exists(relative_path: str | None = None, /, **kwargs) bool

Check whether resource exists.

Parameters:
  • relative_pathstr or None, relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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 a download link for a file (or a directory).

Parameters:
  • relative_pathstr or None, path relative to the resource

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

str

async get_meta(relative_path: str | None = None, /, **kwargs) AsyncResourceObject

Get meta information about a file/directory.

Parameters:
  • relative_pathstr 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_cropbool, cut the preview to the size specified in the preview_size

  • sortstr, field to be used as a key to sort children resources

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceObject

async get_public_meta(**kwargs) AsyncPublicResourceObject

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

  • sortstr, field to be used as a key to sort children resources

  • preview_size – file preview size

  • preview_cropbool, allow preview crop

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncPublicResourceObject

async get_type(relative_path: str | None = None, /, **kwargs) str

Get resource type.

Parameters:
  • relative_path – relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

“file” or “dir”

Get a link to upload the file using the PUT request.

Parameters:
  • relative_pathstr or None, relative path to the resource

  • overwritebool, determines whether to overwrite the destination

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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[AsyncResourceObject, 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_cropbool, cut the preview to the size specified in the preview_size

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

generator of AsyncResourceObject

async mkdir(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject

Create a new directory.

Parameters:
  • relative_pathstr or None, relative path to the directory to be created

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject

async move(*args, **kwargs) AsyncResourceLinkObject | AsyncOperationLinkObject

Move resource to dst_path. This method takes 1 or 2 positional arguments:

  1. move(dst_path, /, **kwargs)

  2. move(relative_path, dst_path, /, **kwargs)

Parameters:
  • relative_pathstr or None, source path to be moved relative to the resource

  • dst_path – destination path

  • overwritebool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject or AsyncOperationLinkObject

async patch(*args, **kwargs) AsyncResourceObject

Update custom properties of a resource. This method takes 1 or 2 positional arguments:

  1. patch(properties, /, **kwargs)

  2. patch(relative_path, properties, /, **kwargs)

Parameters:
  • relative_pathstr or None, path relative to the resource

  • propertiesdict, custom properties to update

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceObject

async public_listdir(**kwargs) AsyncGenerator[AsyncPublicResourceObject, 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_cropbool, cut the preview to the size specified in the preview_size

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

generator of AsyncPublicResourceObject

async publish(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject

Make a resource public.

Parameters:
  • relative_pathstr or None, relative path to the resource to be published

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject, link to the resource

async remove(relative_path: str | None = None, /, **kwargs) AsyncOperationLinkObject | None

Remove the resource.

Parameters:
  • relative_pathstr 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

  • md5str, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncOperationLinkObject if the operation is performed asynchronously, None otherwise

async rename(*args, **kwargs) AsyncResourceLinkObject | AsyncOperationLinkObject

Rename src_path to have filename new_name. Does the same as move() but changes only the filename.

Parameters:
  • relative_pathstr or None, source path to be renamed relative to the resource

  • new_name – target filename to rename to

  • overwritebool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject or AsyncOperationLinkObject

async unpublish(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject

Make a public resource private.

Parameters:
  • relative_pathstr or None, relative path to the resource to be unpublished

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

ResourceLinkObject

async upload(path_or_file: str | IO, relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject

Upload a file to disk.

Parameters:
  • path_or_file – path or file-like object to be uploaded

  • relative_pathstr 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject, link to the destination resource

async upload_url(url: str, relative_path: str | None = None, /, **kwargs) AsyncOperationLinkObject

Upload a file from URL.

Parameters:
  • url – source URL

  • relative_pathstr or None, destination path relative to the resource

  • disable_redirectsbool, forbid redirects

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncOperationLinkObject, link to the asynchronous operation

class yadisk.objects.resources.AsyncResourceListObject(resource_list: dict | None = None, yadisk: Any | None = None)[source]

Bases: ResourceListObject

List of resources.

Parameters:
  • resource_listdict or None

  • yadiskAsyncClient or None, YaDisk object

Variables:
  • sortstr, sort type

  • itemslist, list of resources (AsyncResourceObject)

  • limitint, maximum number of elements in the list

  • offsetint, offset from the beginning of the list

  • pathstr, path to the directory that contains the elements of the list

  • totalint, number of elements in the list

class yadisk.objects.resources.AsyncResourceObject(resource: dict | None = None, yadisk: Any | None = None)[source]

Bases: ResourceObject, AsyncResourceObjectMethodsMixin

Resource object.

Parameters:
  • resourcedict or None

  • yadiskAsyncClient or None, YaDisk object

Variables:
  • antivirus_statusstr, antivirus check status

  • filestr, download URL

  • sizeint, file size

  • public_keystr, public resource key

  • sha256str, SHA256 hash

  • md5str, MD5 hash

  • embeddedAsyncResourceListObject, list of nested resources

  • namestr, filename

  • exifEXIFObject, EXIF metadata

  • resource_idstr, resource ID

  • custom_propertiesdict, custom resource properties

  • public_urlstr, public URL

  • shareShareInfoObject, shared folder information

  • modifieddatetime.datetime, date of last modification

  • createddatetime.datetime, date of creation

  • photoslice_timedatetime.datetime, photo/video creation date

  • mime_typestr, MIME type

  • pathstr, path to the resource

  • previewstr, file preview URL

  • comment_idsCommentIDsObject, comment IDs

  • typestr, type (“file” or “dir”)

  • media_typestr, file type as determined by Yandex.Disk

  • revisionint, Yandex.Disk revision at the time of last modification

async copy(*args, **kwargs) AsyncResourceLinkObject | AsyncOperationLinkObject

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:

  1. copy(dst_path, /, **kwargs)

  2. copy(relative_path, dst_path, /, **kwargs)

Parameters:
  • relative_pathstr 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject or AsyncOperationLinkObject

async download(*args, **kwargs) AsyncResourceLinkObject

Download the file. This method takes 1 or 2 positional arguments:

  1. download(dst_path_or_file, /, **kwargs)

  2. 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_pathstr or None, source path relative to the resource

  • dst_path_or_file – destination path or file-like object

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject, link to the source resource

async exists(relative_path: str | None = None, /, **kwargs) bool

Check whether resource exists.

Parameters:
  • relative_pathstr or None, relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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 a download link for a file (or a directory).

Parameters:
  • relative_pathstr or None, path relative to the resource

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

str

async get_meta(relative_path: str | None = None, /, **kwargs) AsyncResourceObject

Get meta information about a file/directory.

Parameters:
  • relative_pathstr 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_cropbool, cut the preview to the size specified in the preview_size

  • sortstr, field to be used as a key to sort children resources

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceObject

async get_public_meta(**kwargs) AsyncPublicResourceObject

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

  • sortstr, field to be used as a key to sort children resources

  • preview_size – file preview size

  • preview_cropbool, allow preview crop

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncPublicResourceObject

async get_type(relative_path: str | None = None, /, **kwargs) str

Get resource type.

Parameters:
  • relative_path – relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

“file” or “dir”

Get a link to upload the file using the PUT request.

Parameters:
  • relative_pathstr or None, relative path to the resource

  • overwritebool, determines whether to overwrite the destination

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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[AsyncResourceObject, 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_cropbool, cut the preview to the size specified in the preview_size

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

generator of AsyncResourceObject

async mkdir(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject

Create a new directory.

Parameters:
  • relative_pathstr or None, relative path to the directory to be created

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject

async move(*args, **kwargs) AsyncResourceLinkObject | AsyncOperationLinkObject

Move resource to dst_path. This method takes 1 or 2 positional arguments:

  1. move(dst_path, /, **kwargs)

  2. move(relative_path, dst_path, /, **kwargs)

Parameters:
  • relative_pathstr or None, source path to be moved relative to the resource

  • dst_path – destination path

  • overwritebool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject or AsyncOperationLinkObject

async patch(*args, **kwargs) AsyncResourceObject

Update custom properties of a resource. This method takes 1 or 2 positional arguments:

  1. patch(properties, /, **kwargs)

  2. patch(relative_path, properties, /, **kwargs)

Parameters:
  • relative_pathstr or None, path relative to the resource

  • propertiesdict, custom properties to update

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceObject

async public_listdir(**kwargs) AsyncGenerator[AsyncPublicResourceObject, 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_cropbool, cut the preview to the size specified in the preview_size

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

generator of AsyncPublicResourceObject

async publish(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject

Make a resource public.

Parameters:
  • relative_pathstr or None, relative path to the resource to be published

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject, link to the resource

async remove(relative_path: str | None = None, /, **kwargs) AsyncOperationLinkObject | None

Remove the resource.

Parameters:
  • relative_pathstr 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

  • md5str, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncOperationLinkObject if the operation is performed asynchronously, None otherwise

async rename(*args, **kwargs) AsyncResourceLinkObject | AsyncOperationLinkObject

Rename src_path to have filename new_name. Does the same as move() but changes only the filename.

Parameters:
  • relative_pathstr or None, source path to be renamed relative to the resource

  • new_name – target filename to rename to

  • overwritebool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject or AsyncOperationLinkObject

async unpublish(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject

Make a public resource private.

Parameters:
  • relative_pathstr or None, relative path to the resource to be unpublished

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

ResourceLinkObject

async upload(path_or_file: str | IO, relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject

Upload a file to disk.

Parameters:
  • path_or_file – path or file-like object to be uploaded

  • relative_pathstr 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject, link to the destination resource

async upload_url(url: str, relative_path: str | None = None, /, **kwargs) AsyncOperationLinkObject

Upload a file from URL.

Parameters:
  • url – source URL

  • relative_pathstr or None, destination path relative to the resource

  • disable_redirectsbool, forbid redirects

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncOperationLinkObject, link to the asynchronous operation

class yadisk.objects.resources.AsyncTrashResourceListObject(trash_resource_list: dict | None = None, yadisk: Any | None = None)[source]

Bases: TrashResourceListObject

List of trash resources.

Parameters:
  • trash_resource_listdict or None

  • yadiskAsyncClient or None, YaDisk object

Variables:
  • sortstr, sort type

  • itemslist, list of resources (AsyncTrashResourceObject)

  • limitint, maximum number of elements in the list

  • offsetint, offset from the beginning of the list

  • pathstr, path to the directory that contains the elements of the list

  • totalint, number of elements in the list

class yadisk.objects.resources.AsyncTrashResourceObject(trash_resource: dict | None = None, yadisk: Any | None = None)[source]

Bases: TrashResourceObject

Trash resource object.

Parameters:
  • trash_resourcedict or None

  • yadiskAsyncClient or None, YaDisk object

Variables:
  • antivirus_statusstr, antivirus check status

  • filestr, download URL

  • sizeint, file size

  • public_keystr, public resource key

  • sha256str, SHA256 hash

  • md5str, MD5 hash

  • embeddedAsyncTrashResourceListObject, list of nested resources

  • namestr, filename

  • exifEXIFObject, EXIF metadata

  • resource_idstr, resource ID

  • custom_propertiesdict, custom resource properties

  • public_urlstr, public URL

  • shareShareInfoObject, shared folder information

  • modifieddatetime.datetime, date of last modification

  • createddatetime.datetime, date of creation

  • photoslice_timedatetime.datetime, photo/video creation date

  • mime_typestr, MIME type

  • pathstr, path to the resource

  • previewstr, file preview URL

  • comment_idsCommentIDsObject, comment IDs

  • typestr, type (“file” or “dir”)

  • media_typestr, file type as determined by Yandex.Disk

  • revisionint, Yandex.Disk revision at the time of last modification

  • origin_pathstr, original path

  • deleteddatetime.datetime, date of deletion

async exists(relative_path: str | None = None, /, **kwargs) bool[source]

Check whether the trash resource exists.

Parameters:
  • relative_pathstr or None, relative path to the trash resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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) AsyncTrashResourceObject[source]

Get meta information about a trash resource.

Parameters:
  • relative_pathstr 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_cropbool, cut the preview to the size specified in the preview_size

  • sortstr, field to be used as a key to sort children resources

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncTrashResourceObject

async get_type(relative_path: str | None = None, /, **kwargs) str[source]

Get trash resource type.

Parameters:
  • relative_pathstr or None, relative path to the trash resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

“file” or “dir”

async is_dir(relative_path: str | None = None, /, **kwargs) bool[source]

Check whether resource is a trash directory.

Parameters:
  • relative_pathstr or None, relative path to the trash resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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_pathstr or None, relative path to the trash resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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) Generator[AsyncTrashResourceObject, None, None][source]

Get contents of a trash resource.

Parameters:
  • relative_pathstr 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_cropbool, cut the preview to the size specified in the preview_size

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

generator of AsyncTrashResourceObject

async remove(relative_path: str | None = None, /, **kwargs) AsyncOperationLinkObject | None[source]

Remove a trash resource.

Parameters:
  • relative_pathstr 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncOperationLinkObject if the operation is performed asynchronously, None otherwise

async restore(dst_path: str, /, **kwargs) AsyncResourceLinkObject | 'AsyncOperationLinkObject'[source]
async restore(relative_path: str | None, dst_path: str, /, **kwargs) AsyncResourceLinkObject | 'AsyncOperationLinkObject'

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:

  1. restore(dst_path, /, **kwargs)

  2. restore(relative_path=None, dst_path, /, **kwargs)

Parameters:
  • relative_pathstr or None, relative path to the trash resource to be restored

  • dst_path – destination path

  • overwritebool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

AsyncResourceLinkObject or AsyncOperationLinkObject

class yadisk.objects.resources.CommentIDsObject(comment_ids: dict | None = None, yadisk: Any | None = None)[source]

Bases: YaDiskObject

Comment IDs object.

Parameters:
Variables:
  • private_resourcestr, comment ID for private resources

  • public_resourcestr, comment ID for public resources

class yadisk.objects.resources.EXIFObject(exif: dict | None = None, yadisk: Any | None = None)[source]

Bases: YaDiskObject

EXIF metadata object.

Parameters:
Variables:

date_timedatetime.datetime, capture date

class yadisk.objects.resources.FilesResourceListObject(files_resource_list: dict | None = None, yadisk: Any | None = None)[source]

Bases: YaDiskObject

Flat list of files.

Parameters:
  • files_resource_listdict or None

  • yadiskClient/AsyncClient or None, YaDisk object

Variables:
  • itemslist, flat list of files (ResourceObject)

  • limitint, maximum number of elements in the list

  • offsetint, offset from the beginning of the list

class yadisk.objects.resources.LastUploadedResourceListObject(last_uploaded_resources_list: dict | None = None, yadisk: Any | None = None)[source]

Bases: YaDiskObject

List of last uploaded resources.

Parameters:
  • last_uploaded_resources_listdict or None

  • yadiskClient/AsyncClient or None, YaDisk object

Variables:
  • itemslist, list of resources (ResourceObject)

  • limitint, maximum number of elements in the list

class yadisk.objects.resources.PublicResourceLinkObject(link: dict | None = None, yadisk: Any | None = None)[source]

Bases: LinkObject

Public resource link object.

Parameters:
Variables:
  • hrefstr, link URL

  • methodstr, HTTP method

  • templatedbool, tells whether the URL is templated

  • public_keystr, public key of the resource

  • public_urlstr, public URL of the resource

class yadisk.objects.resources.PublicResourceListObject(public_resource_list: dict | None = None, yadisk: Any | None = None)[source]

Bases: ResourceListObject

List of public resources.

Parameters:
  • public_resource_listdict or None

  • yadiskClient/AsyncClient or None, YaDisk object

Variables:
  • sortstr, sort type

  • itemslist, list of resources (ResourceObject)

  • limitint, maximum number of elements in the list

  • offsetint, offset from the beginning of the list

  • pathstr, path to the directory that contains the elements of the list

  • totalint, number of elements in the list

  • public_keystr, public key of the resource

class yadisk.objects.resources.PublicResourceObject(public_resource=None, yadisk=None)[source]

Bases: ResourceObject

Public resource object.

Parameters:
Variables:
  • antivirus_statusstr, antivirus check status

  • filestr, download URL

  • sizeint, file size

  • public_keystr, public resource key

  • sha256str, SHA256 hash

  • md5str, MD5 hash

  • embeddedPublicResourceObject, list of nested resources

  • namestr, filename

  • exifEXIFObject, EXIF metadata

  • resource_idstr, resource ID

  • custom_propertiesdict, custom resource properties

  • public_urlstr, public URL

  • shareShareInfoObject, shared folder information

  • modifieddatetime.datetime, date of last modification

  • createddatetime.datetime, date of creation

  • photoslice_timedatetime.datetime, photo/video creation date

  • mime_typestr, MIME type

  • pathstr, path to the resource

  • previewstr, file preview URL

  • comment_idsCommentIDsObject, comment IDs

  • typestr, type (“file” or “dir”)

  • media_typestr, file type as determined by Yandex.Disk

  • revisionint, Yandex.Disk revision at the time of last modification

  • view_countint, number of times the public resource was viewed

  • ownerUserPublicInfoObject, owner of the public resource

class yadisk.objects.resources.PublicResourcesListObject(public_resources_list: dict | None = None, yadisk: Any | None = None)[source]

Bases: YaDiskObject

List of public resources.

Parameters:
  • public_resources_listdict or None

  • yadiskClient/AsyncClient or None, YaDisk object

Variables:
  • itemslist, list of public resources (PublicResourceObject)

  • typestr, resource type to filter by

  • limitint, maximum number of elements in the list

  • offsetint, offset from the beginning of the list

class yadisk.objects.resources.ResourceDownloadLinkObject(link: dict | None = None, yadisk: Any | None = None)[source]

Bases: LinkObject

Resource download link.

Parameters:
Variables:
  • hrefstr, link URL

  • methodstr, HTTP method

  • templatedbool, tells whether the URL is templated

class yadisk.objects.resources.ResourceLinkObject(link: dict | None = None, yadisk: Any | None = None)[source]

Bases: LinkObject

Resource link object.

Parameters:
Variables:
  • hrefstr, link URL

  • methodstr, HTTP method

  • templatedbool, tells whether the URL is templated

  • pathstr, path to the resource

class yadisk.objects.resources.ResourceListObject(resource_list: dict | None = None, yadisk: Any | None = None)[source]

Bases: YaDiskObject

List of resources.

Parameters:
  • resource_listdict or None

  • yadiskClient/AsyncClient or None, YaDisk object

Variables:
  • sortstr, sort type

  • itemslist, list of resources (ResourceObject)

  • limitint, maximum number of elements in the list

  • offsetint, offset from the beginning of the list

  • pathstr, path to the directory that contains the elements of the list

  • totalint, number of elements in the list

class yadisk.objects.resources.ResourceObject(resource: dict | None = None, yadisk: Any | None = None)[source]

Bases: YaDiskObject

Resource object.

Parameters:
Variables:
  • antivirus_statusstr, antivirus check status

  • filestr, download URL

  • sizeint, file size

  • public_keystr, public resource key

  • sha256str, SHA256 hash

  • md5str, MD5 hash

  • embeddedResourceListObject, list of nested resources

  • namestr, filename

  • exifEXIFObject, EXIF metadata

  • resource_idstr, resource ID

  • custom_propertiesdict, custom resource properties

  • public_urlstr, public URL

  • shareShareInfoObject, shared folder information

  • modifieddatetime.datetime, date of last modification

  • createddatetime.datetime, date of creation

  • photoslice_timedatetime.datetime, photo/video creation date

  • mime_typestr, MIME type

  • pathstr, path to the resource

  • previewstr, file preview URL

  • comment_idsCommentIDsObject, comment IDs

  • typestr, type (“file” or “dir”)

  • media_typestr, file type as determined by Yandex.Disk

  • revisionint, Yandex.Disk revision at the time of last modification

class yadisk.objects.resources.ResourceUploadLinkObject(resource_upload_link: dict | None = None, yadisk: Any | None = None)[source]

Bases: LinkObject

Resource upload link.

Parameters:
  • resource_upload_linkdict or None

  • yadiskClient/AsyncClient or None, YaDisk object

Variables:
  • operation_idstr, ID of the upload operation

  • hrefstr, link URL

  • methodstr, HTTP method

  • templatedbool, tells whether the URL is templated

class yadisk.objects.resources.ShareInfoObject(share_info: dict | None = None, yadisk: Any | None = None)[source]

Bases: YaDiskObject

Shared folder information object.

Parameters:
Variables:
  • is_rootbool, tells whether the folder is root

  • is_ownedbool, tells whether the user is the owner of this directory

  • rightsstr, access rights

class yadisk.objects.resources.SyncFilesResourceListObject(files_resource_list: dict | None = None, yadisk: Any | None = None)[source]

Bases: FilesResourceListObject

Flat list of files.

Parameters:
  • files_resource_listdict or None

  • yadiskClient or None, YaDisk object

Variables:
  • itemslist, flat list of files (SyncResourceObject)

  • limitint, maximum number of elements in the list

  • offsetint, offset from the beginning of the list

class yadisk.objects.resources.SyncLastUploadedResourceListObject(last_uploaded_resources_list: dict | None = None, yadisk: Any | None = None)[source]

Bases: LastUploadedResourceListObject

List of last uploaded resources.

Parameters:
  • last_uploaded_resources_listdict or None

  • yadiskClient or None, YaDisk object

Variables:
  • itemslist, list of resources (SyncResourceObject)

  • limitint, maximum number of elements in the list

class yadisk.objects.resources.SyncPublicResourceLinkObject(link: dict | None = None, yadisk: Any | None = None)[source]

Bases: PublicResourceLinkObject, ResourceObjectMethodsMixin

Public resource link object.

Parameters:
  • linkdict or None

  • yadiskClient or None, YaDisk object

Variables:
  • hrefstr, link URL

  • methodstr, HTTP method

  • templatedbool, tells whether the URL is templated

  • public_keystr, public key of the resource

  • public_urlstr, public URL of the resource

copy(*args, **kwargs) SyncResourceLinkObject | SyncOperationLinkObject

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:

  1. copy(dst_path, /, **kwargs)

  2. copy(relative_src_path, dst_path, /, **kwargs)

Parameters:
  • relative_src_pathstr 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject or SyncOperationLinkObject

download(*args, **kwargs) SyncResourceLinkObject

Download the file. This method takes 1 or 2 positional arguments:

  1. download(dst_path_or_file, /, **kwargs)

  2. 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_pathstr or None, source path relative to the resource

  • dst_path_or_file – destination path or file-like object

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject, link to the source resource

exists(relative_path: str | None = None, /, **kwargs) bool

Check whether resource exists.

Parameters:
  • relative_pathstr or None, relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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 a download link for a file (or a directory).

Parameters:
  • relative_pathstr or None, path relative to the resource

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

str

get_meta(relative_path: str | None = None, /, **kwargs) SyncResourceObject

Get meta information about a file/directory.

Parameters:
  • relative_pathstr 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_cropbool, cut the preview to the size specified in the preview_size

  • sortstr, field to be used as a key to sort children resources

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceObject

get_public_meta(**kwargs) SyncPublicResourceObject

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

  • sortstr, field to be used as a key to sort children resources

  • preview_size – file preview size

  • preview_cropbool, allow preview crop

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncPublicResourceObject

get_type(relative_path: str | None = None, /, **kwargs) str

Get resource type.

Parameters:
  • relative_path – relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

“file” or “dir”

Get a link to upload the file using the PUT request.

Parameters:
  • relative_pathstr or None, relative path to the resource

  • overwritebool, determines whether to overwrite the destination

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

str

is_dir(relative_path: str | None = None, /, **kwargs) bool

Check whether resource is a directory.

Parameters:
  • relative_path – relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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)

is_file(relative_path: str | None = None, /, **kwargs) bool

Check whether resource is a file.

Parameters:
  • relative_path – relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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)

listdir(relative_path: str | None = None, /, **kwargs) Generator[SyncResourceObject, None, 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_cropbool, cut the preview to the size specified in the preview_size

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

generator of SyncResourceObject

mkdir(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject

Create a new directory.

Parameters:
  • relative_pathstr or None, relative path to the directory to be created

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject

move(*args, **kwargs) SyncResourceLinkObject | SyncOperationLinkObject

Move resource to dst_path. This method takes 1 or 2 positional arguments:

  1. move(dst_path, /, **kwargs)

  2. move(relative_path, dst_path, /, **kwargs)

Parameters:
  • relative_pathstr or None, source path to be moved relative to the resource

  • dst_path – destination path

  • overwritebool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject or SyncOperationLinkObject

patch(*args, **kwargs) SyncResourceObject

Update custom properties of a resource. This method takes 1 or 2 positional arguments:

  1. patch(properties, /, **kwargs)

  2. patch(relative_path, properties, /, **kwargs)

Parameters:
  • relative_pathstr or None, path relative to the resource

  • propertiesdict, custom properties to update

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceObject

public_listdir(**kwargs) Generator[SyncPublicResourceObject, None, 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_cropbool, cut the preview to the size specified in the preview_size

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

generator of SyncPublicResourceObject

publish(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject

Make a resource public.

Parameters:
  • relative_pathstr or None, relative path to the resource to be published

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject, link to the resource

remove(relative_path: str | None = None, /, **kwargs) SyncOperationLinkObject | None

Remove the resource.

Parameters:
  • relative_pathstr 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

  • md5str, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncOperationLinkObject if the operation is performed asynchronously, None otherwise

rename(*args, **kwargs) SyncResourceLinkObject | SyncOperationLinkObject

Rename src_path to have filename new_name. Does the same as move() but changes only the filename.

Parameters:
  • relative_pathstr or None, source path to be renamed relative to the resource

  • new_name – target filename to rename to

  • overwritebool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject or SyncOperationLinkObject

unpublish(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject

Make a public resource private.

Parameters:
  • relative_pathstr or None, relative path to the resource to be unpublished

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject

upload(path_or_file: str | IO, relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject

Upload a file to disk.

Parameters:
  • path_or_file – path or file-like object to be uploaded

  • relative_pathstr 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject, link to the destination resource

upload_url(url: str, relative_path: str | None = None, /, **kwargs) OperationLinkObject

Upload a file from URL.

Parameters:
  • url – source URL

  • relative_pathstr or None, destination path relative to the resource

  • disable_redirectsbool, forbid redirects

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncOperationLinkObject, link to the asynchronous operation

class yadisk.objects.resources.SyncPublicResourceListObject(public_resource_list: dict | None = None, yadisk: Any | None = None)[source]

Bases: PublicResourceListObject

List of public resources.

Parameters:
  • public_resource_listdict or None

  • yadiskClient or None, YaDisk object

Variables:
  • sortstr, sort type

  • itemslist, list of resources (SyncResourceObject)

  • limitint, maximum number of elements in the list

  • offsetint, offset from the beginning of the list

  • pathstr, path to the directory that contains the elements of the list

  • totalint, number of elements in the list

  • public_keystr, public key of the resource

class yadisk.objects.resources.SyncPublicResourceObject(public_resource: dict | None = None, yadisk: Any | None = None)[source]

Bases: PublicResourceObject, ResourceObjectMethodsMixin

Public resource object.

Parameters:
  • resourcedict or None

  • yadiskClient or None, YaDisk object

Variables:
  • antivirus_statusstr, antivirus check status

  • filestr, download URL

  • sizeint, file size

  • public_keystr, public resource key

  • sha256str, SHA256 hash

  • md5str, MD5 hash

  • embeddedSyncPublicResourceObject, list of nested resources

  • namestr, filename

  • exifEXIFObject, EXIF metadata

  • resource_idstr, resource ID

  • custom_propertiesdict, custom resource properties

  • public_urlstr, public URL

  • shareShareInfoObject, shared folder information

  • modifieddatetime.datetime, date of last modification

  • createddatetime.datetime, date of creation

  • photoslice_timedatetime.datetime, photo/video creation date

  • mime_typestr, MIME type

  • pathstr, path to the resource

  • previewstr, file preview URL

  • comment_idsCommentIDsObject, comment IDs

  • typestr, type (“file” or “dir”)

  • media_typestr, file type as determined by Yandex.Disk

  • revisionint, Yandex.Disk revision at the time of last modification

  • view_countint, number of times the public resource was viewed

  • ownerUserPublicInfoObject, owner of the public resource

copy(*args, **kwargs) SyncResourceLinkObject | SyncOperationLinkObject

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:

  1. copy(dst_path, /, **kwargs)

  2. copy(relative_src_path, dst_path, /, **kwargs)

Parameters:
  • relative_src_pathstr 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject or SyncOperationLinkObject

download(*args, **kwargs) SyncResourceLinkObject

Download the file. This method takes 1 or 2 positional arguments:

  1. download(dst_path_or_file, /, **kwargs)

  2. 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_pathstr or None, source path relative to the resource

  • dst_path_or_file – destination path or file-like object

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject, link to the source resource

exists(relative_path: str | None = None, /, **kwargs) bool

Check whether resource exists.

Parameters:
  • relative_pathstr or None, relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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 a download link for a file (or a directory).

Parameters:
  • relative_pathstr or None, path relative to the resource

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

str

get_meta(relative_path: str | None = None, /, **kwargs) SyncResourceObject

Get meta information about a file/directory.

Parameters:
  • relative_pathstr 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_cropbool, cut the preview to the size specified in the preview_size

  • sortstr, field to be used as a key to sort children resources

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceObject

get_public_meta(**kwargs) SyncPublicResourceObject

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

  • sortstr, field to be used as a key to sort children resources

  • preview_size – file preview size

  • preview_cropbool, allow preview crop

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncPublicResourceObject

get_type(relative_path: str | None = None, /, **kwargs) str

Get resource type.

Parameters:
  • relative_path – relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

“file” or “dir”

Get a link to upload the file using the PUT request.

Parameters:
  • relative_pathstr or None, relative path to the resource

  • overwritebool, determines whether to overwrite the destination

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

str

is_dir(relative_path: str | None = None, /, **kwargs) bool

Check whether resource is a directory.

Parameters:
  • relative_path – relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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)

is_file(relative_path: str | None = None, /, **kwargs) bool

Check whether resource is a file.

Parameters:
  • relative_path – relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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)

listdir(relative_path: str | None = None, /, **kwargs) Generator[SyncResourceObject, None, 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_cropbool, cut the preview to the size specified in the preview_size

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

generator of SyncResourceObject

mkdir(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject

Create a new directory.

Parameters:
  • relative_pathstr or None, relative path to the directory to be created

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject

move(*args, **kwargs) SyncResourceLinkObject | SyncOperationLinkObject

Move resource to dst_path. This method takes 1 or 2 positional arguments:

  1. move(dst_path, /, **kwargs)

  2. move(relative_path, dst_path, /, **kwargs)

Parameters:
  • relative_pathstr or None, source path to be moved relative to the resource

  • dst_path – destination path

  • overwritebool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject or SyncOperationLinkObject

patch(*args, **kwargs) SyncResourceObject

Update custom properties of a resource. This method takes 1 or 2 positional arguments:

  1. patch(properties, /, **kwargs)

  2. patch(relative_path, properties, /, **kwargs)

Parameters:
  • relative_pathstr or None, path relative to the resource

  • propertiesdict, custom properties to update

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceObject

public_listdir(**kwargs) Generator[SyncPublicResourceObject, None, 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_cropbool, cut the preview to the size specified in the preview_size

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

generator of SyncPublicResourceObject

publish(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject

Make a resource public.

Parameters:
  • relative_pathstr or None, relative path to the resource to be published

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject, link to the resource

remove(relative_path: str | None = None, /, **kwargs) SyncOperationLinkObject | None

Remove the resource.

Parameters:
  • relative_pathstr 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

  • md5str, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncOperationLinkObject if the operation is performed asynchronously, None otherwise

rename(*args, **kwargs) SyncResourceLinkObject | SyncOperationLinkObject

Rename src_path to have filename new_name. Does the same as move() but changes only the filename.

Parameters:
  • relative_pathstr or None, source path to be renamed relative to the resource

  • new_name – target filename to rename to

  • overwritebool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject or SyncOperationLinkObject

unpublish(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject

Make a public resource private.

Parameters:
  • relative_pathstr or None, relative path to the resource to be unpublished

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject

upload(path_or_file: str | IO, relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject

Upload a file to disk.

Parameters:
  • path_or_file – path or file-like object to be uploaded

  • relative_pathstr 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject, link to the destination resource

upload_url(url: str, relative_path: str | None = None, /, **kwargs) OperationLinkObject

Upload a file from URL.

Parameters:
  • url – source URL

  • relative_pathstr or None, destination path relative to the resource

  • disable_redirectsbool, forbid redirects

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncOperationLinkObject, link to the asynchronous operation

class yadisk.objects.resources.SyncPublicResourcesListObject(public_resources_list: dict | None = None, yadisk: Any | None = None)[source]

Bases: PublicResourcesListObject

List of public resources.

Parameters:
  • public_resources_listdict or None

  • yadiskClient or None, YaDisk object

Variables:
  • itemslist, list of public resources (SyncPublicResourceObject)

  • typestr, resource type to filter by

  • limitint, maximum number of elements in the list

  • offsetint, offset from the beginning of the list

class yadisk.objects.resources.SyncResourceLinkObject(link: dict | None = None, yadisk: Any | None = None)[source]

Bases: ResourceLinkObject, ResourceObjectMethodsMixin

Resource link object.

Parameters:
  • linkdict or None

  • yadiskClient or None, YaDisk object

Variables:
  • hrefstr, link URL

  • methodstr, HTTP method

  • templatedbool, tells whether the URL is templated

  • pathstr, path to the resource

copy(*args, **kwargs) SyncResourceLinkObject | SyncOperationLinkObject

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:

  1. copy(dst_path, /, **kwargs)

  2. copy(relative_src_path, dst_path, /, **kwargs)

Parameters:
  • relative_src_pathstr 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject or SyncOperationLinkObject

download(*args, **kwargs) SyncResourceLinkObject

Download the file. This method takes 1 or 2 positional arguments:

  1. download(dst_path_or_file, /, **kwargs)

  2. 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_pathstr or None, source path relative to the resource

  • dst_path_or_file – destination path or file-like object

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject, link to the source resource

exists(relative_path: str | None = None, /, **kwargs) bool

Check whether resource exists.

Parameters:
  • relative_pathstr or None, relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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 a download link for a file (or a directory).

Parameters:
  • relative_pathstr or None, path relative to the resource

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

str

get_meta(relative_path: str | None = None, /, **kwargs) SyncResourceObject

Get meta information about a file/directory.

Parameters:
  • relative_pathstr 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_cropbool, cut the preview to the size specified in the preview_size

  • sortstr, field to be used as a key to sort children resources

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceObject

get_public_meta(**kwargs) SyncPublicResourceObject

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

  • sortstr, field to be used as a key to sort children resources

  • preview_size – file preview size

  • preview_cropbool, allow preview crop

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncPublicResourceObject

get_type(relative_path: str | None = None, /, **kwargs) str

Get resource type.

Parameters:
  • relative_path – relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

“file” or “dir”

Get a link to upload the file using the PUT request.

Parameters:
  • relative_pathstr or None, relative path to the resource

  • overwritebool, determines whether to overwrite the destination

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

str

is_dir(relative_path: str | None = None, /, **kwargs) bool

Check whether resource is a directory.

Parameters:
  • relative_path – relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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)

is_file(relative_path: str | None = None, /, **kwargs) bool

Check whether resource is a file.

Parameters:
  • relative_path – relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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)

listdir(relative_path: str | None = None, /, **kwargs) Generator[SyncResourceObject, None, 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_cropbool, cut the preview to the size specified in the preview_size

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

generator of SyncResourceObject

mkdir(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject

Create a new directory.

Parameters:
  • relative_pathstr or None, relative path to the directory to be created

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject

move(*args, **kwargs) SyncResourceLinkObject | SyncOperationLinkObject

Move resource to dst_path. This method takes 1 or 2 positional arguments:

  1. move(dst_path, /, **kwargs)

  2. move(relative_path, dst_path, /, **kwargs)

Parameters:
  • relative_pathstr or None, source path to be moved relative to the resource

  • dst_path – destination path

  • overwritebool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject or SyncOperationLinkObject

patch(*args, **kwargs) SyncResourceObject

Update custom properties of a resource. This method takes 1 or 2 positional arguments:

  1. patch(properties, /, **kwargs)

  2. patch(relative_path, properties, /, **kwargs)

Parameters:
  • relative_pathstr or None, path relative to the resource

  • propertiesdict, custom properties to update

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceObject

public_listdir(**kwargs) Generator[SyncPublicResourceObject, None, 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_cropbool, cut the preview to the size specified in the preview_size

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

generator of SyncPublicResourceObject

publish(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject

Make a resource public.

Parameters:
  • relative_pathstr or None, relative path to the resource to be published

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject, link to the resource

remove(relative_path: str | None = None, /, **kwargs) SyncOperationLinkObject | None

Remove the resource.

Parameters:
  • relative_pathstr 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

  • md5str, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncOperationLinkObject if the operation is performed asynchronously, None otherwise

rename(*args, **kwargs) SyncResourceLinkObject | SyncOperationLinkObject

Rename src_path to have filename new_name. Does the same as move() but changes only the filename.

Parameters:
  • relative_pathstr or None, source path to be renamed relative to the resource

  • new_name – target filename to rename to

  • overwritebool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject or SyncOperationLinkObject

unpublish(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject

Make a public resource private.

Parameters:
  • relative_pathstr or None, relative path to the resource to be unpublished

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject

upload(path_or_file: str | IO, relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject

Upload a file to disk.

Parameters:
  • path_or_file – path or file-like object to be uploaded

  • relative_pathstr 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject, link to the destination resource

upload_url(url: str, relative_path: str | None = None, /, **kwargs) OperationLinkObject

Upload a file from URL.

Parameters:
  • url – source URL

  • relative_pathstr or None, destination path relative to the resource

  • disable_redirectsbool, forbid redirects

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncOperationLinkObject, link to the asynchronous operation

class yadisk.objects.resources.SyncResourceListObject(resource_list: dict | None = None, yadisk: Any | None = None)[source]

Bases: ResourceListObject

List of resources.

Parameters:
  • resource_listdict or None

  • yadiskClient or None, YaDisk object

Variables:
  • sortstr, sort type

  • itemslist, list of resources (SyncResourceObject)

  • limitint, maximum number of elements in the list

  • offsetint, offset from the beginning of the list

  • pathstr, path to the directory that contains the elements of the list

  • totalint, number of elements in the list

class yadisk.objects.resources.SyncResourceObject(resource: dict | None = None, yadisk: Any | None = None)[source]

Bases: ResourceObject, ResourceObjectMethodsMixin

Resource object.

Parameters:
  • resourcedict or None

  • yadiskClient or None, YaDisk object

Variables:
  • antivirus_statusstr, antivirus check status

  • filestr, download URL

  • sizeint, file size

  • public_keystr, public resource key

  • sha256str, SHA256 hash

  • md5str, MD5 hash

  • embeddedSyncResourceListObject, list of nested resources

  • namestr, filename

  • exifEXIFObject, EXIF metadata

  • resource_idstr, resource ID

  • custom_propertiesdict, custom resource properties

  • public_urlstr, public URL

  • shareShareInfoObject, shared folder information

  • modifieddatetime.datetime, date of last modification

  • createddatetime.datetime, date of creation

  • photoslice_timedatetime.datetime, photo/video creation date

  • mime_typestr, MIME type

  • pathstr, path to the resource

  • previewstr, file preview URL

  • comment_idsCommentIDsObject, comment IDs

  • typestr, type (“file” or “dir”)

  • media_typestr, file type as determined by Yandex.Disk

  • revisionint, Yandex.Disk revision at the time of last modification

copy(*args, **kwargs) SyncResourceLinkObject | SyncOperationLinkObject

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:

  1. copy(dst_path, /, **kwargs)

  2. copy(relative_src_path, dst_path, /, **kwargs)

Parameters:
  • relative_src_pathstr 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject or SyncOperationLinkObject

download(*args, **kwargs) SyncResourceLinkObject

Download the file. This method takes 1 or 2 positional arguments:

  1. download(dst_path_or_file, /, **kwargs)

  2. 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_pathstr or None, source path relative to the resource

  • dst_path_or_file – destination path or file-like object

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject, link to the source resource

exists(relative_path: str | None = None, /, **kwargs) bool

Check whether resource exists.

Parameters:
  • relative_pathstr or None, relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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 a download link for a file (or a directory).

Parameters:
  • relative_pathstr or None, path relative to the resource

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

str

get_meta(relative_path: str | None = None, /, **kwargs) SyncResourceObject

Get meta information about a file/directory.

Parameters:
  • relative_pathstr 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_cropbool, cut the preview to the size specified in the preview_size

  • sortstr, field to be used as a key to sort children resources

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceObject

get_public_meta(**kwargs) SyncPublicResourceObject

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

  • sortstr, field to be used as a key to sort children resources

  • preview_size – file preview size

  • preview_cropbool, allow preview crop

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncPublicResourceObject

get_type(relative_path: str | None = None, /, **kwargs) str

Get resource type.

Parameters:
  • relative_path – relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

“file” or “dir”

Get a link to upload the file using the PUT request.

Parameters:
  • relative_pathstr or None, relative path to the resource

  • overwritebool, determines whether to overwrite the destination

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

str

is_dir(relative_path: str | None = None, /, **kwargs) bool

Check whether resource is a directory.

Parameters:
  • relative_path – relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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)

is_file(relative_path: str | None = None, /, **kwargs) bool

Check whether resource is a file.

Parameters:
  • relative_path – relative path from the resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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)

listdir(relative_path: str | None = None, /, **kwargs) Generator[SyncResourceObject, None, 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_cropbool, cut the preview to the size specified in the preview_size

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

generator of SyncResourceObject

mkdir(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject

Create a new directory.

Parameters:
  • relative_pathstr or None, relative path to the directory to be created

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject

move(*args, **kwargs) SyncResourceLinkObject | SyncOperationLinkObject

Move resource to dst_path. This method takes 1 or 2 positional arguments:

  1. move(dst_path, /, **kwargs)

  2. move(relative_path, dst_path, /, **kwargs)

Parameters:
  • relative_pathstr or None, source path to be moved relative to the resource

  • dst_path – destination path

  • overwritebool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject or SyncOperationLinkObject

patch(*args, **kwargs) SyncResourceObject

Update custom properties of a resource. This method takes 1 or 2 positional arguments:

  1. patch(properties, /, **kwargs)

  2. patch(relative_path, properties, /, **kwargs)

Parameters:
  • relative_pathstr or None, path relative to the resource

  • propertiesdict, custom properties to update

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceObject

public_listdir(**kwargs) Generator[SyncPublicResourceObject, None, 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_cropbool, cut the preview to the size specified in the preview_size

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

generator of SyncPublicResourceObject

publish(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject

Make a resource public.

Parameters:
  • relative_pathstr or None, relative path to the resource to be published

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject, link to the resource

remove(relative_path: str | None = None, /, **kwargs) SyncOperationLinkObject | None

Remove the resource.

Parameters:
  • relative_pathstr 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

  • md5str, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncOperationLinkObject if the operation is performed asynchronously, None otherwise

rename(*args, **kwargs) SyncResourceLinkObject | SyncOperationLinkObject

Rename src_path to have filename new_name. Does the same as move() but changes only the filename.

Parameters:
  • relative_pathstr or None, source path to be renamed relative to the resource

  • new_name – target filename to rename to

  • overwritebool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject or SyncOperationLinkObject

unpublish(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject

Make a public resource private.

Parameters:
  • relative_pathstr or None, relative path to the resource to be unpublished

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject

upload(path_or_file: str | IO, relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject

Upload a file to disk.

Parameters:
  • path_or_file – path or file-like object to be uploaded

  • relative_pathstr 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject, link to the destination resource

upload_url(url: str, relative_path: str | None = None, /, **kwargs) OperationLinkObject

Upload a file from URL.

Parameters:
  • url – source URL

  • relative_pathstr or None, destination path relative to the resource

  • disable_redirectsbool, forbid redirects

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncOperationLinkObject, link to the asynchronous operation

class yadisk.objects.resources.SyncTrashResourceListObject(trash_resource_list: dict | None = None, yadisk: Any | None = None)[source]

Bases: TrashResourceListObject

List of trash resources.

Parameters:
  • trash_resource_listdict or None

  • yadiskClient or None, YaDisk object

Variables:
  • sortstr, sort type

  • itemslist, list of resources (SyncTrashResourceObject)

  • limitint, maximum number of elements in the list

  • offsetint, offset from the beginning of the list

  • pathstr, path to the directory that contains the elements of the list

  • totalint, number of elements in the list

class yadisk.objects.resources.SyncTrashResourceObject(trash_resource: dict | None = None, yadisk: Any | None = None)[source]

Bases: TrashResourceObject

Trash resource object.

Parameters:
  • trash_resourcedict or None

  • yadiskClient or None, YaDisk object

Variables:
  • antivirus_statusstr, antivirus check status

  • filestr, download URL

  • sizeint, file size

  • public_keystr, public resource key

  • sha256str, SHA256 hash

  • md5str, MD5 hash

  • embeddedSyncTrashResourceListObject, list of nested resources

  • namestr, filename

  • exifEXIFObject, EXIF metadata

  • resource_idstr, resource ID

  • custom_propertiesdict, custom resource properties

  • public_urlstr, public URL

  • shareShareInfoObject, shared folder information

  • modifieddatetime.datetime, date of last modification

  • createddatetime.datetime, date of creation

  • photoslice_timedatetime.datetime, photo/video creation date

  • mime_typestr, MIME type

  • pathstr, path to the resource

  • previewstr, file preview URL

  • comment_idsCommentIDsObject, comment IDs

  • typestr, type (“file” or “dir”)

  • media_typestr, file type as determined by Yandex.Disk

  • revisionint, Yandex.Disk revision at the time of last modification

  • origin_pathstr, original path

  • deleteddatetime.datetime, date of deletion

exists(relative_path: str | None = None, /, **kwargs) bool[source]

Check whether the trash resource exists.

Parameters:
  • relative_pathstr or None, relative path to the trash resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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_meta(relative_path: str | None = None, /, **kwargs) SyncTrashResourceObject[source]

Get meta information about a trash resource.

Parameters:
  • relative_pathstr 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_cropbool, cut the preview to the size specified in the preview_size

  • sortstr, field to be used as a key to sort children resources

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncTrashResourceObject

get_type(relative_path: str | None = None, /, **kwargs) str[source]

Get trash resource type.

Parameters:
  • relative_pathstr or None, relative path to the trash resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

“file” or “dir”

is_dir(relative_path: str | None = None, /, **kwargs) bool[source]

Check whether resource is a trash directory.

Parameters:
  • relative_pathstr or None, relative path to the trash resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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)

is_file(relative_path: str | None = None, /, **kwargs) bool[source]

Check whether resource is a trash file.

Parameters:
  • relative_pathstr or None, relative path to the trash resource

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, 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)

listdir(relative_path: str | None = None, /, **kwargs) Generator[SyncTrashResourceObject, None, None][source]

Get contents of a trash resource.

Parameters:
  • relative_pathstr 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_cropbool, cut the preview to the size specified in the preview_size

  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

generator of SyncTrashResourceObject

remove(relative_path: str | None = None, /, **kwargs) SyncOperationLinkObject | None[source]

Remove a trash resource.

Parameters:
  • relative_pathstr 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncOperationLinkObject if the operation is performed asynchronously, None otherwise

restore(dst_path: str, /, **kwargs) SyncResourceLinkObject | 'SyncOperationLinkObject'[source]
restore(relative_path: str | None, dst_path: str, /, **kwargs) SyncResourceLinkObject | 'SyncOperationLinkObject'

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:

  1. restore(dst_path, /, **kwargs)

  2. restore(relative_path=None, dst_path, /, **kwargs)

Parameters:
  • relative_pathstr or None, relative path to the trash resource to be restored

  • dst_path – destination path

  • overwritebool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:
Returns:

SyncResourceLinkObject or SyncOperationLinkObject

class yadisk.objects.resources.TrashResourceListObject(trash_resource_list: dict | None = None, yadisk: Any | None = None)[source]

Bases: ResourceListObject

List of trash resources.

Parameters:
  • trash_resource_listdict or None

  • yadiskClient/AsyncClient or None, YaDisk object

Variables:
  • sortstr, sort type

  • itemslist, list of resources (TrashResourceObject)

  • limitint, maximum number of elements in the list

  • offsetint, offset from the beginning of the list

  • pathstr, path to the directory that contains the elements of the list

  • totalint, number of elements in the list

class yadisk.objects.resources.TrashResourceObject(trash_resource: dict | None = None, yadisk: Any | None = None)[source]

Bases: ResourceObject

Trash resource object.

Parameters:
  • trash_resourcedict or None

  • yadiskClient/AsyncClient or None, YaDisk object

Variables:
  • antivirus_statusstr, antivirus check status

  • filestr, download URL

  • sizeint, file size

  • public_keystr, public resource key

  • sha256str, SHA256 hash

  • md5str, MD5 hash

  • embeddedTrashResourceListObject, list of nested resources

  • namestr, filename

  • exifEXIFObject, EXIF metadata

  • resource_idstr, resource ID

  • custom_propertiesdict, custom resource properties

  • public_urlstr, public URL

  • shareShareInfoObject, shared folder information

  • modifieddatetime.datetime, date of last modification

  • createddatetime.datetime, date of creation

  • photoslice_timedatetime.datetime, photo/video creation date

  • mime_typestr, MIME type

  • pathstr, path to the resource

  • previewstr, file preview URL

  • comment_idsCommentIDsObject, comment IDs

  • typestr, type (“file” or “dir”)

  • media_typestr, file type as determined by Yandex.Disk

  • revisionint, Yandex.Disk revision at the time of last modification

  • origin_pathstr, original path

  • deleteddatetime.datetime, date of deletion

class yadisk.objects.operations.AsyncOperationLinkObject(link: dict | None = None, yadisk: Any | None = None)[source]

Bases: OperationLinkObject

Operation link object.

Parameters:
  • linkdict or None

  • yadiskAsyncClient or None, YaDisk object

Variables:
  • hrefstr, link URL

  • methodstr, HTTP method

  • templatedbool, 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

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:

OperationNotFoundError – requested operation was not found

Returns:

str, "in-progress" indicates that the operation is currently running, "success" indicates that the operation was successful, "failed" means that the operation failed

class yadisk.objects.operations.OperationLinkObject(link: dict | None = None, yadisk: Any | None = None)[source]

Bases: LinkObject

Operation link object.

Parameters:
Variables:
  • hrefstr, link URL

  • methodstr, HTTP method

  • templatedbool, tells whether the URL is templated

class yadisk.objects.operations.OperationStatusObject(operation_status: dict | None = None, yadisk: Any | None = None)[source]

Bases: YaDiskObject

Operation status object.

Parameters:
  • operation_statusdict or None

  • yadiskYaDisk or None, YaDisk object

Variables:
  • typestr, type of the operation

  • statusstr, status of the operation

  • operation_idstr, ID of the operation

  • linkLinkObject, link to the operation

  • datadict, other information about the operation

class yadisk.objects.operations.SyncOperationLinkObject(link: dict | None = None, yadisk: Any | None = None)[source]

Bases: OperationLinkObject

Operation link object.

Parameters:
  • linkdict or None

  • yadiskClient or None, YaDisk object

Variables:
  • hrefstr, link URL

  • methodstr, HTTP method

  • templatedbool, tells whether the URL is templated

get_status(**kwargs) str[source]

Get operation status.

Parameters:
  • fields – list of keys to be included in the response

  • timeoutfloat or tuple, request timeout

  • headersdict or None, additional request headers

  • n_retriesint, maximum number of retries

  • retry_interval – delay between retries in seconds

Raises:

OperationNotFoundError – requested operation was not found

Returns:

str, "in-progress" indicates that the operation is currently running, "success" indicates that the operation was successful, "failed" means that the operation failed