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_types – dict or None
yadisk –
YaDisk
or None, YaDisk object
- import_fields(source_dict: dict | None) None [source]
Set all the fields of the object to the values in source_dict. All the other fields are ignored
- Parameters:
source_dict – dict or None (nothing will be done in that case)
- set_alias(alias: str, name: str) None [source]
Set an alias.
- Parameters:
alias – str, alias to add
name – str, field name
- class yadisk.objects.ErrorObject(error=None, yadisk=None)[source]
Bases:
YaDiskObject
Mirrors Yandex.Disk REST API error object.
- Parameters:
error – dict or None
yadisk – YaDisk or None, YaDisk object
- Variables:
message – str, human-readable error message
description – str, technical error description
error – str, 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_object – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
device_code – str, device code that can be used for obtaining the token
user_code – str, code that the user should enter on the OAuth page
verification_url – str, URL of the OAuth page where user is expected to enter the
user_code
interval – int, 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_in – int, 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:
token – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
access_token – str, token string
refresh_token – str, the refresh-token
token_type – str, type of the token
expires_in – int, amount of time before the token expires
scope – str, 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_status – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
status – str, 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_info – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
max_file_size – int, maximum supported file size (bytes)
paid_max_file_size – int, maximum supported file size for a paid account (bytes)
unlimited_autoupload_enabled – bool, tells whether unlimited autoupload from mobile devices is enabled
total_space – int, total disk size (bytes)
trash_size – int, amount of space used by trash (bytes), part of used_space
is_paid – bool, tells if the account is paid or not
used_space – int, amount of space used (bytes)
system_folders –
SystemFoldersObject
, paths to the system foldersuser –
UserObject
, owner of the diskrevision – int, current revision of Yandex.Disk
- class yadisk.objects.disk.SystemFoldersObject(system_folders: dict | None = None, yadisk: Any | None = None)[source]
Bases:
YaDiskObject
Object, containing paths to system folders.
- Parameters:
system_folders – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
odnoklassniki – str, path to the Odnoklassniki folder
google – str, path to the Google+ folder
instagram – str, path to the Instagram folder
vkontakte – str, path to the VKontakte folder
attach – str, path to the mail attachments folder
mailru – str, path to the My World folder
downloads – str, path to the Downloads folder
applications – str path to the Applications folder
facebook – str, path to the Facebook folder
social – str, path to the social networks folder
messenger – str, path to the Messenger Files folder
calendar – str, path to the Meeting Materials folder
photostream – str, path to the camera folder
screenshots – str, path to the screenshot folder
scans – str, path to the Scans folder
- class yadisk.objects.disk.UserObject(user: dict | None = None, yadisk: Any | None = None)[source]
Bases:
YaDiskObject
User object.
- Parameters:
user – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
country – str, user’s country
login – str, user’s login
display_name – str, user’s display name
uid – str, user’s UID
- class yadisk.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_info – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
login – str, user’s login
display_name – str, user’s display name
uid – str, user’s UID
- class yadisk.objects.resources.AsyncFilesResourceListObject(files_resource_list: dict | None = None, yadisk: Any | None = None)[source]
Bases:
FilesResourceListObject
Flat list of files.
- Parameters:
files_resource_list – dict or None
yadisk –
AsyncClient
or None, YaDisk object
- Variables:
items – list, flat list of files (
AsyncResourceObject
)limit – int, maximum number of elements in the list
offset – int, 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_list – dict or None
yadisk –
AsyncClient
or None, YaDisk object
- Variables:
items – list, list of resources (
AsyncResourceObject
)limit – int, 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:
link – dict or None
yadisk –
AsyncClient
or None, YaDisk object
- Variables:
href – str, link URL
method – str, HTTP method
templated – bool, tells whether the URL is templated
public_key – str, public key of the resource
public_url – str, public URL of the resource
- async copy(*args, **kwargs) 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:
copy(dst_path, /, **kwargs)
copy(relative_path, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, source path relative to the resource
dst_path – destination path
overwrite – if True the destination path can be overwritten, otherwise, an error will be raised
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
InsufficientStorageError – cannot complete request due to lack of storage space
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
- async download(*args, **kwargs) AsyncResourceLinkObject
Download the file. This method takes 1 or 2 positional arguments:
download(dst_path_or_file, /, **kwargs)
download(relative_path, dst_path_or_file, /, **kwargs)
If relative_path is empty or None (or not specified) this method will try to use the file attribute as a download link.
- Parameters:
relative_path – str or None, source path relative to the resource
dst_path_or_file – destination path or file-like object
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
AsyncResourceLinkObject
, link to the source resource
- async exists(relative_path: str | None = None, /, **kwargs) bool
Check whether resource exists.
- Parameters:
relative_path – str or None, relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
bool
- async get_download_link(relative_path: str | None = None, /, **kwargs) str
Get a download link for a file (or a directory).
- Parameters:
relative_path – str or None, path relative to the resource
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
str
- async get_meta(relative_path: str | None = None, /, **kwargs) AsyncResourceObject
Get meta information about a file/directory.
- Parameters:
relative_path – str or None, relative path from resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_public_meta(**kwargs) 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
sort – str, field to be used as a key to sort children resources
preview_size – file preview size
preview_crop – bool, allow preview crop
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_type(relative_path: str | None = None, /, **kwargs) str
Get resource type.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
“file” or “dir”
- async get_upload_link(relative_path: str | None = None, /, **kwargs) str
Get a link to upload the file using the PUT request.
- Parameters:
relative_path – str or None, relative path to the resource
overwrite – bool, determines whether to overwrite the destination
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
str
- async is_dir(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a directory.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a directory, False otherwise (even if it doesn’t exist)
- async is_file(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a file.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a file, False otherwise (even if it doesn’t exist)
- async listdir(relative_path: str | None = None, /, **kwargs) AsyncGenerator[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_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
AsyncResourceObject
- async mkdir(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject
Create a new directory.
- Parameters:
relative_path – str or None, relative path to the directory to be created
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
DirectoryExistsError – destination path already exists
InsufficientStorageError – cannot create directory due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async move(*args, **kwargs) AsyncResourceLinkObject | AsyncOperationLinkObject
Move resource to dst_path. This method takes 1 or 2 positional arguments:
move(dst_path, /, **kwargs)
move(relative_path, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, source path to be moved relative to the resource
dst_path – destination path
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async patch(*args, **kwargs) AsyncResourceObject
Update custom properties of a resource. This method takes 1 or 2 positional arguments:
patch(properties, /, **kwargs)
patch(relative_path, properties, /, **kwargs)
- Parameters:
relative_path – str or None, path relative to the resource
properties – dict, custom properties to update
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async public_listdir(**kwargs) AsyncGenerator[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_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
AsyncPublicResourceObject
- async publish(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject
Make a resource public.
- Parameters:
relative_path – str or None, relative path to the resource to be published
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
AsyncResourceLinkObject
, link to the resource
- async remove(relative_path: str | None = None, /, **kwargs) AsyncOperationLinkObject | None
Remove the resource.
- Parameters:
relative_path – str or None, relative path to the resource to be removed
permanently – if True, the resource will be removed permanently, otherwise, it will be just moved to the trash
md5 – str, MD5 hash of the file to remove
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
BadRequestError – MD5 check is only available for files
ResourceIsLockedError – resource is locked by another request
- Returns:
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_path – str or None, source path to be renamed relative to the resource
new_name – target filename to rename to
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
ValueError – new_name is not a valid filename
- Returns:
- async unpublish(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject
Make a public resource private.
- Parameters:
relative_path – str or None, relative path to the resource to be unpublished
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async upload(path_or_file: str | 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_path – str or None, destination path relative to the resource
overwrite – if True, the resource will be overwritten if it already exists, an error will be raised otherwise
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
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_path – str or None, destination path relative to the resource
disable_redirects – bool, forbid redirects
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
InsufficientStorageError – cannot upload file due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
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_list – dict or None
yadisk –
AsyncClient
or None, YaDisk object
- Variables:
sort – str, sort type
items – list, list of resources (
AsyncResourceObject
)limit – int, maximum number of elements in the list
offset – int, offset from the beginning of the list
path – str, path to the directory that contains the elements of the list
total – int, number of elements in the list
public_key – str, public key of the resource
- class yadisk.objects.resources.AsyncPublicResourceObject(public_resource: dict | None = None, yadisk: Any | None = None)[source]
Bases:
PublicResourceObject
,AsyncResourceObjectMethodsMixin
Public resource object.
- Parameters:
resource – dict or None
yadisk –
AsyncClient
or None, YaDisk object
- Variables:
antivirus_status – str, antivirus check status
file – str, download URL
size – int, file size
public_key – str, public resource key
sha256 – str, SHA256 hash
md5 – str, MD5 hash
embedded –
AsyncPublicResourceObject
, list of nested resourcesname – str, filename
exif –
EXIFObject
, EXIF metadataresource_id – str, resource ID
custom_properties – dict, custom resource properties
public_url – str, public URL
share –
ShareInfoObject
, shared folder informationmodified –
datetime.datetime
, date of last modificationcreated –
datetime.datetime
, date of creationphotoslice_time –
datetime.datetime
, photo/video creation datemime_type – str, MIME type
path – str, path to the resource
preview – str, file preview URL
comment_ids –
CommentIDsObject
, comment IDstype – str, type (“file” or “dir”)
media_type – str, file type as determined by Yandex.Disk
revision – int, Yandex.Disk revision at the time of last modification
view_count – int, number of times the public resource was viewed
owner –
UserPublicInfoObject
, owner of the public resource
- async copy(*args, **kwargs) 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:
copy(dst_path, /, **kwargs)
copy(relative_path, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, source path relative to the resource
dst_path – destination path
overwrite – if True the destination path can be overwritten, otherwise, an error will be raised
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
InsufficientStorageError – cannot complete request due to lack of storage space
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
- async download(*args, **kwargs) AsyncResourceLinkObject
Download the file. This method takes 1 or 2 positional arguments:
download(dst_path_or_file, /, **kwargs)
download(relative_path, dst_path_or_file, /, **kwargs)
If relative_path is empty or None (or not specified) this method will try to use the file attribute as a download link.
- Parameters:
relative_path – str or None, source path relative to the resource
dst_path_or_file – destination path or file-like object
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
AsyncResourceLinkObject
, link to the source resource
- async exists(relative_path: str | None = None, /, **kwargs) bool
Check whether resource exists.
- Parameters:
relative_path – str or None, relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
bool
- async get_download_link(relative_path: str | None = None, /, **kwargs) str
Get a download link for a file (or a directory).
- Parameters:
relative_path – str or None, path relative to the resource
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
str
- async get_meta(relative_path: str | None = None, /, **kwargs) AsyncResourceObject
Get meta information about a file/directory.
- Parameters:
relative_path – str or None, relative path from resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_public_meta(**kwargs) 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
sort – str, field to be used as a key to sort children resources
preview_size – file preview size
preview_crop – bool, allow preview crop
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_type(relative_path: str | None = None, /, **kwargs) str
Get resource type.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
“file” or “dir”
- async get_upload_link(relative_path: str | None = None, /, **kwargs) str
Get a link to upload the file using the PUT request.
- Parameters:
relative_path – str or None, relative path to the resource
overwrite – bool, determines whether to overwrite the destination
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
str
- async is_dir(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a directory.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a directory, False otherwise (even if it doesn’t exist)
- async is_file(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a file.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a file, False otherwise (even if it doesn’t exist)
- async listdir(relative_path: str | None = None, /, **kwargs) AsyncGenerator[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_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
AsyncResourceObject
- async mkdir(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject
Create a new directory.
- Parameters:
relative_path – str or None, relative path to the directory to be created
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
DirectoryExistsError – destination path already exists
InsufficientStorageError – cannot create directory due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async move(*args, **kwargs) AsyncResourceLinkObject | AsyncOperationLinkObject
Move resource to dst_path. This method takes 1 or 2 positional arguments:
move(dst_path, /, **kwargs)
move(relative_path, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, source path to be moved relative to the resource
dst_path – destination path
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async patch(*args, **kwargs) AsyncResourceObject
Update custom properties of a resource. This method takes 1 or 2 positional arguments:
patch(properties, /, **kwargs)
patch(relative_path, properties, /, **kwargs)
- Parameters:
relative_path – str or None, path relative to the resource
properties – dict, custom properties to update
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async public_listdir(**kwargs) AsyncGenerator[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_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
AsyncPublicResourceObject
- async publish(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject
Make a resource public.
- Parameters:
relative_path – str or None, relative path to the resource to be published
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
AsyncResourceLinkObject
, link to the resource
- async remove(relative_path: str | None = None, /, **kwargs) AsyncOperationLinkObject | None
Remove the resource.
- Parameters:
relative_path – str or None, relative path to the resource to be removed
permanently – if True, the resource will be removed permanently, otherwise, it will be just moved to the trash
md5 – str, MD5 hash of the file to remove
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
BadRequestError – MD5 check is only available for files
ResourceIsLockedError – resource is locked by another request
- Returns:
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_path – str or None, source path to be renamed relative to the resource
new_name – target filename to rename to
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
ValueError – new_name is not a valid filename
- Returns:
- async unpublish(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject
Make a public resource private.
- Parameters:
relative_path – str or None, relative path to the resource to be unpublished
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async upload(path_or_file: str | 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_path – str or None, destination path relative to the resource
overwrite – if True, the resource will be overwritten if it already exists, an error will be raised otherwise
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
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_path – str or None, destination path relative to the resource
disable_redirects – bool, forbid redirects
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
InsufficientStorageError – cannot upload file due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
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_list – dict or None
yadisk –
AsyncClient
or None, YaDisk object
- Variables:
items – list, list of public resources (
AsyncPublicResourceObject
)type – str, resource type to filter by
limit – int, maximum number of elements in the list
offset – int, offset from the beginning of the list
- class yadisk.objects.resources.AsyncResourceLinkObject(link: dict | None = None, yadisk: Any | None = None)[source]
Bases:
ResourceLinkObject
,AsyncResourceObjectMethodsMixin
Resource link object.
- Parameters:
link – dict or None
yadisk –
AsyncClient
or None, YaDisk object
- Variables:
href – str, link URL
method – str, HTTP method
templated – bool, tells whether the URL is templated
path – str, path to the resource
- async copy(*args, **kwargs) 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:
copy(dst_path, /, **kwargs)
copy(relative_path, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, source path relative to the resource
dst_path – destination path
overwrite – if True the destination path can be overwritten, otherwise, an error will be raised
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
InsufficientStorageError – cannot complete request due to lack of storage space
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
- async download(*args, **kwargs) AsyncResourceLinkObject
Download the file. This method takes 1 or 2 positional arguments:
download(dst_path_or_file, /, **kwargs)
download(relative_path, dst_path_or_file, /, **kwargs)
If relative_path is empty or None (or not specified) this method will try to use the file attribute as a download link.
- Parameters:
relative_path – str or None, source path relative to the resource
dst_path_or_file – destination path or file-like object
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
AsyncResourceLinkObject
, link to the source resource
- async exists(relative_path: str | None = None, /, **kwargs) bool
Check whether resource exists.
- Parameters:
relative_path – str or None, relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
bool
- async get_download_link(relative_path: str | None = None, /, **kwargs) str
Get a download link for a file (or a directory).
- Parameters:
relative_path – str or None, path relative to the resource
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
str
- async get_meta(relative_path: str | None = None, /, **kwargs) AsyncResourceObject
Get meta information about a file/directory.
- Parameters:
relative_path – str or None, relative path from resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_public_meta(**kwargs) 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
sort – str, field to be used as a key to sort children resources
preview_size – file preview size
preview_crop – bool, allow preview crop
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_type(relative_path: str | None = None, /, **kwargs) str
Get resource type.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
“file” or “dir”
- async get_upload_link(relative_path: str | None = None, /, **kwargs) str
Get a link to upload the file using the PUT request.
- Parameters:
relative_path – str or None, relative path to the resource
overwrite – bool, determines whether to overwrite the destination
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
str
- async is_dir(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a directory.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a directory, False otherwise (even if it doesn’t exist)
- async is_file(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a file.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a file, False otherwise (even if it doesn’t exist)
- async listdir(relative_path: str | None = None, /, **kwargs) AsyncGenerator[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_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
AsyncResourceObject
- async mkdir(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject
Create a new directory.
- Parameters:
relative_path – str or None, relative path to the directory to be created
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
DirectoryExistsError – destination path already exists
InsufficientStorageError – cannot create directory due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async move(*args, **kwargs) AsyncResourceLinkObject | AsyncOperationLinkObject
Move resource to dst_path. This method takes 1 or 2 positional arguments:
move(dst_path, /, **kwargs)
move(relative_path, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, source path to be moved relative to the resource
dst_path – destination path
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async patch(*args, **kwargs) AsyncResourceObject
Update custom properties of a resource. This method takes 1 or 2 positional arguments:
patch(properties, /, **kwargs)
patch(relative_path, properties, /, **kwargs)
- Parameters:
relative_path – str or None, path relative to the resource
properties – dict, custom properties to update
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async public_listdir(**kwargs) AsyncGenerator[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_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
AsyncPublicResourceObject
- async publish(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject
Make a resource public.
- Parameters:
relative_path – str or None, relative path to the resource to be published
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
AsyncResourceLinkObject
, link to the resource
- async remove(relative_path: str | None = None, /, **kwargs) AsyncOperationLinkObject | None
Remove the resource.
- Parameters:
relative_path – str or None, relative path to the resource to be removed
permanently – if True, the resource will be removed permanently, otherwise, it will be just moved to the trash
md5 – str, MD5 hash of the file to remove
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
BadRequestError – MD5 check is only available for files
ResourceIsLockedError – resource is locked by another request
- Returns:
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_path – str or None, source path to be renamed relative to the resource
new_name – target filename to rename to
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
ValueError – new_name is not a valid filename
- Returns:
- async unpublish(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject
Make a public resource private.
- Parameters:
relative_path – str or None, relative path to the resource to be unpublished
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async upload(path_or_file: str | 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_path – str or None, destination path relative to the resource
overwrite – if True, the resource will be overwritten if it already exists, an error will be raised otherwise
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
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_path – str or None, destination path relative to the resource
disable_redirects – bool, forbid redirects
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
InsufficientStorageError – cannot upload file due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
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_list – dict or None
yadisk –
AsyncClient
or None, YaDisk object
- Variables:
sort – str, sort type
items – list, list of resources (
AsyncResourceObject
)limit – int, maximum number of elements in the list
offset – int, offset from the beginning of the list
path – str, path to the directory that contains the elements of the list
total – int, number of elements in the list
- class yadisk.objects.resources.AsyncResourceObject(resource: dict | None = None, yadisk: Any | None = None)[source]
Bases:
ResourceObject
,AsyncResourceObjectMethodsMixin
Resource object.
- Parameters:
resource – dict or None
yadisk –
AsyncClient
or None, YaDisk object
- Variables:
antivirus_status – str, antivirus check status
file – str, download URL
size – int, file size
public_key – str, public resource key
sha256 – str, SHA256 hash
md5 – str, MD5 hash
embedded –
AsyncResourceListObject
, list of nested resourcesname – str, filename
exif –
EXIFObject
, EXIF metadataresource_id – str, resource ID
custom_properties – dict, custom resource properties
public_url – str, public URL
share –
ShareInfoObject
, shared folder informationmodified –
datetime.datetime
, date of last modificationcreated –
datetime.datetime
, date of creationphotoslice_time –
datetime.datetime
, photo/video creation datemime_type – str, MIME type
path – str, path to the resource
preview – str, file preview URL
comment_ids –
CommentIDsObject
, comment IDstype – str, type (“file” or “dir”)
media_type – str, file type as determined by Yandex.Disk
revision – int, Yandex.Disk revision at the time of last modification
- async copy(*args, **kwargs) 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:
copy(dst_path, /, **kwargs)
copy(relative_path, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, source path relative to the resource
dst_path – destination path
overwrite – if True the destination path can be overwritten, otherwise, an error will be raised
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
InsufficientStorageError – cannot complete request due to lack of storage space
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
- async download(*args, **kwargs) AsyncResourceLinkObject
Download the file. This method takes 1 or 2 positional arguments:
download(dst_path_or_file, /, **kwargs)
download(relative_path, dst_path_or_file, /, **kwargs)
If relative_path is empty or None (or not specified) this method will try to use the file attribute as a download link.
- Parameters:
relative_path – str or None, source path relative to the resource
dst_path_or_file – destination path or file-like object
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
AsyncResourceLinkObject
, link to the source resource
- async exists(relative_path: str | None = None, /, **kwargs) bool
Check whether resource exists.
- Parameters:
relative_path – str or None, relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
bool
- async get_download_link(relative_path: str | None = None, /, **kwargs) str
Get a download link for a file (or a directory).
- Parameters:
relative_path – str or None, path relative to the resource
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
str
- async get_meta(relative_path: str | None = None, /, **kwargs) AsyncResourceObject
Get meta information about a file/directory.
- Parameters:
relative_path – str or None, relative path from resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_public_meta(**kwargs) 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
sort – str, field to be used as a key to sort children resources
preview_size – file preview size
preview_crop – bool, allow preview crop
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_type(relative_path: str | None = None, /, **kwargs) str
Get resource type.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
“file” or “dir”
- async get_upload_link(relative_path: str | None = None, /, **kwargs) str
Get a link to upload the file using the PUT request.
- Parameters:
relative_path – str or None, relative path to the resource
overwrite – bool, determines whether to overwrite the destination
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
str
- async is_dir(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a directory.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a directory, False otherwise (even if it doesn’t exist)
- async is_file(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a file.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a file, False otherwise (even if it doesn’t exist)
- async listdir(relative_path: str | None = None, /, **kwargs) AsyncGenerator[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_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
AsyncResourceObject
- async mkdir(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject
Create a new directory.
- Parameters:
relative_path – str or None, relative path to the directory to be created
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
DirectoryExistsError – destination path already exists
InsufficientStorageError – cannot create directory due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async move(*args, **kwargs) AsyncResourceLinkObject | AsyncOperationLinkObject
Move resource to dst_path. This method takes 1 or 2 positional arguments:
move(dst_path, /, **kwargs)
move(relative_path, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, source path to be moved relative to the resource
dst_path – destination path
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async patch(*args, **kwargs) AsyncResourceObject
Update custom properties of a resource. This method takes 1 or 2 positional arguments:
patch(properties, /, **kwargs)
patch(relative_path, properties, /, **kwargs)
- Parameters:
relative_path – str or None, path relative to the resource
properties – dict, custom properties to update
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async public_listdir(**kwargs) AsyncGenerator[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_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
AsyncPublicResourceObject
- async publish(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject
Make a resource public.
- Parameters:
relative_path – str or None, relative path to the resource to be published
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
AsyncResourceLinkObject
, link to the resource
- async remove(relative_path: str | None = None, /, **kwargs) AsyncOperationLinkObject | None
Remove the resource.
- Parameters:
relative_path – str or None, relative path to the resource to be removed
permanently – if True, the resource will be removed permanently, otherwise, it will be just moved to the trash
md5 – str, MD5 hash of the file to remove
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
BadRequestError – MD5 check is only available for files
ResourceIsLockedError – resource is locked by another request
- Returns:
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_path – str or None, source path to be renamed relative to the resource
new_name – target filename to rename to
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
ValueError – new_name is not a valid filename
- Returns:
- async unpublish(relative_path: str | None = None, /, **kwargs) AsyncResourceLinkObject
Make a public resource private.
- Parameters:
relative_path – str or None, relative path to the resource to be unpublished
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- async upload(path_or_file: str | 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_path – str or None, destination path relative to the resource
overwrite – if True, the resource will be overwritten if it already exists, an error will be raised otherwise
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
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_path – str or None, destination path relative to the resource
disable_redirects – bool, forbid redirects
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
InsufficientStorageError – cannot upload file due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
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_list – dict or None
yadisk –
AsyncClient
or None, YaDisk object
- Variables:
sort – str, sort type
items – list, list of resources (
AsyncTrashResourceObject
)limit – int, maximum number of elements in the list
offset – int, offset from the beginning of the list
path – str, path to the directory that contains the elements of the list
total – int, number of elements in the list
- class yadisk.objects.resources.AsyncTrashResourceObject(trash_resource: dict | None = None, yadisk: Any | None = None)[source]
Bases:
TrashResourceObject
Trash resource object.
- Parameters:
trash_resource – dict or None
yadisk –
AsyncClient
or None, YaDisk object
- Variables:
antivirus_status – str, antivirus check status
file – str, download URL
size – int, file size
public_key – str, public resource key
sha256 – str, SHA256 hash
md5 – str, MD5 hash
embedded –
AsyncTrashResourceListObject
, list of nested resourcesname – str, filename
exif –
EXIFObject
, EXIF metadataresource_id – str, resource ID
custom_properties – dict, custom resource properties
public_url – str, public URL
share –
ShareInfoObject
, shared folder informationmodified –
datetime.datetime
, date of last modificationcreated –
datetime.datetime
, date of creationphotoslice_time –
datetime.datetime
, photo/video creation datemime_type – str, MIME type
path – str, path to the resource
preview – str, file preview URL
comment_ids –
CommentIDsObject
, comment IDstype – str, type (“file” or “dir”)
media_type – str, file type as determined by Yandex.Disk
revision – int, Yandex.Disk revision at the time of last modification
origin_path – str, original path
deleted –
datetime.datetime
, date of deletion
- async exists(relative_path: str | None = None, /, **kwargs) bool [source]
Check whether the trash resource exists.
- Parameters:
relative_path – str or None, relative path to the trash resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
bool
- async get_meta(relative_path: str | None = None, /, **kwargs) AsyncTrashResourceObject [source]
Get meta information about a trash resource.
- Parameters:
relative_path – str or None, relative path to the trash resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- async get_type(relative_path: str | None = None, /, **kwargs) str [source]
Get trash resource type.
- Parameters:
relative_path – str or None, relative path to the trash resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
“file” or “dir”
- async is_dir(relative_path: str | None = None, /, **kwargs) bool [source]
Check whether resource is a trash directory.
- Parameters:
relative_path – str or None, relative path to the trash resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a directory, False otherwise (even if it doesn’t exist)
- async is_file(relative_path: str | None = None, /, **kwargs) bool [source]
Check whether resource is a trash file.
- Parameters:
relative_path – str or None, relative path to the trash resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a file, False otherwise (even if it doesn’t exist)
- async listdir(relative_path: str | None = None, /, **kwargs) Generator[AsyncTrashResourceObject, None, None] [source]
Get contents of a trash resource.
- Parameters:
relative_path – str or None, relative path to the directory in the trash bin
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
AsyncTrashResourceObject
- async remove(relative_path: str | None = None, /, **kwargs) AsyncOperationLinkObject | None [source]
Remove a trash resource.
- Parameters:
relative_path – str or None, relative path to the trash resource to be deleted
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
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:
restore(dst_path, /, **kwargs)
restore(relative_path=None, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, relative path to the trash resource to be restored
dst_path – destination path
overwrite – bool, determines whether the destination can be overwritten
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- class yadisk.objects.resources.CommentIDsObject(comment_ids: dict | None = None, yadisk: Any | None = None)[source]
Bases:
YaDiskObject
Comment IDs object.
- Parameters:
comment_ids – dict or None
yadisk –
Client
/AsyncClient
or None, YaDisk object
- Variables:
private_resource – str, comment ID for private resources
public_resource – str, 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:
exif – dict or None
yadisk –
Client
/AsyncClient
or None, YaDisk object
- Variables:
date_time –
datetime.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_list – dict or None
yadisk –
Client
/AsyncClient
or None, YaDisk object
- Variables:
items – list, flat list of files (
ResourceObject
)limit – int, maximum number of elements in the list
offset – int, offset from the beginning of the list
- class yadisk.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_list – dict or None
yadisk –
Client
/AsyncClient
or None, YaDisk object
- Variables:
items – list, list of resources (
ResourceObject
)limit – int, 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:
link – dict or None
yadisk –
Client
/AsyncClient
or None, YaDisk object
- Variables:
href – str, link URL
method – str, HTTP method
templated – bool, tells whether the URL is templated
public_key – str, public key of the resource
public_url – str, public URL of the resource
- 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_list – dict or None
yadisk –
Client
/AsyncClient
or None, YaDisk object
- Variables:
sort – str, sort type
items – list, list of resources (
ResourceObject
)limit – int, maximum number of elements in the list
offset – int, offset from the beginning of the list
path – str, path to the directory that contains the elements of the list
total – int, number of elements in the list
public_key – str, public key of the resource
- class yadisk.objects.resources.PublicResourceObject(public_resource=None, yadisk=None)[source]
Bases:
ResourceObject
Public resource object.
- Parameters:
resource – dict or None
yadisk –
Client
/AsyncClient
or None, YaDisk object
- Variables:
antivirus_status – str, antivirus check status
file – str, download URL
size – int, file size
public_key – str, public resource key
sha256 – str, SHA256 hash
md5 – str, MD5 hash
embedded –
PublicResourceObject
, list of nested resourcesname – str, filename
exif –
EXIFObject
, EXIF metadataresource_id – str, resource ID
custom_properties – dict, custom resource properties
public_url – str, public URL
share –
ShareInfoObject
, shared folder informationmodified –
datetime.datetime
, date of last modificationcreated –
datetime.datetime
, date of creationphotoslice_time –
datetime.datetime
, photo/video creation datemime_type – str, MIME type
path – str, path to the resource
preview – str, file preview URL
comment_ids –
CommentIDsObject
, comment IDstype – str, type (“file” or “dir”)
media_type – str, file type as determined by Yandex.Disk
revision – int, Yandex.Disk revision at the time of last modification
view_count – int, number of times the public resource was viewed
owner –
UserPublicInfoObject
, owner of the public resource
- 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_list – dict or None
yadisk –
Client
/AsyncClient
or None, YaDisk object
- Variables:
items – list, list of public resources (
PublicResourceObject
)type – str, resource type to filter by
limit – int, maximum number of elements in the list
offset – int, offset from the beginning of the list
- class yadisk.objects.resources.ResourceDownloadLinkObject(link: dict | None = None, yadisk: Any | None = None)[source]
Bases:
LinkObject
Resource download link.
- Parameters:
link – dict or None
yadisk –
Client
/AsyncClient
or None, YaDisk object
- Variables:
href – str, link URL
method – str, HTTP method
templated – bool, 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:
link – dict or None
yadisk –
Client
/AsyncClient
or None, YaDisk object
- Variables:
href – str, link URL
method – str, HTTP method
templated – bool, tells whether the URL is templated
path – str, path to the resource
- class yadisk.objects.resources.ResourceListObject(resource_list: dict | None = None, yadisk: Any | None = None)[source]
Bases:
YaDiskObject
List of resources.
- Parameters:
resource_list – dict or None
yadisk –
Client
/AsyncClient
or None, YaDisk object
- Variables:
sort – str, sort type
items – list, list of resources (
ResourceObject
)limit – int, maximum number of elements in the list
offset – int, offset from the beginning of the list
path – str, path to the directory that contains the elements of the list
total – int, number of elements in the list
- class yadisk.objects.resources.ResourceObject(resource: dict | None = None, yadisk: Any | None = None)[source]
Bases:
YaDiskObject
Resource object.
- Parameters:
resource – dict or None
yadisk –
Client
/AsyncClient
or None, YaDisk object
- Variables:
antivirus_status – str, antivirus check status
file – str, download URL
size – int, file size
public_key – str, public resource key
sha256 – str, SHA256 hash
md5 – str, MD5 hash
embedded –
ResourceListObject
, list of nested resourcesname – str, filename
exif –
EXIFObject
, EXIF metadataresource_id – str, resource ID
custom_properties – dict, custom resource properties
public_url – str, public URL
share –
ShareInfoObject
, shared folder informationmodified –
datetime.datetime
, date of last modificationcreated –
datetime.datetime
, date of creationphotoslice_time –
datetime.datetime
, photo/video creation datemime_type – str, MIME type
path – str, path to the resource
preview – str, file preview URL
comment_ids –
CommentIDsObject
, comment IDstype – str, type (“file” or “dir”)
media_type – str, file type as determined by Yandex.Disk
revision – int, Yandex.Disk revision at the time of last modification
- class yadisk.objects.resources.ResourceUploadLinkObject(resource_upload_link: dict | None = None, yadisk: Any | None = None)[source]
Bases:
LinkObject
Resource upload link.
- Parameters:
resource_upload_link – dict or None
yadisk –
Client
/AsyncClient
or None, YaDisk object
- Variables:
operation_id – str, ID of the upload operation
href – str, link URL
method – str, HTTP method
templated – bool, tells whether the URL is templated
Bases:
YaDiskObject
Shared folder information object.
- Parameters:
share_info – dict or None
yadisk –
Client
/AsyncClient
or None, YaDisk object
- Variables:
is_root – bool, tells whether the folder is root
is_owned – bool, tells whether the user is the owner of this directory
rights – str, access rights
- class yadisk.objects.resources.SyncFilesResourceListObject(files_resource_list: dict | None = None, yadisk: Any | None = None)[source]
Bases:
FilesResourceListObject
Flat list of files.
- Parameters:
files_resource_list – dict or None
yadisk –
Client
or None, YaDisk object
- Variables:
items – list, flat list of files (
SyncResourceObject
)limit – int, maximum number of elements in the list
offset – int, 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_list – dict or None
yadisk –
Client
or None, YaDisk object
- Variables:
items – list, list of resources (
SyncResourceObject
)limit – int, 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:
link – dict or None
yadisk –
Client
or None, YaDisk object
- Variables:
href – str, link URL
method – str, HTTP method
templated – bool, tells whether the URL is templated
public_key – str, public key of the resource
public_url – str, public URL of the resource
- 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:
copy(dst_path, /, **kwargs)
copy(relative_src_path, dst_path, /, **kwargs)
- Parameters:
relative_src_path – str or None, source path relative to the resource
dst_path – destination path
overwrite – if True the destination path can be overwritten, otherwise, an error will be raised
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
InsufficientStorageError – cannot complete request due to lack of storage space
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
- download(*args, **kwargs) SyncResourceLinkObject
Download the file. This method takes 1 or 2 positional arguments:
download(dst_path_or_file, /, **kwargs)
download(relative_path, dst_path_or_file, /, **kwargs)
If relative_path is empty or None (or not specified) this method will try to use the file attribute as a download link.
- Parameters:
relative_path – str or None, source path relative to the resource
dst_path_or_file – destination path or file-like object
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
SyncResourceLinkObject
, link to the source resource
- exists(relative_path: str | None = None, /, **kwargs) bool
Check whether resource exists.
- Parameters:
relative_path – str or None, relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
bool
- get_download_link(relative_path: str | None = None, /, **kwargs) str
Get a download link for a file (or a directory).
- Parameters:
relative_path – str or None, path relative to the resource
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
str
- get_meta(relative_path: str | None = None, /, **kwargs) SyncResourceObject
Get meta information about a file/directory.
- Parameters:
relative_path – str or None, relative path from resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- 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
sort – str, field to be used as a key to sort children resources
preview_size – file preview size
preview_crop – bool, allow preview crop
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- get_type(relative_path: str | None = None, /, **kwargs) str
Get resource type.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
“file” or “dir”
- get_upload_link(relative_path: str | None = None, /, **kwargs) str
Get a link to upload the file using the PUT request.
- Parameters:
relative_path – str or None, relative path to the resource
overwrite – bool, determines whether to overwrite the destination
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
str
- is_dir(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a directory.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a directory, False otherwise (even if it doesn’t exist)
- is_file(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a file.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a file, False otherwise (even if it doesn’t exist)
- 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_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
SyncResourceObject
- mkdir(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject
Create a new directory.
- Parameters:
relative_path – str or None, relative path to the directory to be created
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
DirectoryExistsError – destination path already exists
InsufficientStorageError – cannot create directory due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- move(*args, **kwargs) SyncResourceLinkObject | SyncOperationLinkObject
Move resource to dst_path. This method takes 1 or 2 positional arguments:
move(dst_path, /, **kwargs)
move(relative_path, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, source path to be moved relative to the resource
dst_path – destination path
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- patch(*args, **kwargs) SyncResourceObject
Update custom properties of a resource. This method takes 1 or 2 positional arguments:
patch(properties, /, **kwargs)
patch(relative_path, properties, /, **kwargs)
- Parameters:
relative_path – str or None, path relative to the resource
properties – dict, custom properties to update
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- 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_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
SyncPublicResourceObject
- publish(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject
Make a resource public.
- Parameters:
relative_path – str or None, relative path to the resource to be published
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
SyncResourceLinkObject
, link to the resource
- remove(relative_path: str | None = None, /, **kwargs) SyncOperationLinkObject | None
Remove the resource.
- Parameters:
relative_path – str or None, relative path to the resource to be removed
permanently – if True, the resource will be removed permanently, otherwise, it will be just moved to the trash
md5 – str, MD5 hash of the file to remove
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
BadRequestError – MD5 check is only available for files
ResourceIsLockedError – resource is locked by another request
- Returns:
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_path – str or None, source path to be renamed relative to the resource
new_name – target filename to rename to
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
ValueError – new_name is not a valid filename
- Returns:
- unpublish(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject
Make a public resource private.
- Parameters:
relative_path – str or None, relative path to the resource to be unpublished
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- 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_path – str or None, destination path relative to the resource
overwrite – if True, the resource will be overwritten if it already exists, an error will be raised otherwise
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
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_path – str or None, destination path relative to the resource
disable_redirects – bool, forbid redirects
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
InsufficientStorageError – cannot upload file due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
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_list – dict or None
yadisk –
Client
or None, YaDisk object
- Variables:
sort – str, sort type
items – list, list of resources (
SyncResourceObject
)limit – int, maximum number of elements in the list
offset – int, offset from the beginning of the list
path – str, path to the directory that contains the elements of the list
total – int, number of elements in the list
public_key – str, public key of the resource
- class yadisk.objects.resources.SyncPublicResourceObject(public_resource: dict | None = None, yadisk: Any | None = None)[source]
Bases:
PublicResourceObject
,ResourceObjectMethodsMixin
Public resource object.
- Parameters:
resource – dict or None
yadisk –
Client
or None, YaDisk object
- Variables:
antivirus_status – str, antivirus check status
file – str, download URL
size – int, file size
public_key – str, public resource key
sha256 – str, SHA256 hash
md5 – str, MD5 hash
embedded –
SyncPublicResourceObject
, list of nested resourcesname – str, filename
exif –
EXIFObject
, EXIF metadataresource_id – str, resource ID
custom_properties – dict, custom resource properties
public_url – str, public URL
share –
ShareInfoObject
, shared folder informationmodified –
datetime.datetime
, date of last modificationcreated –
datetime.datetime
, date of creationphotoslice_time –
datetime.datetime
, photo/video creation datemime_type – str, MIME type
path – str, path to the resource
preview – str, file preview URL
comment_ids –
CommentIDsObject
, comment IDstype – str, type (“file” or “dir”)
media_type – str, file type as determined by Yandex.Disk
revision – int, Yandex.Disk revision at the time of last modification
view_count – int, number of times the public resource was viewed
owner –
UserPublicInfoObject
, owner of the public resource
- 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:
copy(dst_path, /, **kwargs)
copy(relative_src_path, dst_path, /, **kwargs)
- Parameters:
relative_src_path – str or None, source path relative to the resource
dst_path – destination path
overwrite – if True the destination path can be overwritten, otherwise, an error will be raised
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
InsufficientStorageError – cannot complete request due to lack of storage space
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
- download(*args, **kwargs) SyncResourceLinkObject
Download the file. This method takes 1 or 2 positional arguments:
download(dst_path_or_file, /, **kwargs)
download(relative_path, dst_path_or_file, /, **kwargs)
If relative_path is empty or None (or not specified) this method will try to use the file attribute as a download link.
- Parameters:
relative_path – str or None, source path relative to the resource
dst_path_or_file – destination path or file-like object
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
SyncResourceLinkObject
, link to the source resource
- exists(relative_path: str | None = None, /, **kwargs) bool
Check whether resource exists.
- Parameters:
relative_path – str or None, relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
bool
- get_download_link(relative_path: str | None = None, /, **kwargs) str
Get a download link for a file (or a directory).
- Parameters:
relative_path – str or None, path relative to the resource
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
str
- get_meta(relative_path: str | None = None, /, **kwargs) SyncResourceObject
Get meta information about a file/directory.
- Parameters:
relative_path – str or None, relative path from resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- 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
sort – str, field to be used as a key to sort children resources
preview_size – file preview size
preview_crop – bool, allow preview crop
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- get_type(relative_path: str | None = None, /, **kwargs) str
Get resource type.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
“file” or “dir”
- get_upload_link(relative_path: str | None = None, /, **kwargs) str
Get a link to upload the file using the PUT request.
- Parameters:
relative_path – str or None, relative path to the resource
overwrite – bool, determines whether to overwrite the destination
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
str
- is_dir(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a directory.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a directory, False otherwise (even if it doesn’t exist)
- is_file(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a file.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a file, False otherwise (even if it doesn’t exist)
- 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_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
SyncResourceObject
- mkdir(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject
Create a new directory.
- Parameters:
relative_path – str or None, relative path to the directory to be created
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
DirectoryExistsError – destination path already exists
InsufficientStorageError – cannot create directory due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- move(*args, **kwargs) SyncResourceLinkObject | SyncOperationLinkObject
Move resource to dst_path. This method takes 1 or 2 positional arguments:
move(dst_path, /, **kwargs)
move(relative_path, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, source path to be moved relative to the resource
dst_path – destination path
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- patch(*args, **kwargs) SyncResourceObject
Update custom properties of a resource. This method takes 1 or 2 positional arguments:
patch(properties, /, **kwargs)
patch(relative_path, properties, /, **kwargs)
- Parameters:
relative_path – str or None, path relative to the resource
properties – dict, custom properties to update
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- 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_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
SyncPublicResourceObject
- publish(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject
Make a resource public.
- Parameters:
relative_path – str or None, relative path to the resource to be published
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
SyncResourceLinkObject
, link to the resource
- remove(relative_path: str | None = None, /, **kwargs) SyncOperationLinkObject | None
Remove the resource.
- Parameters:
relative_path – str or None, relative path to the resource to be removed
permanently – if True, the resource will be removed permanently, otherwise, it will be just moved to the trash
md5 – str, MD5 hash of the file to remove
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
BadRequestError – MD5 check is only available for files
ResourceIsLockedError – resource is locked by another request
- Returns:
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_path – str or None, source path to be renamed relative to the resource
new_name – target filename to rename to
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
ValueError – new_name is not a valid filename
- Returns:
- unpublish(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject
Make a public resource private.
- Parameters:
relative_path – str or None, relative path to the resource to be unpublished
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- 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_path – str or None, destination path relative to the resource
overwrite – if True, the resource will be overwritten if it already exists, an error will be raised otherwise
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
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_path – str or None, destination path relative to the resource
disable_redirects – bool, forbid redirects
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
InsufficientStorageError – cannot upload file due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
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_list – dict or None
yadisk –
Client
or None, YaDisk object
- Variables:
items – list, list of public resources (
SyncPublicResourceObject
)type – str, resource type to filter by
limit – int, maximum number of elements in the list
offset – int, offset from the beginning of the list
- class yadisk.objects.resources.SyncResourceLinkObject(link: dict | None = None, yadisk: Any | None = None)[source]
Bases:
ResourceLinkObject
,ResourceObjectMethodsMixin
Resource link object.
- Parameters:
link – dict or None
yadisk –
Client
or None, YaDisk object
- Variables:
href – str, link URL
method – str, HTTP method
templated – bool, tells whether the URL is templated
path – str, path to the resource
- 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:
copy(dst_path, /, **kwargs)
copy(relative_src_path, dst_path, /, **kwargs)
- Parameters:
relative_src_path – str or None, source path relative to the resource
dst_path – destination path
overwrite – if True the destination path can be overwritten, otherwise, an error will be raised
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
InsufficientStorageError – cannot complete request due to lack of storage space
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
- download(*args, **kwargs) SyncResourceLinkObject
Download the file. This method takes 1 or 2 positional arguments:
download(dst_path_or_file, /, **kwargs)
download(relative_path, dst_path_or_file, /, **kwargs)
If relative_path is empty or None (or not specified) this method will try to use the file attribute as a download link.
- Parameters:
relative_path – str or None, source path relative to the resource
dst_path_or_file – destination path or file-like object
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
SyncResourceLinkObject
, link to the source resource
- exists(relative_path: str | None = None, /, **kwargs) bool
Check whether resource exists.
- Parameters:
relative_path – str or None, relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
bool
- get_download_link(relative_path: str | None = None, /, **kwargs) str
Get a download link for a file (or a directory).
- Parameters:
relative_path – str or None, path relative to the resource
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
str
- get_meta(relative_path: str | None = None, /, **kwargs) SyncResourceObject
Get meta information about a file/directory.
- Parameters:
relative_path – str or None, relative path from resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- 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
sort – str, field to be used as a key to sort children resources
preview_size – file preview size
preview_crop – bool, allow preview crop
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- get_type(relative_path: str | None = None, /, **kwargs) str
Get resource type.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
“file” or “dir”
- get_upload_link(relative_path: str | None = None, /, **kwargs) str
Get a link to upload the file using the PUT request.
- Parameters:
relative_path – str or None, relative path to the resource
overwrite – bool, determines whether to overwrite the destination
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
str
- is_dir(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a directory.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a directory, False otherwise (even if it doesn’t exist)
- is_file(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a file.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a file, False otherwise (even if it doesn’t exist)
- 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_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
SyncResourceObject
- mkdir(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject
Create a new directory.
- Parameters:
relative_path – str or None, relative path to the directory to be created
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
DirectoryExistsError – destination path already exists
InsufficientStorageError – cannot create directory due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- move(*args, **kwargs) SyncResourceLinkObject | SyncOperationLinkObject
Move resource to dst_path. This method takes 1 or 2 positional arguments:
move(dst_path, /, **kwargs)
move(relative_path, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, source path to be moved relative to the resource
dst_path – destination path
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- patch(*args, **kwargs) SyncResourceObject
Update custom properties of a resource. This method takes 1 or 2 positional arguments:
patch(properties, /, **kwargs)
patch(relative_path, properties, /, **kwargs)
- Parameters:
relative_path – str or None, path relative to the resource
properties – dict, custom properties to update
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- 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_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
SyncPublicResourceObject
- publish(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject
Make a resource public.
- Parameters:
relative_path – str or None, relative path to the resource to be published
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
SyncResourceLinkObject
, link to the resource
- remove(relative_path: str | None = None, /, **kwargs) SyncOperationLinkObject | None
Remove the resource.
- Parameters:
relative_path – str or None, relative path to the resource to be removed
permanently – if True, the resource will be removed permanently, otherwise, it will be just moved to the trash
md5 – str, MD5 hash of the file to remove
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
BadRequestError – MD5 check is only available for files
ResourceIsLockedError – resource is locked by another request
- Returns:
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_path – str or None, source path to be renamed relative to the resource
new_name – target filename to rename to
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
ValueError – new_name is not a valid filename
- Returns:
- unpublish(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject
Make a public resource private.
- Parameters:
relative_path – str or None, relative path to the resource to be unpublished
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- 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_path – str or None, destination path relative to the resource
overwrite – if True, the resource will be overwritten if it already exists, an error will be raised otherwise
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
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_path – str or None, destination path relative to the resource
disable_redirects – bool, forbid redirects
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
InsufficientStorageError – cannot upload file due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
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_list – dict or None
yadisk –
Client
or None, YaDisk object
- Variables:
sort – str, sort type
items – list, list of resources (
SyncResourceObject
)limit – int, maximum number of elements in the list
offset – int, offset from the beginning of the list
path – str, path to the directory that contains the elements of the list
total – int, number of elements in the list
- class yadisk.objects.resources.SyncResourceObject(resource: dict | None = None, yadisk: Any | None = None)[source]
Bases:
ResourceObject
,ResourceObjectMethodsMixin
Resource object.
- Parameters:
resource – dict or None
yadisk –
Client
or None, YaDisk object
- Variables:
antivirus_status – str, antivirus check status
file – str, download URL
size – int, file size
public_key – str, public resource key
sha256 – str, SHA256 hash
md5 – str, MD5 hash
embedded –
SyncResourceListObject
, list of nested resourcesname – str, filename
exif –
EXIFObject
, EXIF metadataresource_id – str, resource ID
custom_properties – dict, custom resource properties
public_url – str, public URL
share –
ShareInfoObject
, shared folder informationmodified –
datetime.datetime
, date of last modificationcreated –
datetime.datetime
, date of creationphotoslice_time –
datetime.datetime
, photo/video creation datemime_type – str, MIME type
path – str, path to the resource
preview – str, file preview URL
comment_ids –
CommentIDsObject
, comment IDstype – str, type (“file” or “dir”)
media_type – str, file type as determined by Yandex.Disk
revision – int, Yandex.Disk revision at the time of last modification
- 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:
copy(dst_path, /, **kwargs)
copy(relative_src_path, dst_path, /, **kwargs)
- Parameters:
relative_src_path – str or None, source path relative to the resource
dst_path – destination path
overwrite – if True the destination path can be overwritten, otherwise, an error will be raised
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
InsufficientStorageError – cannot complete request due to lack of storage space
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
- download(*args, **kwargs) SyncResourceLinkObject
Download the file. This method takes 1 or 2 positional arguments:
download(dst_path_or_file, /, **kwargs)
download(relative_path, dst_path_or_file, /, **kwargs)
If relative_path is empty or None (or not specified) this method will try to use the file attribute as a download link.
- Parameters:
relative_path – str or None, source path relative to the resource
dst_path_or_file – destination path or file-like object
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
SyncResourceLinkObject
, link to the source resource
- exists(relative_path: str | None = None, /, **kwargs) bool
Check whether resource exists.
- Parameters:
relative_path – str or None, relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
bool
- get_download_link(relative_path: str | None = None, /, **kwargs) str
Get a download link for a file (or a directory).
- Parameters:
relative_path – str or None, path relative to the resource
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
str
- get_meta(relative_path: str | None = None, /, **kwargs) SyncResourceObject
Get meta information about a file/directory.
- Parameters:
relative_path – str or None, relative path from resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- 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
sort – str, field to be used as a key to sort children resources
preview_size – file preview size
preview_crop – bool, allow preview crop
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- get_type(relative_path: str | None = None, /, **kwargs) str
Get resource type.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
“file” or “dir”
- get_upload_link(relative_path: str | None = None, /, **kwargs) str
Get a link to upload the file using the PUT request.
- Parameters:
relative_path – str or None, relative path to the resource
overwrite – bool, determines whether to overwrite the destination
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
str
- is_dir(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a directory.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a directory, False otherwise (even if it doesn’t exist)
- is_file(relative_path: str | None = None, /, **kwargs) bool
Check whether resource is a file.
- Parameters:
relative_path – relative path from the resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a file, False otherwise (even if it doesn’t exist)
- 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_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
SyncResourceObject
- mkdir(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject
Create a new directory.
- Parameters:
relative_path – str or None, relative path to the directory to be created
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
DirectoryExistsError – destination path already exists
InsufficientStorageError – cannot create directory due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- move(*args, **kwargs) SyncResourceLinkObject | SyncOperationLinkObject
Move resource to dst_path. This method takes 1 or 2 positional arguments:
move(dst_path, /, **kwargs)
move(relative_path, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, source path to be moved relative to the resource
dst_path – destination path
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- patch(*args, **kwargs) SyncResourceObject
Update custom properties of a resource. This method takes 1 or 2 positional arguments:
patch(properties, /, **kwargs)
patch(relative_path, properties, /, **kwargs)
- Parameters:
relative_path – str or None, path relative to the resource
properties – dict, custom properties to update
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- 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_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
SyncPublicResourceObject
- publish(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject
Make a resource public.
- Parameters:
relative_path – str or None, relative path to the resource to be published
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
SyncResourceLinkObject
, link to the resource
- remove(relative_path: str | None = None, /, **kwargs) SyncOperationLinkObject | None
Remove the resource.
- Parameters:
relative_path – str or None, relative path to the resource to be removed
permanently – if True, the resource will be removed permanently, otherwise, it will be just moved to the trash
md5 – str, MD5 hash of the file to remove
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
BadRequestError – MD5 check is only available for files
ResourceIsLockedError – resource is locked by another request
- Returns:
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_path – str or None, source path to be renamed relative to the resource
new_name – target filename to rename to
overwrite – bool, determines whether to overwrite the destination
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
ValueError – new_name is not a valid filename
- Returns:
- unpublish(relative_path: str | None = None, /, **kwargs) SyncResourceLinkObject
Make a public resource private.
- Parameters:
relative_path – str or None, relative path to the resource to be unpublished
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- 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_path – str or None, destination path relative to the resource
overwrite – if True, the resource will be overwritten if it already exists, an error will be raised otherwise
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
InsufficientStorageError – cannot upload file due to lack of storage space
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
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_path – str or None, destination path relative to the resource
disable_redirects – bool, forbid redirects
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ParentNotFoundError – parent directory doesn’t exist
PathExistsError – destination path already exists
InsufficientStorageError – cannot upload file due to lack of storage space
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
UploadTrafficLimitExceededError – upload limit has been exceeded
- Returns:
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_list – dict or None
yadisk –
Client
or None, YaDisk object
- Variables:
sort – str, sort type
items – list, list of resources (
SyncTrashResourceObject
)limit – int, maximum number of elements in the list
offset – int, offset from the beginning of the list
path – str, path to the directory that contains the elements of the list
total – int, number of elements in the list
- class yadisk.objects.resources.SyncTrashResourceObject(trash_resource: dict | None = None, yadisk: Any | None = None)[source]
Bases:
TrashResourceObject
Trash resource object.
- Parameters:
trash_resource – dict or None
yadisk –
Client
or None, YaDisk object
- Variables:
antivirus_status – str, antivirus check status
file – str, download URL
size – int, file size
public_key – str, public resource key
sha256 – str, SHA256 hash
md5 – str, MD5 hash
embedded –
SyncTrashResourceListObject
, list of nested resourcesname – str, filename
exif –
EXIFObject
, EXIF metadataresource_id – str, resource ID
custom_properties – dict, custom resource properties
public_url – str, public URL
share –
ShareInfoObject
, shared folder informationmodified –
datetime.datetime
, date of last modificationcreated –
datetime.datetime
, date of creationphotoslice_time –
datetime.datetime
, photo/video creation datemime_type – str, MIME type
path – str, path to the resource
preview – str, file preview URL
comment_ids –
CommentIDsObject
, comment IDstype – str, type (“file” or “dir”)
media_type – str, file type as determined by Yandex.Disk
revision – int, Yandex.Disk revision at the time of last modification
origin_path – str, original path
deleted –
datetime.datetime
, date of deletion
- exists(relative_path: str | None = None, /, **kwargs) bool [source]
Check whether the trash resource exists.
- Parameters:
relative_path – str or None, relative path to the trash resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
bool
- get_meta(relative_path: str | None = None, /, **kwargs) SyncTrashResourceObject [source]
Get meta information about a trash resource.
- Parameters:
relative_path – str or None, relative path to the trash resource
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
sort – str, field to be used as a key to sort children resources
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
- get_type(relative_path: str | None = None, /, **kwargs) str [source]
Get trash resource type.
- Parameters:
relative_path – str or None, relative path to the trash resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
“file” or “dir”
- is_dir(relative_path: str | None = None, /, **kwargs) bool [source]
Check whether resource is a trash directory.
- Parameters:
relative_path – str or None, relative path to the trash resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a directory, False otherwise (even if it doesn’t exist)
- is_file(relative_path: str | None = None, /, **kwargs) bool [source]
Check whether resource is a trash file.
- Parameters:
relative_path – str or None, relative path to the trash resource
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
ForbiddenError – application doesn’t have enough rights for this request
- Returns:
True if path is a file, False otherwise (even if it doesn’t exist)
- listdir(relative_path: str | None = None, /, **kwargs) Generator[SyncTrashResourceObject, None, None] [source]
Get contents of a trash resource.
- Parameters:
relative_path – str or None, relative path to the directory in the trash bin
limit – number of children resources to be included in the response
offset – number of children resources to be skipped in the response
preview_size – size of the file preview
preview_crop – bool, cut the preview to the size specified in the preview_size
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
WrongResourceTypeError – resource is not a directory
- Returns:
generator of
SyncTrashResourceObject
- remove(relative_path: str | None = None, /, **kwargs) SyncOperationLinkObject | None [source]
Remove a trash resource.
- Parameters:
relative_path – str or None, relative path to the trash resource to be deleted
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
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:
restore(dst_path, /, **kwargs)
restore(relative_path=None, dst_path, /, **kwargs)
- Parameters:
relative_path – str or None, relative path to the trash resource to be restored
dst_path – destination path
overwrite – bool, determines whether the destination can be overwritten
force_async – forces the operation to be executed asynchronously
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
PathNotFoundError – resource was not found on Disk
PathExistsError – destination path already exists
ForbiddenError – application doesn’t have enough rights for this request
ResourceIsLockedError – resource is locked by another request
- Returns:
- class yadisk.objects.resources.TrashResourceListObject(trash_resource_list: dict | None = None, yadisk: Any | None = None)[source]
Bases:
ResourceListObject
List of trash resources.
- Parameters:
trash_resource_list – dict or None
yadisk –
Client
/AsyncClient
or None, YaDisk object
- Variables:
sort – str, sort type
items – list, list of resources (
TrashResourceObject
)limit – int, maximum number of elements in the list
offset – int, offset from the beginning of the list
path – str, path to the directory that contains the elements of the list
total – int, number of elements in the list
- class yadisk.objects.resources.TrashResourceObject(trash_resource: dict | None = None, yadisk: Any | None = None)[source]
Bases:
ResourceObject
Trash resource object.
- Parameters:
trash_resource – dict or None
yadisk –
Client
/AsyncClient
or None, YaDisk object
- Variables:
antivirus_status – str, antivirus check status
file – str, download URL
size – int, file size
public_key – str, public resource key
sha256 – str, SHA256 hash
md5 – str, MD5 hash
embedded –
TrashResourceListObject
, list of nested resourcesname – str, filename
exif –
EXIFObject
, EXIF metadataresource_id – str, resource ID
custom_properties – dict, custom resource properties
public_url – str, public URL
share –
ShareInfoObject
, shared folder informationmodified –
datetime.datetime
, date of last modificationcreated –
datetime.datetime
, date of creationphotoslice_time –
datetime.datetime
, photo/video creation datemime_type – str, MIME type
path – str, path to the resource
preview – str, file preview URL
comment_ids –
CommentIDsObject
, comment IDstype – str, type (“file” or “dir”)
media_type – str, file type as determined by Yandex.Disk
revision – int, Yandex.Disk revision at the time of last modification
origin_path – str, original path
deleted –
datetime.datetime
, date of deletion
- class yadisk.objects.link_object.LinkObject(link: dict | None = None, yadisk: Any | None = None)[source]
Bases:
YaDiskObject
Link object.
- Parameters:
link – dict or None
yadisk –
Client
/AsyncClient
or None, YaDisk object
- Variables:
href – str, link URL
method – str, HTTP method
templated – bool, tells whether the URL is templated
- class yadisk.objects.operations.AsyncOperationLinkObject(link: dict | None = None, yadisk: Any | None = None)[source]
Bases:
OperationLinkObject
Operation link object.
- Parameters:
link – dict or None
yadisk –
AsyncClient
or None, YaDisk object
- Variables:
href – str, link URL
method – str, HTTP method
templated – bool, tells whether the URL is templated
- async get_status(**kwargs) str [source]
Get operation status.
- Parameters:
fields – list of keys to be included in the response
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
OperationNotFoundError – requested operation was not found
- Returns:
str,
"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:
link – dict or None
yadisk –
Client
/AsyncClient
or None, YaDisk object
- Variables:
href – str, link URL
method – str, HTTP method
templated – bool, 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_status – dict or None
yadisk –
YaDisk
or None, YaDisk object
- Variables:
type – str, type of the operation
status – str, status of the operation
operation_id – str, ID of the operation
link –
LinkObject
, link to the operationdata – dict, other information about the operation
- class yadisk.objects.operations.SyncOperationLinkObject(link: dict | None = None, yadisk: Any | None = None)[source]
Bases:
OperationLinkObject
Operation link object.
- Parameters:
link – dict or None
yadisk –
Client
or None, YaDisk object
- Variables:
href – str, link URL
method – str, HTTP method
templated – bool, 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
timeout – float or tuple, request timeout
headers – dict or None, additional request headers
n_retries – int, maximum number of retries
retry_interval – delay between retries in seconds
- Raises:
OperationNotFoundError – requested operation was not found
- Returns:
str,
"in-progress"
indicates that the operation is currently running,"success"
indicates that the operation was successful,"failed"
means that the operation failed