Skip to main content
`Ctrl`+`K`

# yndx_disk.clients package

## Submodules

## yndx_disk.clients.async_client module

class yndx_disk.clients.async_client.AsyncDiskClient(token: str, auto_update_info: bool = True)

  Bases: `object`

  A class representing an asynchronous client for interacting with a disk service.

  Attributes: - user (dict): Information about the user. - system_folders (dict): Information about the system folders. - is_paid (bool): Whether the user has a paid account. - payment_flow (bool): Whether the user is in the payment flow. - unlimited_autoupload_enabled (bool): Whether unlimited autoupload is enabled. - reg_time (str): The registration time of the user. - total_space (int): The total disk space available. - used_space (int): The used disk space. - max_file_size (int): The maximum file size allowed. - paid_max_file_size (int): The maximum file size allowed for a paid account. - photounlim_size (int): The photo unlimited size. - trash_size (int): The size of the trash. - revision (int): The revision number.

  async copy(source_path: str, destination_path: str, overwrite: bool = False) → None

    Copy a file or directory from one location to another on the disk.

    This method copies a file or directory from the source path to the destination path. If the request is successful (status code 202), it waits for the operation to finish and raises a YandexDiskAPIException if the operation fails. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response. If the auto_update_info attribute is True, it updates the disk information after the operation is successful.

    Parameters: - source_path (str): The path of the file or directory to be copied. - destination_path (str): The path where the file or directory should be copied to. - overwrite (bool, optional): Whether to overwrite the destination file or directory if it already exists. Defaults to False.

    Returns: - None

    Raises: - YandexDiskAPIException: If the request fails or if the operation fails.

  async delete(path: str, permanently: bool = False) → None

    Delete a file or directory from the disk.

    This method deletes a file or directory from the disk using the provided path. If the request is successful (status code 202), it waits for the operation to finish and raises a YandexDiskAPIException if the operation fails. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response. If the auto_update_info attribute is True, it updates the disk information after the operation is successful.

    Parameters: - path (str): The path of the file or directory to be deleted. - permanent (bool, optional): Whether to delete the file or directory permanently. Defaults to False.

    Returns: - None

    Raises: - YandexDiskAPIException: If the request fails or if the operation fails.

  async delete_trash(path: str = '')

    Delete a file or directory from the trash on the server.

    This method deletes a file or directory from the trash using the provided path. If the request is successful (status code 202), it waits for the operation to finish and raises a YandexDiskAPIException if the operation fails. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response. If the auto_update_info attribute is True, it updates the disk information after the operation is successful.

    Parameters: - path (str, optional): The path of the file or directory to be deleted from the trash. Defaults to “”.

    Returns: - None

    Raises: - YandexDiskAPIException: If the request fails or if the operation fails.

  async get_object(path: str) → File | Directory

    Get an object from the disk.

    This method retrieves information about an object (file or directory) from the disk using the provided path. If the request is successful (status code 200), it returns a File or Directory object based on the type of the object. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response.

    Parameters: - path (str): The path of the object to retrieve.

    Returns: - File | Directory: The retrieved File or Directory object.

    Raises: - YandexDiskAPIException: If the request fails or if the object type cannot be determined.

  is_paid: bool = None
  async listdir(path: str = '/', limit: int = 100, offset: int = 0) → list[ File | Directory ]

    List the contents of a directory on the disk.

    This method retrieves the contents of a directory from the disk using the provided path. If the request is successful (status code 200), it returns a list of File or Directory objects representing the contents of the directory. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response.

    Parameters: - path (str, optional): The path of the directory to list. Defaults to “/”. - limit (int, optional): The maximum number of items to return in the response. Defaults to 100. - offset (int, optional): The number of items to skip before returning the response. Defaults to 0.

    Returns: - list[File | Directory]: A list of File or Directory objects representing the contents of the directory.

    Raises: - YandexDiskAPIException: If the request fails or if the object type cannot be determined.

  async listdir_trash(path: str = '/', limit: int = 100, offset: int = 0) → list[ File | Directory ]

    List the contents of a directory in the trash on the disk.

    This method retrieves the contents of a directory in the trash from the disk using the provided path. If the request is successful (status code 200), it returns a list of File or Directory objects representing the contents of the directory. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response.

    Parameters: - path (str, optional): The path of the directory in the trash to list. Defaults to “/”. - limit (int, optional): The maximum number of items to return in the response. Defaults to 100. - offset (int, optional): The number of items to skip before returning the response. Defaults to 0.

    Returns: - list[File | Directory]: A list of File or Directory objects representing the contents of the directory in the trash.

    Raises: - YandexDiskAPIException: If the request fails or if the object type cannot be determined.

  max_file_size: int = None
  async move(source_path: str, destination_path: str, overwrite: bool = False) → None

    Move a file or directory from one location to another on the disk.

    This method moves a file or directory from the source path to the destination path. If the request is successful (status code 202), it waits for the operation to finish and raises a YandexDiskAPIException if the operation fails. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response. If the auto_update_info attribute is True, it updates the disk information after the operation is successful.

    Parameters: - source_path (str): The path of the file or directory to be moved. - destination_path (str): The path where the file or directory should be moved to. - overwrite (bool, optional): Whether to overwrite the destination file or directory if it already exists. Defaults to False.

    Returns: - None

    Raises: - YandexDiskAPIException: If the request fails or if the operation fails.

  paid_max_file_size: int = None
  payment_flow: bool = None
  photounlim_size: int = None
  async publish(path: str, return_public_url: bool = False) → str | None

    Publish a file or directory on the server.

    This method publishes a file or directory on the server using the provided path. If the request is successful (status code 200), it returns the public URL of the published file or directory. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response.

    Parameters: - path (str): The path of the file or directory to be published. - return_public_url (bool, optional): Whether to return the public URL of the published file or directory. Defaults to False.

    Returns: - str | None: The public URL of the published file or directory if return_public_url is True, otherwise None.

    Raises: - YandexDiskAPIException: If the request fails.

  reg_time: str = None
  async restore_trash(path: str, new_name: str = '', overwrite: bool = False)

    Restore a file or directory from the trash on the server.

    This method restores a file or directory from the trash using the provided path. If the request is successful (status code 202), it waits for the operation to finish and raises a YandexDiskAPIException if the operation fails. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response. If the auto_update_info attribute is True, it updates the disk information after the operation is successful.

    Parameters: - path (str): The path of the file or directory to be restored. - new_name (str, optional): The new name for the restored file or directory. Defaults to “”. - overwrite (bool, optional): Whether to overwrite the destination file or directory if it already exists. Defaults to False.

    Returns: - None

    Raises: - YandexDiskAPIException: If the request fails or if the operation fails.

  revision: int = None
  system_folders: dict = None
  total_space: int = None
  trash_size: int = None
  unlimited_autoupload_enabled: bool = None
  async unpublish(path: str)

    Unpublish a file or directory on the server.

    This method unpublishes a file or directory on the server using the provided path. If the request is successful (status code 200), it returns the public URL of the unpublished file or directory. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response.

    Parameters: - path (str): The path of the file or directory to be unpublished.

    Returns: - None

    Raises: - YandexDiskAPIException: If the request fails.

  async update_disk_info() → None

    Update the disk information for the client.

    This method retrieves the disk information from the server using the provided token. If the request is successful (status code 200), it updates the client’s information with the retrieved data. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response.

    Returns: - None

  async upload_file(file_path: str, path: str, overwrite: bool = False, chunk_size: int = 1024) → None

    Upload a file to the server.

    This method uploads a file to the server using the provided file path and destination path. If the file size is larger than the available space or the maximum file size allowed, it raises a YandexDiskAPIException. If the request is successful (status code 201), it updates the disk information if auto_update_info is True. If the request is successful (status code 202), it waits for the operation to finish and updates the disk information if auto_update_info is True. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response.

    Parameters: - file_path (str): The path of the file to be uploaded. - path (str): The destination path on the server. - overwrite (bool, optional): Whether to overwrite the destination file if it already exists. Defaults to False. - chunk_size (int, optional): The size of each chunk to be uploaded. Defaults to 1024.

    Returns: - None

    Raises: - YandexDiskAPIException: If the file size is too large or the request fails.

  used_space: int = None
  user: dict = None

## yndx_disk.clients.sync_client module

class yndx_disk.clients.sync_client.DiskClient(token: str, auto_update_info: bool = True)

  Bases: `AsyncDiskClient`

  copy(source_path: str, destination_path: str, overwrite: bool = False) → None

    Copy a file or directory from one location to another on the disk.

    This method copies a file or directory from the source path to the destination path. If the request is successful (status code 202), it waits for the operation to finish and raises a YandexDiskAPIException if the operation fails. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response. If the auto_update_info attribute is True, it updates the disk information after the operation is successful.

    Parameters: - source_path (str): The path of the file or directory to be copied. - destination_path (str): The path where the file or directory should be copied to. - overwrite (bool, optional): Whether to overwrite the destination file or directory if it already exists. Defaults to False.

    Returns: - None

    Raises: - YandexDiskAPIException: If the request fails or if the operation fails.

  delete(path: str = '', permanently: bool = False) → None

    Delete a file or directory from the disk.

    This method deletes a file or directory from the disk using the provided path. If the request is successful (status code 202), it waits for the operation to finish and raises a YandexDiskAPIException if the operation fails. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response. If the auto_update_info attribute is True, it updates the disk information after the operation is successful.

    Parameters: - path (str): The path of the file or directory to be deleted. - permanent (bool, optional): Whether to delete the file or directory permanently. Defaults to False.

    Returns: - None

    Raises: - YandexDiskAPIException: If the request fails or if the operation fails.

  delete_trash(path: str = '')

    Delete a file or directory from the trash on the server.

    This method deletes a file or directory from the trash using the provided path. If the request is successful (status code 202), it waits for the operation to finish and raises a YandexDiskAPIException if the operation fails. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response. If the auto_update_info attribute is True, it updates the disk information after the operation is successful.

    Parameters: - path (str, optional): The path of the file or directory to be deleted from the trash. Defaults to “”.

    Returns: - None

    Raises: - YandexDiskAPIException: If the request fails or if the operation fails.

  get_object(path: str) → File | Directory

    Get an object from the disk.

    This method retrieves information about an object (file or directory) from the disk using the provided path. If the request is successful (status code 200), it returns a File or Directory object based on the type of the object. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response.

    Parameters: - path (str): The path of the object to retrieve.

    Returns: - File | Directory: The retrieved File or Directory object.

    Raises: - YandexDiskAPIException: If the request fails or if the object type cannot be determined.

  listdir(path: str = '/', limit: int = 100, offset: int = 0) → list[ File | Directory ]

    List the contents of a directory on the disk.

    This method retrieves the contents of a directory from the disk using the provided path. If the request is successful (status code 200), it returns a list of File or Directory objects representing the contents of the directory. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response.

    Parameters: - path (str, optional): The path of the directory to list. Defaults to “/”. - limit (int, optional): The maximum number of items to return in the response. Defaults to 100. - offset (int, optional): The number of items to skip before returning the response. Defaults to 0.

    Returns: - list[File | Directory]: A list of File or Directory objects representing the contents of the directory.

    Raises: - YandexDiskAPIException: If the request fails or if the object type cannot be determined.

  listdir_trash(path: str = '/', limit: int = 100, offset: int = 0) → list[ File | Directory ]

    List the contents of a directory in the trash on the disk.

    This method retrieves the contents of a directory in the trash from the disk using the provided path. If the request is successful (status code 200), it returns a list of File or Directory objects representing the contents of the directory. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response.

    Parameters: - path (str, optional): The path of the directory in the trash to list. Defaults to “/”. - limit (int, optional): The maximum number of items to return in the response. Defaults to 100. - offset (int, optional): The number of items to skip before returning the response. Defaults to 0.

    Returns: - list[File | Directory]: A list of File or Directory objects representing the contents of the directory in the trash.

    Raises: - YandexDiskAPIException: If the request fails or if the object type cannot be determined.

  move(source_path: str, destination_path: str, overwrite: bool = False) → None

    Move a file or directory from one location to another on the disk.

    This method moves a file or directory from the source path to the destination path. If the request is successful (status code 202), it waits for the operation to finish and raises a YandexDiskAPIException if the operation fails. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response. If the auto_update_info attribute is True, it updates the disk information after the operation is successful.

    Parameters: - source_path (str): The path of the file or directory to be moved. - destination_path (str): The path where the file or directory should be moved to. - overwrite (bool, optional): Whether to overwrite the destination file or directory if it already exists. Defaults to False.

    Returns: - None

    Raises: - YandexDiskAPIException: If the request fails or if the operation fails.

  publish(path: str, return_public_url: bool = False) → str | None

    Publish a file or directory on the server.

    This method publishes a file or directory on the server using the provided path. If the request is successful (status code 200), it returns the public URL of the published file or directory. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response.

    Parameters: - path (str): The path of the file or directory to be published. - return_public_url (bool, optional): Whether to return the public URL of the published file or directory. Defaults to False.

    Returns: - str | None: The public URL of the published file or directory if return_public_url is True, otherwise None.

    Raises: - YandexDiskAPIException: If the request fails.

  restore_trash(path: str, new_name: str = '', overwrite: bool = False)

    Restore a file or directory from the trash on the server.

    This method restores a file or directory from the trash using the provided path. If the request is successful (status code 202), it waits for the operation to finish and raises a YandexDiskAPIException if the operation fails. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response. If the auto_update_info attribute is True, it updates the disk information after the operation is successful.

    Parameters: - path (str): The path of the file or directory to be restored. - new_name (str, optional): The new name for the restored file or directory. Defaults to “”. - overwrite (bool, optional): Whether to overwrite the destination file or directory if it already exists. Defaults to False.

    Returns: - None

    Raises: - YandexDiskAPIException: If the request fails or if the operation fails.

  unpublish(path: str)

    Unpublish a file or directory on the server.

    This method unpublishes a file or directory on the server using the provided path. If the request is successful (status code 200), it returns the public URL of the unpublished file or directory. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response.

    Parameters: - path (str): The path of the file or directory to be unpublished.

    Returns: - None

    Raises: - YandexDiskAPIException: If the request fails.

  update_disk_info() → None

    Update the disk information for the client.

    This method retrieves the disk information from the server using the provided token. If the request is successful (status code 200), it updates the client’s information with the retrieved data. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response.

    Returns: - None

  upload_file(file_path: str, path: str, overwrite: bool = False, chunk_size: int = 1024) → None

    Upload a file to the server.

    This method uploads a file to the server using the provided file path and destination path. If the file size is larger than the available space or the maximum file size allowed, it raises a YandexDiskAPIException. If the request is successful (status code 201), it updates the disk information if auto_update_info is True. If the request is successful (status code 202), it waits for the operation to finish and updates the disk information if auto_update_info is True. If the request fails, it raises a YandexDiskAPIException with the status code and description from the response.

    Parameters: - file_path (str): The path of the file to be uploaded. - path (str): The destination path on the server. - overwrite (bool, optional): Whether to overwrite the destination file if it already exists. Defaults to False. - chunk_size (int, optional): The size of each chunk to be uploaded. Defaults to 1024.

    Returns: - None

    Raises: - YandexDiskAPIException: If the file size is too large or the request fails.

## Module contents