Skip to main content

asynchronous generic cloud drive library

Project description

wcpan.drive

Asynchronous generic cloud drive library.

This package only provides the core functionality. It need SnapsnotService and FileService implementation to work.

Example Usage

from wcpan.drive.core import create_drive
from wcpan.drive.core.types import (
    CreateFileService,
    CreateSnapshotService,
)
from wcpan.drive.core.lib import (
    download_file_to_local,
    upload_file_from_local,
)


# Assumes we already know how to create FileService and SnapshotService.
async def simple_demo(
    create_file_service: CreateFileService,
    create_snapshot_service: CreateSnapshotService,
):
    async with create_drive(
        file=create_file_service,
        snapshot=create_snapshot_service,
    ) as drive:
        # Check for authorization.
        if not await drive.is_authorized():
            # Start OAuth 2.0 process
            url = await drive.get_oauth_url()
            # ... The user visits the url ...
            # Get tokens from the user.
            token = ...
            # Finish OAuth 2.0 process.
            await drive.set_oauth_token(token)

        # It is important to keep the snapshot up-to-date.
        async for change in drive.sync():
            print(change)

        # Get the root node.
        root_node = await drive.get_root()

        # Get a node.
        node = await drive.get_node_by_path('/path/to/drive/file')

        # List children.
        children = await drive.get_children(root_node)

        # Make a directory.
        new_directory = await drive.create_directory('directory_name', root_node)

        # Download a file.
        await download_file_to_local(drive, node, '/tmp')

        # Upload a file.
        new_file = await upload_from_local(drive, root_node, '/path/to/local/file')

        # Traverse drive.
        async for root, directorys, files in drive.walk(root_node):
            print(root, directorys, files)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wcpan_drive_core-4.0.2.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wcpan_drive_core-4.0.2-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file wcpan_drive_core-4.0.2.tar.gz.

File metadata

  • Download URL: wcpan_drive_core-4.0.2.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.2 Linux/5.15.133.1-microsoft-standard-WSL2

File hashes

Hashes for wcpan_drive_core-4.0.2.tar.gz
Algorithm Hash digest
SHA256 5f624211b0087a99547fba3faafd92b7517cb659a0fa1df0a9b84abe808f8cb9
MD5 6702068e8ec18c34c2f91876ceac5f25
BLAKE2b-256 b9094e6133bf33e3b8e88ed950db01d0dcdc37c47c5277852ea7ab3ca3f20857

See more details on using hashes here.

File details

Details for the file wcpan_drive_core-4.0.2-py3-none-any.whl.

File metadata

  • Download URL: wcpan_drive_core-4.0.2-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.2 Linux/5.15.133.1-microsoft-standard-WSL2

File hashes

Hashes for wcpan_drive_core-4.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2119b3440bc86b04b3abf86d18807f995990eca34e15db3de0739404d6ff2275
MD5 09bcd0305ab2053eff13606f866b333e
BLAKE2b-256 b4ea347a063e6f7980ea87a1e95048b9d5a4a199d53e49008b796a5fdcb71980

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page