Common Patterns

Here are a few common patterns and use cases for Shade that we have curated that you may find useful. Please check out Get Started with the Shade Python SDK before continuing with these patterns

Get All Workspaces for Your User

shade = Shade(remote_url=REMOTE_URL, api_key=API_KEY)
workspaces = shade.workspace.get_workspaces()

Get All Drives of a Workspace

workspace = shade.workspace.get_workspace_by_domain(WORKSPACE_DOMAIN)
drives = shade.drive.get_drives(workspace)

List Files and Folders by Path

assets = shade.asset.listdir_files(
    drive=drive, path=Path('/'), page=0, limit=100
) 

folders = shade.asset.listdir_folders(
        drive=drive.get('id'),
        path=Path('/'),
        page=0,
        limit=100,  # Returns the path of the folder
    )
print('folders', folders)

Sharing a Folder

def share_folder():
    if shade.share.share_asset(
        drive=drive,
        asset_path=Path(folders[0]),
        email='<enter email>',
        role=DriveRole.EDITOR,
        message='Hello',
    ):
        print('Shared folder with user')

Sharing a File

For more information on roles check out Workspace and Drive Permissions

def share_file():
    if shade.share.share_asset(
        drive=drive,
        asset_path=Path(assets[0].get('path')),
        email='<enter email>',
        role=DriveRole.EDITOR,
        message='Hello you are invited',
    ):
        print('Shared file with user')

Getting a Download URL for an Asset

def get_signed_url():
    signed_url = shade.asset.get_signed_download_url(drive, asset.get('path'))
    print('signed_url', signed_url)

Searching

def search_in_folder():
    files = shade.asset.listdir_files(
        drive=drive,
        query=QueryBuilder()
        .set_query('city')
        .set_path('/38d862c3-7699-4ff0-b0fc-9be89c2f85af/shade_tests/places/nyc')
        .limit(50)
        .threshold(0)
        .finish(),
    )

    print(len(files))

More patterns can be found in our examples here

Last updated