Folder

class tekdrive.models.Folder(tekdrive: TekDrive, id: Optional[str] = None, _data: Optional[Dict[str, Any]] = None)

A class representing a TekDrive folder.

Examples

Load a folder by id:

folder_id = "3b525331-9da7-4e8d-b045-4acdba8d9dc7"
folder = td.folder(folder_id)
created_at

When the folder was created.

Type

datetime

creator

Folder creator.

Type

Partial User

id

Unique ID of the folder.

Type

str

folder_type

Folder type such as "STANDARD", "PERSONAL", or "SHARES".

Type

str

name

Name of the folder.

Type

str

owner

Folder owner.

Type

Partial User

parent_folder_id

Unique ID of the folder’s parent folder.

Type

str

shared_at

When the folder was shared with the requesting user. Will be None if the user has direct access.

Type

datetime, optional

type

Type of TekDrive object - will always be "FOLDER".

Type

str

permissions

Folder permissions for the requesting user.

Type

Permissions

updated_at

When the folder was last updated.

Type

datetime, optional

add_member(username: Optional[str] = None, user_id: Optional[str] = None, edit_access: bool = False) → tekdrive.models.drive.member.Member

Share the folder with an existing or new user.

Parameters
  • username – The username (email) of the sharee.

  • user_id – The user ID of the sharee.

  • edit_access – Give member edit access?

Examples

Share with read only permissions (default):

folder_member = folder.add_member(username="read_only@example.com")

Share with edit permissions:

folder_member = folder.add_member(user_id="354bcafb-6c54-4a1f-9b94-a76f38b548e5", edit_access=True)
Returns

Member

children() → List[Union[tekdrive.models.drive.file.File, tekdrive.models.drive.folder.Folder]]

Get a list of child files and folders for the given folder.

Examples

Iterate over all folder children:

for child in folder.children():
    print(child.id)
Returns

List [ Union [File , Folder] ]

delete(hard_delete: bool = False) → None

Delete the folder, by default it will be placed in the user’s trashcan.

Parameters

hard_delete – Permanently delete the folder?

Examples

Delete - placing in trash:

folder.delete()

Delete - immediately delete:

folder.delete(hard_delete=True)
members() → List[tekdrive.models.drive.member.Member]

Get a list of folder members.

Examples

Iterate over all folder members:

for member in folder.members():
    print(member.username)
Returns

List [ Member ]

modify_member(user_id: str, edit_access: bool) → tekdrive.models.drive.member.Member

Modify an existing folder member.

Parameters
  • user_id – The user ID of the member.

  • edit_access – Give member edit access?

Examples

Grant edit access:

updated_folder_member = folder.modify_member(user_id="354bcafb-6c54-4a1f-9b94-a76f38b548e5", edit_access=True)

Revoke edit access:

updated_folder_member = folder.modify_member(user_id="354bcafb-6c54-4a1f-9b94-a76f38b548e5", edit_access=False)
Returns

Member

move(parent_folder_id: str) → None

Move folder.

Parameters

parent_folder_id – Unique ID of another folder to move the folder into.

Examples

Move by ID:

new_parent_folder_id = "1ae7fa38-9759-49f1-9e41-28a190b96023"
folder.move(new_parent_folder_id)

Move to newly created folder:

new_parent_folder = td.folder.create("FolderA")
folder.move(new_parent_folder.id)
remove_member(user_id: str) → None

Revoke access for a current folder member.

Parameters

user_id – The user ID of the member.

Examples

Remove member:

folder.remove_member(user_id="354bcafb-6c54-4a1f-9b94-a76f38b548e5")
restore() → None

Restore the folder from user’s trashcan.

Examples

Restore - remove from trash:

folder.restore()
save() → None

Save any changes to folder meta. Supported attributes: name.

Examples

Rename a folder:

folder.name = "my_new_name"
folder.save()
upload(path_or_readable: Union[str, IO], file_name: str)

Create a new file and automatically upload its contents directly into this folder.

Parameters
  • path_or_readable – Path to a local file or a readable stream representing the contents to upload.

  • file_name (optional) – Name of the new file.

Raises

ClientException – If invalid file path is given.

Examples

Upload using path:

here = os.path.dirname(__file__)
contents_path = os.path.join(here, "test_file_overwrite.txt")
folder.upload(contents_path, "my_new_file")

Upload using readable stream:

with open("./test_file.txt"), "rb") as f:
    folder.upload(f)