Skip to main content

asynchronous generic cloud drive library

Project description

wcpan.drive

Asynchronous generic cloud drive library.

This package needs a driver to actually work with a cloud drive.

Example Usage

from wcpan.drive.core.drive import (
    DriveFactory, download_to_local, upload_from_local,
)


async def simple_demo():
    # Load config and data from default locations.
    factory = DriveFactory()
    factory.load_config()

    async with factory() 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 cache in sync.
        async for change in drive.sync():
            print(change)

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

        # 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 folder.
        new_folder = await drive.create_folder(root_node, 'folder_name')

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

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

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


async def config_demo():
    factory = DriveFactory()

    # Read config files from here.
    # The default is $HOME/.config/wcpan.drive.
    # These files are what you want to keep and backup.
    factory.config_path = '/tmp/config'

    # Put generated files here.
    # The default is $HOME/.local/share/wcpan.drive.
    # These files should be safely deleted.
    factory.data_path = '/tmp/data'

    # Setup cache database, will write to data folder.
    factory.database = 'nodes.sqlite'

    # Setup driver class.
    factory.driver = 'some.random.driver.RandomDriver'

    # load config file from config folder
    # this will not overwrite the above given values
    factory.load_config()

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-3.1.0.tar.gz (19.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-3.1.0-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file wcpan.drive.core-3.1.0.tar.gz.

File metadata

  • Download URL: wcpan.drive.core-3.1.0.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for wcpan.drive.core-3.1.0.tar.gz
Algorithm Hash digest
SHA256 49e7c3f09b79c825aa38600847936cb61184bfe4887f36a9f15101b8c092eee9
MD5 0be75785cc1c9786fee18a6dfe7192b9
BLAKE2b-256 bb91a3e86488ccf75098219d9710b9fa22f201fc95081de62321296204c1d5a1

See more details on using hashes here.

File details

Details for the file wcpan.drive.core-3.1.0-py3-none-any.whl.

File metadata

  • Download URL: wcpan.drive.core-3.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for wcpan.drive.core-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d6c0d1032d55d8000206c0602bb3eac871c45539eafc9480ecd82370c204fc7a
MD5 192742c2767f97ee6231880bbcc586cb
BLAKE2b-256 83780520b53d3175b3161eefa44c7837538467cb97f0225d8268fa4e8db33422

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