Documentation

class yadisk.YaDisk(id='', secret='', token='')[source]

Implements access to Yandex.Disk REST API.

Parameters:
  • id – application ID
  • secret – application secret password
  • token – application token
Variables:
  • idstr, application ID
  • secretstr, application secret password
  • tokenstr, application token
check_token(token=None, **kwargs)[source]

Check whether the token is valid.

Parameters:
  • token – token to check, equivalent to self.token if None
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

bool

clear_session_cache()[source]

Clears the session cache. Unused sessions will be closed.

copy(src_path, dst_path, **kwargs)[source]

Copy src_path to dst_path. If the operation is performed asynchronously, returns the link to the operation, otherwise, returns the link to the newly created resource.

Parameters:
  • src_path – source path
  • dst_path – destination path
  • overwrite – if True the destination path can be overwritten, otherwise, an error will be raised
  • force_async – forces the operation to be executed asynchronously
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

LinkObject or OperationLinkObject

download(src_path, path_or_file, **kwargs)[source]

Download the file.

Parameters:
  • src_path – source path
  • path_or_file – destination path or file-like object
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
download_public(public_key, file_or_path, **kwargs)[source]

Download the public resource.

Parameters:
  • public_key – public key or public URL of the resource
  • file_or_path – destination path or file-like object
  • path – relative path to the resource within the public folder
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
exists(path, **kwargs)[source]

Check whether path exists.

Parameters:
  • path – path to the resource
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

bool

get_auth_url(**kwargs)[source]

Get authentication URL for the user to go to.

Parameters:
  • type – response type (“code” to get the confirmation code or “token” to get the token automatically)
  • device_id – unique device ID, must be between 6 and 50 characters
  • device_name – device name, should not be longer than 100 characters
  • display – indicates whether to use lightweight layout, values other than “popup” are ignored
  • login_hint – username or email for the account the token is being requested for
  • scope – list of permissions for the application
  • optional_scope – list of optional permissions for the application
  • force_confirm – if True, user will be required to confirm access to the account even if the user has already granted access for the application
  • state – The state string, which Yandex.OAuth returns without any changes (<= 1024 characters)
Returns:

authentication URL

get_code_url(**kwargs)[source]

Get the URL for the user to get the confirmation code. The confirmation code can later be used to get the token.

Parameters:
  • device_id – unique device ID, must be between 6 and 50 characters
  • device_name – device name, should not be longer than 100 characters
  • display – indicates whether to use lightweight layout, values other than “popup” are ignored
  • login_hint – username or email for the account the token is being requested for
  • scope – list of permissions for the application
  • optional_scope – list of optional permissions for the application
  • force_confirm – if True, user will be required to confirm access to the account even if the user has already granted access for the application
  • state – The state string, which Yandex.OAuth returns without any changes (<= 1024 characters)
Returns:

authentication URL

get_disk_info(**kwargs)[source]

Get disk information.

Parameters:
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

DiskInfoObject

Get a download link for a file (or a directory).

Parameters:
  • path – path to the resource
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

str

get_files(**kwargs)[source]

Get a flat list of all files (that doesn’t include directories).

Parameters:
  • offset – offset from the beginning of the list
  • limit – number of list elements to be included
  • media_type – type of files to include in the list
  • sortstr, field to be used as a key to sort children resources
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

generator of ResourceObject

get_last_uploaded(**kwargs)[source]

Get the list of latest uploaded files sorted by upload date.

Parameters:
  • limit – maximum number of elements in the list
  • media_type – type of files to include in the list
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

generator of LastUploadedResourceListObject

get_meta(path, **kwargs)[source]

Get meta information about a file/directory.

Parameters:
  • path – path to the resource
  • limit – number of children resources to be included in the response
  • offset – number of children resources to be skipped in the response
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • sortstr, field to be used as a key to sort children resources
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

ResourceObject

get_operation_status(operation_id, **kwargs)[source]

Get operation status.

Parameters:
  • operation_id – ID of the operation or a link
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

str

Get a download link for a public resource.

Parameters:
  • public_key – public key or public URL of the resource
  • path – relative path to the resource within the public folder
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

str

get_public_meta(public_key, **kwargs)[source]

Get meta-information about a public resource.

Parameters:
  • public_key – public key or public URL of the resource
  • path – relative path to a resource in a public folder. By specifying the key of the published folder in public_key, you can request metainformation for any resource in the folder.
  • offset – offset from the beginning of the list of nested resources
  • limit – maximum number of nested elements to be included in the list
  • sortstr, field to be used as a key to sort children resources
  • preview_size – file preview size
  • preview_cropbool, allow preview crop
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

PublicResourceObject

get_public_resources(**kwargs)[source]

Get a list of public resources.

Parameters:
  • offset – offset from the beginning of the list
  • limit – maximum number of elements in the list
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • type – filter based on type of resources (“file” or “dir”)
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

PublicResourcesListObject

get_public_type(public_key, **kwargs)[source]

Get public resource type.

Parameters:
  • public_key – public key or public URL of the resource
  • path – relative path to the resource within the public folder
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

“file” or “dir”

get_session(token=None)[source]

Like YaDisk.make_session but wrapped in functools.lru_cache.

Returns:requests.Session, different instances for different threads
get_token(code, **kwargs)[source]

Get a new token.

Parameters:
  • code – confirmation code
  • device_id – unique device ID (between 6 and 50 characters)
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

TokenObject

get_trash_meta(path, **kwargs)[source]

Get meta information about a trash resource.

Parameters:
  • path – path to the trash resource
  • limit – number of children resources to be included in the response
  • offset – number of children resources to be skipped in the response
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • sortstr, field to be used as a key to sort children resources
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

TrashResourceObject

get_trash_type(path, **kwargs)[source]

Get trash resource type.

Parameters:
  • path – path to the trash resource
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

“file” or “dir”

get_type(path, **kwargs)[source]

Get resource type.

Parameters:
  • path – path to the resource
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

“file” or “dir”

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

Parameters:
  • path – destination path
  • overwritebool, determines whether to overwrite the destination
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

str

is_dir(path, **kwargs)[source]

Check whether path is a directory.

Parameters:
  • path – path to the resource
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

True if path is a directory, False otherwise (even if it doesn’t exist)

is_file(path, **kwargs)[source]

Check whether path is a file.

Parameters:
  • path – path to the resource
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

True if path is a file, False otherwise (even if it doesn’t exist)

is_public_dir(public_key, **kwargs)[source]

Check whether public_key is a public directory.

Parameters:
  • public_key – public key or public URL of the resource
  • path – relative path to the resource within the public folder
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

True if public_key is a directory, False otherwise (even if it doesn’t exist)

is_public_file(public_key, **kwargs)[source]

Check whether public_key is a public file.

Parameters:
  • public_key – public key or public URL of the resource
  • path – relative path to the resource within the public folder
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

True if public_key is a file, False otherwise (even if it doesn’t exist)

is_trash_dir(path, **kwargs)[source]

Check whether path is a trash directory.

Parameters:
  • path – path to the trash resource
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

True if path is a directory, False otherwise (even if it doesn’t exist)

is_trash_file(path, **kwargs)[source]

Check whether path is a trash file.

Parameters:
  • path – path to the trash resource
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

True if path is a directory, False otherwise (even if it doesn’t exist)

listdir(path, **kwargs)[source]

Get contents of path.

Parameters:
  • path – path to the directory
  • limit – number of children resources to be included in the response
  • offset – number of children resources to be skipped in the response
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

generator of ResourceObject

make_session(token=None)[source]

Prepares requests.Session object with headers needed for API.

Parameters:token – application token, equivalent to self.token if None
Returns:requests.Session
mkdir(path, **kwargs)[source]

Create a new directory.

Parameters:
  • path – path to the directory to be created
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

LinkObject

move(src_path, dst_path, **kwargs)[source]

Move src_path to dst_path.

Parameters:
  • src_path – source path to be moved
  • dst_path – destination path
  • overwritebool, determines whether to overwrite the destination
  • force_async – forces the operation to be executed asynchronously
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

OperationLinkObject or LinkObject

patch(path, properties, **kwargs)[source]

Update custom properties of a resource.

Parameters:
  • path – path to the resource
  • propertiesdict, custom properties to update
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

ResourceObject

public_exists(public_key, **kwargs)[source]

Check whether the public resource exists.

Parameters:
  • public_key – public key or public URL of the resource
  • path – relative path to the resource within the public folder
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

bool

public_listdir(public_key, **kwargs)[source]

Get contents of a public directory.

Parameters:
  • public_key – public key or public URL of the resource
  • path – relative path to the resource in the public folder. By specifying the key of the published folder in public_key, you can request contents of any nested folder.
  • limit – number of children resources to be included in the response
  • offset – number of children resources to be skipped in the response
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

generator of PublicResourceObject

publish(path, **kwargs)[source]

Make a resource public.

Parameters:
  • path – path to the resource to be published
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

LinkObject, link to the resource

refresh_token(refresh_token, **kwargs)[source]

Refresh an existing token.

Parameters:
  • refresh_token – the refresh token that was received with the token
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

TokenObject

remove(path, **kwargs)[source]

Remove the resource.

Parameters:
  • path – path to the resource to be removed
  • permanently – if True, the resource will be removed permanently, otherwise, it will be just moved to the trash
  • md5str, MD5 hash of the file to remove
  • force_async – forces the operation to be executed asynchronously
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

OperationLinkObject if the operation is performed asynchronously, None otherwise

remove_trash(path, **kwargs)[source]

Remove a trash resource.

Parameters:
  • path – path to the trash resource to be deleted
  • force_async – forces the operation to be executed asynchronously
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

OperationLinkObject if the operation is performed asynchronously, None otherwise

restore_trash(path, dst_path=None, **kwargs)[source]

Restore a trash resource. Returns a link to the newly created resource or a link to the asynchronous operation.

Parameters:
  • path – path to the trash resource to restore
  • dst_path – destination path
  • overwritebool, determines whether the destination can be overwritten
  • force_async – forces the operation to be executed asynchronously
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

LinkObject or OperationLinkObject

revoke_token(token=None, **kwargs)[source]

Revoke the token.

Parameters:
  • token – token to revoke, equivalent to self.token if None
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

TokenRevokeStatusObject

save_to_disk(public_key, **kwargs)[source]

Saves a public resource to the disk. Returns the link to the operation if it’s performed asynchronously, or a link to the resource otherwise.

Parameters:
  • public_key – public key or public URL of the resource
  • name – filename of the saved resource
  • path – path to the copied resource in the public folder
  • save_path – path to the destination directory (downloads directory by default)
  • force_async – forces the operation to be executed asynchronously
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

LinkObject or OperationLinkObject

trash_exists(path, **kwargs)[source]

Check whether the trash resource at path exists.

Parameters:
  • path – path to the trash resource
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

bool

trash_listdir(path, **kwargs)[source]

Get contents of a trash resource.

Parameters:
  • path – path to the directory in the trash bin
  • limit – number of children resources to be included in the response
  • offset – number of children resources to be skipped in the response
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

generator of TrashResourceObject

unpublish(path, **kwargs)[source]

Make a public resource private.

Parameters:
  • path – path to the resource to be unpublished
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

LinkObject, link to the resource

upload(path_or_file, dst_path, **kwargs)[source]

Upload a file to disk.

Parameters:
  • path_or_file – path or file-like object to be uploaded
  • dst_path – destination path
  • overwrite – if True, the resource will be overwritten if it already exists, an error will be raised otherwise
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
upload_url(url, path, **kwargs)[source]

Upload a file from URL.

Parameters:
  • url – source URL
  • path – destination path
  • disable_redirectsbool, forbid redirects
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

OperationLinkObject, link to the asynchronous operation

General parameters

Almost all methods of YaDisk (the ones that accept **kwargs) accept some additional arguments:

  • n_retries - int, maximum number of retries for a request
  • retry_delay - float, delay between retries (in seconds)
  • headers - dict or None, additional request headers

requests parameters like timeout, proxies, etc. are also accepted (see requests.request()).

This also applies to low-level functions and API request objects as well.

Settings

The following settings can be accessed and changed at runtime in yadisk.settings module:

  • DEFAULT_TIMEOUT - tuple of 2 numbers (int or float`), default timeout for requests. First number is the connect timeout, the second one is the read timeout.
  • DEFAULT_N_RETRIES - int, default number of retries
  • DEFAULT_RETRY_INTERVAL - float, default retry interval
  • DEFAULT_UPLOAD_TIMEOUT - analogous to DEFAULT_TIMEOUT but for upload function
  • DEFAULT_UPLOAD_RETRY_INTERVAL - analogous to DEFAULT_RETRY_INTERVAL but for upload function

Exceptions

Aside from the exceptions listed below, API requests can also raise exceptions in requests.

exception yadisk.exceptions.YaDiskError(error_type=None, msg='', response=None)[source]

Bases: Exception

Base class for all exceptions in this library.

Variables:
  • error_typestr, unique error code as returned by API
  • response – an instance of requests.Response
Parameters:
  • error_typestr, unique error code as returned by API
  • msgstr, exception message
  • response – an instance of requests.Response
exception yadisk.exceptions.RetriableYaDiskError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.YaDiskError

Thrown when there was an error but it would make sense to retry the request.

exception yadisk.exceptions.UnknownYaDiskError(msg='', response=None)[source]

Bases: yadisk.exceptions.RetriableYaDiskError

Thrown when the request failed but the response does not contain any error info.

exception yadisk.exceptions.WrongResourceTypeError(msg='')[source]

Bases: yadisk.exceptions.YaDiskError

Thrown when the resource was expected to be of different type (e.g., file instead of directory).

exception yadisk.exceptions.BadRequestError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.YaDiskError

Thrown when the server returns code 400.

exception yadisk.exceptions.UnauthorizedError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.YaDiskError

Thrown when the server returns code 401.

exception yadisk.exceptions.ForbiddenError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.YaDiskError

Thrown when the server returns code 403.

exception yadisk.exceptions.NotFoundError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.YaDiskError

Thrown when the server returns code 404.

exception yadisk.exceptions.NotAcceptableError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.YaDiskError

Thrown when the server returns code 406.

exception yadisk.exceptions.ConflictError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.YaDiskError

Thrown when the server returns code 409.

exception yadisk.exceptions.UnsupportedMediaError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.YaDiskError

Thrown when the server returns code 415.

exception yadisk.exceptions.LockedError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.YaDiskError

Thrown when the server returns code 423.

exception yadisk.exceptions.TooManyRequestsError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.YaDiskError

Thrown when the server returns code 429.

exception yadisk.exceptions.InternalServerError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.RetriableYaDiskError

Thrown when the server returns code 500.

exception yadisk.exceptions.BadGatewayError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.RetriableYaDiskError

Thrown when the server returns code 502

exception yadisk.exceptions.UnavailableError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.RetriableYaDiskError

Thrown when the server returns code 503.

exception yadisk.exceptions.GatewayTimeoutError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.RetriableYaDiskError

Thrown when the server returns code 504

exception yadisk.exceptions.InsufficientStorageError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.YaDiskError

Thrown when the server returns code 509.

exception yadisk.exceptions.PathNotFoundError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.NotFoundError

Thrown when the requested path does not exist.

exception yadisk.exceptions.ParentNotFoundError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.ConflictError

Thrown by mkdir, upload, etc. when the parent directory doesn’t exist.

exception yadisk.exceptions.PathExistsError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.ConflictError

Thrown when the requested path already exists.

exception yadisk.exceptions.DirectoryExistsError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.PathExistsError

Thrown when the directory already exists.

exception yadisk.exceptions.FieldValidationError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.BadRequestError

Thrown when the request contains fields with invalid data.

exception yadisk.exceptions.ResourceIsLockedError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.LockedError

Thrown when the resource is locked by another operation.

exception yadisk.exceptions.MD5DifferError(error_type=None, msg='', response=None)[source]

Bases: yadisk.exceptions.ConflictError

Thrown when the MD5 hash of the file to be deleted doesn’t match with the actual one.

Objects

class yadisk.objects.YaDiskObject(field_types=None)[source]

Base class for all objects mirroring the ones returned by Yandex.Disk REST API. It must have a fixed number of fields, each field must have a type. It also supports subscripting and access of fields through the . operator.

Parameters:field_typesdict or None
import_fields(source_dict)[source]

Set all the fields of the object to the values in source_dict. All the other fields are ignored

Parameters:source_dictdict or None (nothing will be done in that case)
remove_alias(alias)[source]

Remove an alias.

Parameters:aliasstr
remove_field(field)[source]

Remove field.

Parameters:fieldstr
set_alias(alias, name)[source]

Set an alias.

Parameters:
  • aliasstr, alias to add
  • namestr, field name
set_field_type(field, type)[source]

Set field type.

Parameters:
  • fieldstr
  • type – type or factory
set_field_types(field_types)[source]

Set the field types of the object

Parameters:field_typesdict, where keys are the field names and values are types (or factories)
class yadisk.objects.ErrorObject(error=None)[source]

Bases: yadisk.objects.yadisk_object.YaDiskObject

Mirrors Yandex.Disk REST API error object.

Parameters:

errordict or None

Variables:
  • messagestr, human-readable error message
  • descriptionstr, technical error description
  • errorstr, error code
class yadisk.objects.auth.TokenObject(token=None)[source]

Bases: yadisk.objects.yadisk_object.YaDiskObject

Token object.

Parameters:

tokendict or None

Variables:
  • access_tokenstr, token string
  • refresh_tokenstr, the refresh-token
  • token_typestr, type of the token
  • expires_inint, amount of time before the token expires
class yadisk.objects.auth.TokenRevokeStatusObject(token_revoke_status=None)[source]

Bases: yadisk.objects.yadisk_object.YaDiskObject

Result of token revocation request.

Parameters:token_revoke_statusdict or None
Variables:statusstr, status of the operation
class yadisk.objects.disk.DiskInfoObject(disk_info=None)[source]

Bases: yadisk.objects.yadisk_object.YaDiskObject

Disk information object.

Parameters:

disk_infodict or None

Variables:
  • max_file_sizeint, maximum supported file size (bytes)
  • unlimited_autoupload_enabledbool, tells whether unlimited autoupload from mobile devices is enabled
  • total_spaceint, total disk size (bytes)
  • trash_sizeint, amount of space used by trash (bytes), part of used_space
  • is_paidbool, tells if the account is paid or not
  • used_spaceint, amount of space used (bytes)
  • system_foldersSystemFoldersObject, paths to the system folders
  • userUserObject, owner of the disk
  • revisionint, current revision of Yandex.Disk
class yadisk.objects.disk.SystemFoldersObject(system_folders=None)[source]

Bases: yadisk.objects.yadisk_object.YaDiskObject

Object, containing paths to system folders.

Parameters:

system_foldersdict or None

Variables:
  • odnoklassnikistr, path to the Odnoklassniki folder
  • googlestr, path to the Google+ folder
  • instagramstr, path to the Instagram folder
  • vkontaktestr, path to the VKontakte folder
  • mailrustr, path to the My World folder
  • facebookstr, path to the Facebook folder
  • socialstr, path to the social networks folder
  • screenshotsstr, path to the screenshot folder
  • photostreamstr, path to the camera folder
class yadisk.objects.disk.UserObject(user=None)[source]

Bases: yadisk.objects.yadisk_object.YaDiskObject

User object.

Parameters:

userdict or None

Variables:
  • countrystr, user’s country
  • loginstr, user’s login
  • display_namestr, user’s display name
  • uidstr, user’s UID
class yadisk.objects.disk.UserPublicInfoObject(public_user_info=None)[source]

Bases: yadisk.objects.disk.UserObject

Public user information object. Inherits from UserObject for compatibility.

Parameters:

public_user_infodict or None

Variables:
  • loginstr, user’s login
  • display_namestr, user’s display name
  • uidstr, user’s UID
class yadisk.objects.resources.CommentIDsObject(comment_ids=None)[source]

Bases: yadisk.objects.yadisk_object.YaDiskObject

Comment IDs object.

Parameters:

comment_idsdict or None

Variables:
  • private_resourcestr, comment ID for private resources
  • public_resourcestr, comment ID for public resources
class yadisk.objects.resources.EXIFObject(exif=None)[source]

Bases: yadisk.objects.yadisk_object.YaDiskObject

EXIF metadata object.

Parameters:exifdict or None
Variables:date_timedatetime.datetime, capture date
class yadisk.objects.resources.FilesResourceListObject(files_resource_list=None)[source]

Bases: yadisk.objects.yadisk_object.YaDiskObject

Flat list of files.

Parameters:

files_resource_listdict or None

Variables:
  • itemslist, flat list of files (ResourceObject)
  • limitint, maximum number of elements in the list
  • offsetint, offset from the beginning of the list
class yadisk.objects.resources.LastUploadedResourceListObject(last_uploaded_resources_list=None)[source]

Bases: yadisk.objects.yadisk_object.YaDiskObject

List of last uploaded resources.

Parameters:

last_uploaded_resources_listdict or None

Variables:
  • itemslist, list of resources (ResourceObject)
  • limitint, maximum number of elements in the list
class yadisk.objects.resources.LinkObject(link=None)[source]

Bases: yadisk.objects.yadisk_object.YaDiskObject

Link object.

Parameters:

linkdict or None

Variables:
  • hrefstr, link URL
  • methodstr, HTTP method
  • templatedbool, tells whether the URL is templated
class yadisk.objects.resources.OperationLinkObject(link=None)[source]

Bases: yadisk.objects.resources.LinkObject

Operation link object.

Parameters:

linkdict or None

Variables:
  • hrefstr, link URL
  • methodstr, HTTP method
  • templatedbool, tells whether the URL is templated
class yadisk.objects.resources.PublicResourcesListObject(public_resources_list=None)[source]

Bases: yadisk.objects.yadisk_object.YaDiskObject

List of public resources.

Parameters:

public_resources_listdict or None

Variables:
  • itemslist, list of public resources (PublicResourceObject)
  • typestr, resource type to filter by
  • limitint, maximum number of elements in the list
  • offsetint, offset from the beginning of the list
class yadisk.objects.resources.ResourceListObject(resource_list=None)[source]

Bases: yadisk.objects.yadisk_object.YaDiskObject

List of resources.

Parameters:

resource_listdict or None

Variables:
  • sortstr, sort type
  • itemslist, list of resources (ResourceObject)
  • limitint, maximum number of elements in the list
  • offsetint, offset from the beginning of the list
  • pathstr, path to the directory that contains the elements of the list
  • totalint, number of elements in the list
class yadisk.objects.resources.ResourceObject(resource=None)[source]

Bases: yadisk.objects.yadisk_object.YaDiskObject

Resource object.

Parameters:

resourcedict or None

Variables:
  • antivirus_statusstr, antivirus check status
  • filestr, download URL
  • sizeint, file size
  • public_keystr, public resource key
  • sha256str, SHA256 hash
  • md5str, MD5 hash
  • embeddedResourceListObject, list of nested resources
  • namestr, filename
  • exifEXIFObject, EXIF metadata
  • resource_idstr, resource ID
  • custom_propertiesdict, custom resource properties
  • public_urlstr, public URL
  • shareShareInfoObject, shared folder information
  • modifieddatetime.datetime, date of last modification
  • createddatetime.datetime, date of creation
  • photoslice_timedatetime.datetime, photo/video creation date
  • mime_typestr, MIME type
  • pathstr, path to the resource
  • previewstr, file preview URL
  • comment_idsCommentIDsObject, comment IDs
  • typestr, type (“file” or “dir”)
  • media_typestr, file type as determined by Yandex.Disk
  • revisionint, Yandex.Disk revision at the time of last modification
class yadisk.objects.resources.ResourceUploadLinkObject(resource_upload_link=None)[source]

Bases: yadisk.objects.resources.LinkObject

Resource upload link.

Parameters:

resource_upload_linkdict or None

Variables:
  • operation_idstr, ID of the upload operation
  • hrefstr, link URL
  • methodstr, HTTP method
  • templatedbool, tells whether the URL is templated
class yadisk.objects.resources.ShareInfoObject(share_info=None)[source]

Bases: yadisk.objects.yadisk_object.YaDiskObject

Shared folder information object.

Parameters:

share_infodict or None

Variables:
  • is_rootbool, tells whether the folder is root
  • is_ownedbool, tells whether the user is the owner of this directory
  • rightsstr, access rights
class yadisk.objects.resources.PublicResourceObject(public_resource=None)[source]

Bases: yadisk.objects.resources.ResourceObject

Public resource object.

Parameters:

resourcedict or None

Variables:
  • antivirus_statusstr, antivirus check status
  • filestr, download URL
  • sizeint, file size
  • public_keystr, public resource key
  • sha256str, SHA256 hash
  • md5str, MD5 hash
  • embeddedPublicResourceObject, list of nested resources
  • namestr, filename
  • exifEXIFObject, EXIF metadata
  • resource_idstr, resource ID
  • custom_propertiesdict, custom resource properties
  • public_urlstr, public URL
  • shareShareInfoObject, shared folder information
  • modifieddatetime.datetime, date of last modification
  • createddatetime.datetime, date of creation
  • photoslice_timedatetime.datetime, photo/video creation date
  • mime_typestr, MIME type
  • pathstr, path to the resource
  • previewstr, file preview URL
  • comment_idsCommentIDsObject, comment IDs
  • typestr, type (“file” or “dir”)
  • media_typestr, file type as determined by Yandex.Disk
  • revisionint, Yandex.Disk revision at the time of last modification
  • view_countint, number of times the public resource was viewed
  • ownerUserPublicInfoObject, owner of the public resource
class yadisk.objects.resources.PublicResourceListObject(public_resource_list=None)[source]

Bases: yadisk.objects.resources.ResourceListObject

List of public resources.

Parameters:

public_resource_listdict or None

Variables:
  • sortstr, sort type
  • itemslist, list of resources (ResourceObject)
  • limitint, maximum number of elements in the list
  • offsetint, offset from the beginning of the list
  • pathstr, path to the directory that contains the elements of the list
  • totalint, number of elements in the list
  • public_keystr, public key of the resource
class yadisk.objects.resources.TrashResourceObject(trash_resource=None)[source]

Bases: yadisk.objects.resources.ResourceObject

Trash resource object.

Parameters:

trash_resourcedict or None

Variables:
  • antivirus_statusstr, antivirus check status
  • filestr, download URL
  • sizeint, file size
  • public_keystr, public resource key
  • sha256str, SHA256 hash
  • md5str, MD5 hash
  • embeddedTrashResourceListObject, list of nested resources
  • namestr, filename
  • exifEXIFObject, EXIF metadata
  • resource_idstr, resource ID
  • custom_propertiesdict, custom resource properties
  • public_urlstr, public URL
  • shareShareInfoObject, shared folder information
  • modifieddatetime.datetime, date of last modification
  • createddatetime.datetime, date of creation
  • photoslice_timedatetime.datetime, photo/video creation date
  • mime_typestr, MIME type
  • pathstr, path to the resource
  • previewstr, file preview URL
  • comment_idsCommentIDsObject, comment IDs
  • typestr, type (“file” or “dir”)
  • media_typestr, file type as determined by Yandex.Disk
  • revisionint, Yandex.Disk revision at the time of last modification
  • origin_pathstr, original path
  • deleteddatetime.datetime, date of deletion
class yadisk.objects.resources.TrashResourceListObject(trash_resource_list=None)[source]

Bases: yadisk.objects.resources.ResourceListObject

List of trash resources.

Parameters:

trash_resource_listdict or None

Variables:
  • sortstr, sort type
  • itemslist, list of resources (TrashResourceObject)
  • limitint, maximum number of elements in the list
  • offsetint, offset from the beginning of the list
  • pathstr, path to the directory that contains the elements of the list
  • totalint, number of elements in the list
class yadisk.objects.operations.OperationStatusObject(operation_status=None)[source]

Bases: yadisk.objects.yadisk_object.YaDiskObject

Operation status object.

Parameters:

operation_statusdict or None

Variables:
  • typestr, type of the operation
  • statusstr, status of the operation
  • operation_idstr, ID of the operation
  • linkLinkObject, link to the operation
  • datadict, other information about the operation

Low-level API

Utilities

yadisk.utils.get_exception(response)[source]

Get an exception instance based on response, assuming the request has failed.

Parameters:response – an instance of requests.Response
Returns:an exception instance, subclass of YaDiskError
yadisk.utils.auto_retry(func, n_retries=None, retry_interval=None)[source]

Attempt to perform a request with automatic retries. A retry is triggered by requests.exceptions.RequestException or RetriableYaDiskError.

Parameters:
  • func – function to run, must not require any arguments
  • n_retriesint, maximum number of retries
  • retry_intervalint or float, delay between retries (in seconds)
Returns:

return value of func()

Functions

yadisk.functions.auth.check_token(session, **kwargs)[source]

Check whether the token is valid.

Parameters:session – an instance of requests.Session with prepared headers
Returns:bool
yadisk.functions.auth.get_auth_url(client_id, **kwargs)[source]

Get authentication URL for the user to go to.

Parameters:
  • client_id – application ID
  • type – response type (“code” to get the confirmation code or “token” to get the token automatically)
  • device_id – unique device ID, must be between 6 and 50 characters
  • device_name – device name, should not be longer than 100 characters
  • display – indicates whether to use lightweight layout, values other than “popup” are ignored
  • login_hint – username or email for the account the token is being requested for
  • scope – list of permissions for the application
  • optional_scope – list of optional permissions for the application
  • force_confirm – if True, user will be required to confirm access to the account even if the user has already granted access for the application
  • state – The state string, which Yandex.OAuth returns without any changes (<= 1024 characters)
Returns:

authentication URL

yadisk.functions.auth.get_code_url(client_id, **kwargs)[source]

Get the URL for the user to get the confirmation code. The confirmation code can later be used to get the token.

Parameters:
  • client_id – application ID
  • device_id – unique device ID, must be between 6 and 50 characters
  • device_name – device name, should not be longer than 100 characters
  • display – indicates whether to use lightweight layout, values other than “popup” are ignored
  • login_hint – username or email for the account the token is being requested for
  • scope – list of permissions for the application
  • optional_scope – list of optional permissions for the application
  • force_confirm – if True, user will be required to confirm access to the account even if the user has already granted access for the application
  • state – The state string, which Yandex.OAuth returns without any changes (<= 1024 characters)
Returns:

authentication URL

yadisk.functions.auth.get_token(code, client_id, client_secret, **kwargs)[source]

Get a new token.

Parameters:
  • code – confirmation code
  • client_id – application ID
  • client_secret – application secret password
  • device_id – unique device ID (between 6 and 50 characters)
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

TokenObject

yadisk.functions.auth.refresh_token(refresh_token, client_id, client_secret, **kwargs)[source]

Refresh an existing token.

Parameters:
  • refresh_token – the refresh token that was received with the token
  • client_id – application ID
  • client_secret – application secret password
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

TokenObject

yadisk.functions.auth.revoke_token(token, client_id, client_secret, **kwargs)[source]

Revoke the token.

Parameters:
  • token – token to revoke
  • client_id – application ID
  • client_secret – application secret password
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

TokenRevokeStatusObject

yadisk.functions.disk.get_disk_info(session, **kwargs)[source]

Get disk information.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

DiskInfoObject

yadisk.functions.resources.copy(session, src_path, dst_path, **kwargs)[source]

Copy src_path to dst_path. If the operation is performed asynchronously, returns the link to the operation, otherwise, returns the link to the newly created resource.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • src_path – source path
  • dst_path – destination path
  • overwrite – if True the destination path can be overwritten, otherwise, an error will be raised
  • force_async – forces the operation to be executed asynchronously
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

LinkObject or OperationLinkObject

yadisk.functions.resources.download(session, src_path, file_or_path, **kwargs)[source]

Download the file.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • src_path – source path
  • path_or_file – destination path or file-like object
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
yadisk.functions.resources.exists(session, path, **kwargs)[source]

Check whether path exists.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the resource
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

bool

Get a download link for a file (or a directory).

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the resource
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

str

yadisk.functions.resources.get_meta(session, path, **kwargs)[source]

Get meta information about a file/directory.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the resource
  • limit – number of children resources to be included in the response
  • offset – number of children resources to be skipped in the response
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • sortstr, field to be used as a key to sort children resources
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

ResourceObject

yadisk.functions.resources.get_type(session, path, **kwargs)[source]

Get resource type.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the resource
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

“file” or “dir”

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

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – destination path
  • overwritebool, determines whether to overwrite the destination
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

str

yadisk.functions.resources.is_dir(session, path, **kwargs)[source]

Check whether path is a directory.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the resource
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

True if path is a directory, False otherwise (even if it doesn’t exist)

yadisk.functions.resources.is_file(session, path, **kwargs)[source]

Check whether path is a file.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the resource
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

True if path is a file, False otherwise (even if it doesn’t exist)

yadisk.functions.resources.listdir(session, path, **kwargs)[source]

Get contents of path.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the directory
  • limit – number of children resources to be included in the response
  • offset – number of children resources to be skipped in the response
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

generator of ResourceObject

yadisk.functions.resources.mkdir(session, path, **kwargs)[source]

Create a new directory.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the directory to be created
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

LinkObject

yadisk.functions.resources.remove(session, path, **kwargs)[source]

Remove the resource.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the resource to be removed
  • permanently – if True, the resource will be removed permanently, otherwise, it will be just moved to the trash
  • md5str, MD5 hash of the file to remove
  • force_async – forces the operation to be executed asynchronously
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

LinkObject if the operation is performed asynchronously, None otherwise

yadisk.functions.resources.upload(session, file_or_path, dst_path, **kwargs)[source]

Upload a file to disk.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • file_or_path – path or file-like object to be uploaded
  • dst_path – destination path
  • overwrite – if True, the resource will be overwritten if it already exists, an error will be raised otherwise
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
yadisk.functions.resources.get_trash_meta(session, path, **kwargs)[source]

Get meta information about a trash resource.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the trash resource
  • limit – number of children resources to be included in the response
  • offset – number of children resources to be skipped in the response
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • sortstr, field to be used as a key to sort children resources
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

TrashResourceObject

yadisk.functions.resources.trash_exists(session, path, **kwargs)[source]

Check whether the trash resource at path exists.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the trash resource
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

bool

yadisk.functions.resources.restore_trash(session, path, dst_path=None, **kwargs)[source]

Restore a trash resource. Returns a link to the newly created resource or a link to the asynchronous operation.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the trash resource to be restored
  • dst_path – destination path
  • overwritebool, determines whether the destination can be overwritten
  • force_async – forces the operation to be executed asynchronously
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

LinkObject or OperationLinkObject

yadisk.functions.resources.move(session, src_path, dst_path, **kwargs)[source]

Move src_path to dst_path.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • src_path – source path to be moved
  • dst_path – destination path
  • overwritebool, determines whether to overwrite the destination
  • force_async – forces the operation to be executed asynchronously
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

LinkObject or OperationLinkObject

yadisk.functions.resources.remove_trash(session, path, **kwargs)[source]

Remove a trash resource.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the trash resource to be deleted
  • force_async – forces the operation to be executed asynchronously
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

OperationLinkObject if the operation is performed asynchronously, None otherwise

yadisk.functions.resources.publish(session, path, **kwargs)[source]

Make a resource public.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the resource to be published
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

LinkObject, link to the resource

yadisk.functions.resources.unpublish(session, path, **kwargs)[source]

Make a public resource private.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the resource to be unpublished
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

LinkObject

yadisk.functions.resources.save_to_disk(session, public_key, **kwargs)[source]

Saves a public resource to the disk. Returns the link to the operation if it’s performed asynchronously, or a link to the resource otherwise.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • public_key – public key or public URL of the public resource
  • name – filename of the saved resource
  • path – path to the copied resource in the public folder
  • save_path – path to the destination directory (downloads directory by default)
  • force_async – forces the operation to be executed asynchronously
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

LinkObject or OperationLinkObject

yadisk.functions.resources.get_public_meta(session, public_key, **kwargs)[source]

Get meta-information about a public resource.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • public_key – public key or public URL of the public resource
  • path – relative path to a resource in a public folder. By specifying the key of the published folder in public_key, you can request metainformation for any resource in the folder.
  • offset – offset from the beginning of the list of nested resources
  • limit – maximum number of nested elements to be included in the list
  • sortstr, field to be used as a key to sort children resources
  • preview_size – file preview size
  • preview_cropbool, allow preview crop
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

PublicResourceObject

yadisk.functions.resources.public_exists(session, public_key, **kwargs)[source]

Check whether the public resource exists.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • public_key – public key or public URL of the public resource
  • path – relative path to the resource within the public folder
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

bool

yadisk.functions.resources.public_listdir(session, public_key, **kwargs)[source]

Get contents of a public directory.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • public_key – public key or public URL of the public resource
  • path – relative path to the resource in the public folder. By specifying the key of the published folder in public_key, you can request contents of any nested folder.
  • limit – number of children resources to be included in the response
  • offset – number of children resources to be skipped in the response
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

generator of PublicResourceObject

yadisk.functions.resources.get_public_type(session, public_key, **kwargs)[source]

Get public resource type.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • public_key – public key or public URL of the public resource
  • path – relative path to the resource within the public folder
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

“file” or “dir”

yadisk.functions.resources.is_public_dir(session, public_key, **kwargs)[source]

Check whether the public resource is a public directory.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • public_key – public key or public URL of the public resource
  • path – relative path to the resource within the public folder
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

True if public_key is a directory, False otherwise (even if it doesn’t exist)

yadisk.functions.resources.is_public_file(session, public_key, **kwargs)[source]

Check whether the public resource is a public file.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • public_key – public key or public URL of the public resource
  • path – relative path to the resource within the public folder
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

True if public_key is a file, False otherwise (even if it doesn’t exist)

yadisk.functions.resources.trash_listdir(session, path, **kwargs)[source]

Get contents of a trash resource.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the directory in the trash bin
  • limit – number of children resources to be included in the response
  • offset – number of children resources to be skipped in the response
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

generator of TrashResourceObject

yadisk.functions.resources.get_trash_type(session, path, **kwargs)[source]

Get trash resource type.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the trash resource
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

“file” or “dir”

yadisk.functions.resources.is_trash_dir(session, path, **kwargs)[source]

Check whether path is a trash directory.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the trash resource
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

True if path is a directory, False otherwise (even if it doesn’t exist)

yadisk.functions.resources.is_trash_file(session, path, **kwargs)[source]

Check whether path is a trash file.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the trash resource
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

True if path is a file, False otherwise (even if it doesn’t exist)

yadisk.functions.resources.get_public_resources(session, **kwargs)[source]

Get a list of public resources.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • offset – offset from the beginning of the list
  • limit – maximum number of elements in the list
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • type – filter based on type of resources (“file” or “dir”)
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

PublicResourcesListObject

yadisk.functions.resources.patch(session, path, properties, **kwargs)[source]

Update custom properties of a resource.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the resource
  • propertiesdict, custom properties to update
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

ResourceObject

yadisk.functions.resources.get_files(session, **kwargs)[source]

Get a flat list of all files (that doesn’t include directories).

Parameters:
  • session – an instance of requests.Session with prepared headers
  • offset – offset from the beginning of the list
  • limit – number of list elements to be included
  • media_type – type of files to include in the list
  • sortstr, field to be used as a key to sort children resources
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

generator of ResourceObject

yadisk.functions.resources.get_last_uploaded(session, **kwargs)[source]

Get the list of latest uploaded files sorted by upload date.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • limit – maximum number of elements in the list
  • media_type – type of files to include in the list
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

generator of LastUploadedResourceListObject

yadisk.functions.resources.upload_url(session, url, path, **kwargs)[source]

Upload a file from URL.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • url – source URL
  • path – destination path
  • disable_redirectsbool, forbid redirects
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

OperationLinkObject, link to the asynchronous operation

Get a download link for a public resource.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • public_key – public key or public URL of the public resource
  • path – relative path to the resource within the public folder
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

str

yadisk.functions.resources.download_public(session, public_key, file_or_path, **kwargs)[source]

Download the public resource.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • public_key – public key or public URL of the public resource
  • file_or_path – destination path or file-like object
  • path – relative path to the resource within the public folder
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
yadisk.functions.operations.get_operation_status(session, operation_id, **kwargs)[source]

Get operation status.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • operation_id – ID of the operation or a link
  • fields – list of keys to be included in the response
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
Returns:

str

API request objects

class yadisk.api.APIRequest(session, args, **kwargs)[source]

Base class for all API requests.

Parameters:
  • session – an instance of requests.Session
  • argsdict of arguments, that will be passed to process_args
  • timeoutfloat or tuple, request timeout
  • headersdict or None, additional request headers
  • n_retriesint, maximum number of retries
  • retry_interval – delay between retries in seconds
  • kwargs – other arguments for requests.Session.send
Variables:
  • urlstr, request URL
  • methodstr, request method
  • content_typestr, Content-Type header (“application/x-www-form-urlencoded” by default)
  • timeoutfloat or tuple, request timeout
  • n_retriesint, maximum number of retries
  • success_codeslist-like, list of response codes that indicate request’s success
  • retry_intervalfloat, delay between retries in seconds
prepare()[source]

Prepare the request

process()[source]

Process the response.

Returns:depends on self.process_json()
process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
send()[source]
Actually send the request
Returns:requests.Response (self.response)
class yadisk.api.auth.RefreshTokenRequest(session, refresh_token, client_id, client_secret, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to refresh an existing token.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • refresh_token – the refresh token that was received with the original token
  • client_id – application ID
  • client_secret – application secret password
Returns:

TokenObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.auth.RevokeTokenRequest(session, token, client_id, client_secret, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to revoke the token.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • token – the token to be revoked
  • client_id – application ID
  • client_secret – application secret password
Returns:

TokenRevokeStatusObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.auth.GetTokenRequest(session, code, client_id, client_secret, device_id=None, device_name=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to get the token.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • code – confirmation code
  • client_id – application ID
  • client_secret – application secret password
  • device_id – unique device ID (between 6 and 50 characters)
Returns:

TokenObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.disk.DiskInfoRequest(session, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to get disk information.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • fields – list of keys to be included in the response
Returns:

DiskInfoObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.GetPublicResourcesRequest(session, offset=0, limit=20, preview_size=None, preview_crop=None, type=None, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to get a list of public resources.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • offset – offset from the beginning of the list
  • limit – maximum number of elements in the list
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • type – filter based on type of resources (“file” or “dir”)
  • fields – list of keys to be included in the response
Returns:

PublicResourcesListObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.UnpublishRequest(session, path, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to make a public resource private.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the resource to be unpublished
  • fields – list of keys to be included in the response
Returns:

LinkObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.GetDownloadLinkRequest(session, path, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to get a download link to a resource.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the resource to be downloaded
  • fields – list of keys to be included in the response
Returns:

LinkObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.GetTrashRequest(session, path=None, offset=0, limit=20, sort=None, preview_size=None, preview_crop=None, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to get meta-information about a trash resource.

Parameters:
  • path – path to the trash resource
  • limit – number of children resources to be included in the response
  • offset – number of children resources to be skipped in the response
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • sortstr, field to be used as a key to sort children resources
  • fields – list of keys to be included in the response
Returns:

TrashResourceObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.RestoreTrashRequest(session, path, dst_path=None, force_async=False, overwrite=False, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to restore trash.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the trash resource to be restored
  • dst_path – destination path
  • force_async – forces the operation to be executed asynchronously
  • overwritebool, determines whether the destination can be overwritten
  • fields – list of keys to be included in the response
Returns:

LinkObject or OperationLinkObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.DeleteTrashRequest(session, path=None, force_async=False, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to delete a trash resource.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the trash resource to be deleted
  • force_async – forces the operation to be executed asynchronously
  • fields – list of keys to be included in the response
Returns:

OperationLinkObject or None

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.LastUploadedRequest(session, limit=20, media_type=None, preview_size=None, preview_crop=None, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to get the list of latest uploaded files sorted by upload date.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • limit – maximum number of elements in the list
  • media_type – type of files to include in the list
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • fields – list of keys to be included in the response
Returns:

LastUploadedResourceListObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.CopyRequest(session, src_path, dst_path, overwrite=False, force_async=False, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to copy a file or a directory.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • src_path – source path
  • dst_path – destination path
  • overwrite – if True the destination path can be overwritten, otherwise, an error will be raised
  • force_async – forces the operation to be executed asynchronously
  • fields – list of keys to be included in the response
Returns:

LinkObject or OperationLinkObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.GetMetaRequest(session, path, limit=None, offset=None, preview_size=None, preview_crop=None, sort=None, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to get meta-information about a resource.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the resource
  • limit – number of children resources to be included in the response
  • offset – number of children resources to be skipped in the response
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • sortstr, field to be used as a key to sort children resources
  • fields – list of keys to be included in the response
Returns:

ResourceObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.GetUploadLinkRequest(session, path, overwrite=False, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to get an upload link.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to be uploaded at
  • overwritebool, determines whether to overwrite the destination
  • fields – list of keys to be included in the response
Returns:

ResourceUploadLinkObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.MkdirRequest(session, path, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to create a new directory.

Parameters:
  • path – path to the directory to be created
  • fields – list of keys to be included in the response
Returns:

LinkObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.PublishRequest(session, path, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to make a resource public.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the resource to be published
  • fields – list of keys to be included in the response
Returns:

LinkObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.UploadURLRequest(session, url, path, disable_redirects=False, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to upload a file from URL.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • url – source URL
  • path – destination path
  • disable_redirectsbool, forbid redirects
  • fields – list of keys to be included in the response
Returns:

OperationLinkObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.DeleteRequest(session, path, permanently=False, md5=None, force_async=False, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to delete a file or a directory.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the resource to be removed
  • permanently – if True, the resource will be removed permanently, otherwise, it will be just moved to the trash
  • force_async – forces the operation to be executed asynchronously
  • md5str, MD5 hash of the file to remove
  • fields – list of keys to be included in the response
Returns:

OperationLinkObject or None

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.SaveToDiskRequest(session, public_key, name=None, path=None, save_path=None, force_async=False, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to save a public resource to the disk.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • public_key – public key or public URL of the resource
  • name – filename of the saved resource
  • path – path to the copied resource in the public folder
  • save_path – path to the destination directory (downloads directory by default)
  • force_async – forces the operation to be executed asynchronously
  • fields – list of keys to be included in the response
Returns:

LinkObject or OperationLinkObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.GetPublicMetaRequest(session, public_key, offset=0, limit=20, path=None, sort=None, preview_size=None, preview_crop=None, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to get meta-information about a public resource.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • public_key – public key or public URL of the resource
  • path – relative path to a resource in a public folder. By specifying the key of the published folder in public_key, you can request metainformation for any resource in the folder.
  • offset – offset from the beginning of the list of nested resources
  • limit – maximum number of nested elements to be included in the list
  • sortstr, field to be used as a key to sort children resources
  • preview_size – file preview size
  • preview_cropbool, allow preview crop
  • fields – list of keys to be included in the response
Returns:

PublicResourceObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.GetPublicDownloadLinkRequest(session, public_key, path=None, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to get a download link for a public resource.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • public_key – public key or public URL of the resource
  • path – relative path to the resource within the public folder
  • fields – list of keys to be included in the response
Returns:

LinkObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.MoveRequest(session, src_path, dst_path, force_async=False, overwrite=False, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to move a resource.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • src_path – source path to be moved
  • dst_path – destination path
  • force_async – forces the operation to be executed asynchronously
  • overwritebool, determines whether to overwrite the destination
  • fields – list of keys to be included in the response
Returns:

OperationLinkObject or LinkObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.FilesRequest(session, offset=0, limit=20, media_type=None, preview_size=None, preview_crop=None, sort=None, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to get a flat list of all files (that doesn’t include directories).

Parameters:
  • session – an instance of requests.Session with prepared headers
  • offset – offset from the beginning of the list
  • limit – number of list elements to be included
  • media_type – type of files to include in the list
  • sortstr, field to be used as a key to sort children resources
  • preview_size – size of the file preview
  • preview_cropbool, cut the preview to the size specified in the preview_size
  • fields – list of keys to be included in the response
Returns:

FilesResourceListObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.resources.PatchRequest(session, path, properties, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to update custom properties of a resource.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • path – path to the resource
  • propertiesdict, custom properties to update
  • fields – list of keys to be included in the response
Returns:

ResourceObject

prepare(*args, **kwargs)[source]

Prepare the request

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything
class yadisk.api.operations.GetOperationStatusRequest(session, operation_id, fields=None, **kwargs)[source]

Bases: yadisk.api.api_request.APIRequest

A request to get operation status.

Parameters:
  • session – an instance of requests.Session with prepared headers
  • operation_id – operation ID or link
  • fields – list of keys to be included in the response
Returns:

OperationStatusObject

process_json(js)[source]

Process the JSON response.

Parameters:jsdict, JSON response
Returns:processed response, can be anything