Skip to main content

PyYaDisk

PyYaDisk is a wrapper over Yandex Disk Rest API V1. The library is in creation process. You can check realized features with our roadmap below.

Installation

Install and update using pip:

pip install -U pyyadisk

Usage

0. Get Oauth-token

Before you start using YandexDisk API, you need to get a token for Oauth authorization. You can get it from Yandex Poligon.

1. Yandex Disk instance

Let's start. At first we need to make an YandexDisk instance:

from pyyadisk import YandexDisk

token = 'ya_oauth_token'
disk = YandexDisk(token=token, proxy=proxy, ssl_verify=True, max_retries=5)

token: Oauth token (get it at https://yandex.ru/dev/disk/poligon/)

proxy: (optional) Proxy address for http and https

ssl_verify: (optional) Flag of connection ssl verification check

max_retries: (optional) Number of maximum connection retries

2. Set Path

Now we ready to make some operations. Let's set the path for operations:

disk.path(path='path/to/directory')

path: full path to directory or file

3. Upload a file

3.1. Upload local file

Ok. We ready to upload a file from computer. If file exists it will be overwritten with flag overwrite=True

disk = YandexDisk(token=token)
disk.path(path='path/to/directory')
response = disk.upload(filepath='home/computer/path/to/the/file.pdf', overwrite=True)

filepath: Path to the file

overwrite: (optional) Enable overwriting for uploaded item

Or in one line

disk.path('path/to/directory').upload('home/computer/path/to/the/file.pdf', overwrite=True)

3.2. Upload file by URL

disk = YandexDisk(token=token)
disk.path(path='path/to/directory')
operation_id = disk.upload_by_url(filename='file.pdf', url='https://example.com/file_1.pdf', disable_redirects=False)

Uploading file by url working at serverside in async mode. upload_by_url() returns operation_id.

filename: name of the file

url: url of the file

disable_redirects: Disable redirects

4. Uploading status

By operation_id we can get status of uploading:

status = disk.operations(self, operation_id: str)

5. File or Directory operations

Now when file or directory was uploaded we can make some operations with it.

  • get(limit: int = None, offset: int = None): Get stats of file or directory

    limit: The number of items to return

    offset: Offset from the beginning

  • create(self, subdir: str = None): Create directory

    subdir: Name of subdirectory. If 'subdir = None' the directory will be created by path-data

  • delete(self, force_async: bool = None, md5_hash: str = None, permanently: bool = False): Delete file or directory

    force_async: Execute asynchronously (True or False).

    md5_hash: md5 hash of file

    permanently: Flag of permanently delete

  • copy_to(self, destination: str, force_async: bool = None, overwrite: bool = None): Copy file or directory

  • move_to(self, destination: str, force_async: bool = None, overwrite: bool = None): Move file or directory

    destination: Destination path

    force_async: Execute asynchronously (True or False).

    overwrite: Flag of overwrite enable

disk = YandexDisk(token=token)

create_ = disk.path('path/to/directory').create()  # Create directory

info = disk.path('path/to/directory').get()  # Directory stats

copy_ = disk.path('path/to/directory').copy_to('path/to/new/directory')  # Copy from path='path/to/directory'

move_ = disk.path('path/to/directory').move_to('path/to/new/directory')  # Move from path='path/to/directory'

disk.path('path/to/directory').delete()  # Delete directory or file

6. Share

share(): Share file or directory which set by YandexDisk.path('path/to/the/file'). Returns tuple(response_code, public_url)

unshare(): Unshare file or directory

public_url(): Get public url of file or directory

public_key(): Get public key of file or directory

Example:

disk = YandexDisk(token=token)

link = disk.path('path/to/directory').share()
link = disk.path('path/to/directory').public_url()
public_key = disk.path('path/to/directory').public_key()
disk.path('path/to/directory').unshare()

Roadmap

  • OAuth authorization by token

/v1/disk

  • Get disk metadata

/v1/disk/resources

  • Get metadata of file or directory
  • Create directory
  • Delete file or directory
  • Move file or directory
  • Copy file or directory
  • Get download link (private)
  • Share directory or file and get public link
  • Get download link (public)
  • Get list of files
  • Get last uploaded files
  • Upload file
  • Upload file by url

/v1/disk/resources/save-to-disk

  • Save public file to disk by public key or url

Metadata

Release files for pyyadisk 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyyadisk 0.1.3
File Size Uploaded Provenance Actions
pyyadisk-0.1.3.tar.gz 8.1 kB Without provenance Details for pyyadisk-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyyadisk 0.1.3
File Interpreter ABI Platform Actions
pyyadisk-0.1.3-py3-none-any.whl Python 3 none any Details for pyyadisk-0.1.3-py3-none-any.whl

Total release size: 16.4 kB

Release files / pyyadisk-0.1.3.tar.gz

Download URL pyyadisk-0.1.3.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c9e82b8886a76f83ce81421305455fa1688fd8d378c37c5b2864cb5e7171fb7a
BLAKE2b-256 checksum
How to use checksums
2faab06df3ab067e1be92dbc2bd7bc870c89fd988ea68fb2a46e91f1c7ae310b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.6.9

Release files / pyyadisk-0.1.3-py3-none-any.whl

Download URL pyyadisk-0.1.3-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f2e25e0a37d419928fd69d7441191d51c0fd3e14bcc7dfd349ec3455d2924d7a
BLAKE2b-256 checksum
How to use checksums
9c5e6e28d5a85833400c2408ecd061a157fc6e983abe229c7b1b2df922eac065
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.6.9

Security for pyyadisk 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page