# 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](/developers/readme.md) before continuing with these patterns

### Get All Workspaces for Your User

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

### Get All Drives of a Workspace

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

### List Files and Folders by Path

```python
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

```python
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](/sharing-and-collaboration/workspace-and-drive-permissions.md)

```python
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

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

### Searching

```python
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](https://github.com/shade-labs/shade-python-sdk/tree/main/examples)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://academy.shade.inc/developers/common-patterns.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
