One Drive

class O365.drive.CopyOperation(*, parent=None, con=None, **kwargs)[source]

Bases: O365.utils.utils.ApiComponent

https://github.com/OneDrive/onedrive-api-docs/issues/762

__init__(*, parent=None, con=None, **kwargs)[source]
Parameters
  • parent (Drive) – parent for this operation

  • con (Connection) – connection to use if no parent specified

  • protocol (Protocol) – protocol to use if no parent specified (kwargs)

  • main_resource (str) – use this resource instead of parent resource (kwargs)

  • monitor_url (str) –

  • item_id (str) –

check_status(delay=0)[source]

Checks the api endpoint in a loop

Parameters

delay – number of seconds to wait between api calls. Note Connection ‘requests_delay’ also apply.

Returns

tuple of status and percentage complete

Return type

tuple(str, float)

get_item()[source]

Returns the item copied

Returns

Copied Item

Return type

DriveItem

class O365.drive.DownloadableMixin[source]

Bases: object

download(to_path=None, name=None, chunk_size='auto', convert_to_pdf=False, output=None)[source]

Downloads this file to the local drive. Can download the file in chunks with multiple requests to the server.

Parameters
  • to_path (str or Path) – a path to store the downloaded file

  • name (str) – the name you want the stored file to have.

  • chunk_size (int) – number of bytes to retrieve from each api call to the server. if auto, files bigger than SIZE_THERSHOLD will be chunked (into memory, will be however only 1 request)

  • convert_to_pdf (bool) – will try to download the converted pdf if file extension in ALLOWED_PDF_EXTENSIONS

  • output (RawIOBase) – (optional) an opened io object to write to. if set, the to_path and name will be ignored

Returns

Success / Failure

Return type

bool

class O365.drive.Drive(*, parent=None, con=None, **kwargs)[source]

Bases: O365.utils.utils.ApiComponent

A Drive representation. A Drive is a Container of Folders and Files and act as a root item

__init__(*, parent=None, con=None, **kwargs)[source]

Create a drive representation

Parameters
  • parent (Drive or Storage) – parent for this operation

  • con (Connection) – connection to use if no parent specified

  • protocol (Protocol) – protocol to use if no parent specified (kwargs)

  • main_resource (str) – use this resource instead of parent resource (kwargs)

get_child_folders(limit=None, *, query=None, order_by=None, batch=None)[source]

Returns all the folders inside this folder

Parameters
  • limit (int) – max no. of folders to get. Over 999 uses batch.

  • query (Query or str) – applies a OData filter to the request

  • order_by (Query or str) – orders the result set based on this condition

  • batch (int) – batch size, retrieves items in batches allowing to retrieve more items than the limit.

Returns

folder items in this folder

Return type

generator of DriveItem or Pagination

get_item(item_id)[source]

Returns a DriveItem by it’s Id

Returns

one item

Return type

DriveItem

get_item_by_path(item_path)[source]

Returns a DriveItem by it’s path: /path/to/file :return: one item :rtype: DriveItem

get_items(limit=None, *, query=None, order_by=None, batch=None)[source]

Returns a collection of drive items from the root folder

Parameters
  • limit (int) – max no. of items to get. Over 999 uses batch.

  • query (Query or str) – applies a OData filter to the request

  • order_by (Query or str) – orders the result set based on this condition

  • batch (int) – batch size, retrieves items in batches allowing to retrieve more items than the limit.

Returns

items in this folder

Return type

generator of DriveItem or Pagination

get_recent(limit=None, *, query=None, order_by=None, batch=None)[source]

Returns a collection of recently used DriveItems

Parameters
  • limit (int) – max no. of items to get. Over 999 uses batch.

  • query (Query or str) – applies a OData filter to the request

  • order_by (Query or str) – orders the result set based on this condition

  • batch (int) – batch size, retrieves items in batches allowing to retrieve more items than the limit.

Returns

items in this folder

Return type

generator of DriveItem or Pagination

get_root_folder()[source]

Returns the Root Folder of this drive

Returns

Root Folder

Return type

DriveItem

get_shared_with_me(limit=None, *, query=None, order_by=None, batch=None)[source]

Returns a collection of DriveItems shared with me

Parameters
  • limit (int) – max no. of items to get. Over 999 uses batch.

  • query (Query or str) – applies a OData filter to the request

  • order_by (Query or str) – orders the result set based on this condition

  • batch (int) – batch size, retrieves items in batches allowing to retrieve more items than the limit.

Returns

items in this folder

Return type

generator of DriveItem or Pagination

get_special_folder(name)[source]

Returns the specified Special Folder

Returns

a special Folder

Return type

drive.Folder

refresh()[source]

Updates this drive with data from the server

Returns

Success / Failure

Return type

bool

search(search_text, limit=None, *, query=None, order_by=None, batch=None)[source]

Search for DriveItems under this drive. Your app can search more broadly to include items shared with the current user.

To broaden the search scope, use this search instead the Folder Search.

The search API uses a search service under the covers, which requires indexing of content.

As a result, there will be some time between creation of an item and when it will appear in search results.

Parameters
  • search_text (str) – The query text used to search for items. Values may be matched across several fields including filename, metadata, and file content.

  • limit (int) – max no. of items to get. Over 999 uses batch.

  • query (Query or str) – applies a OData filter to the request

  • order_by (Query or str) – orders the result set based on this condition

  • batch (int) – batch size, retrieves items in batches allowing to retrieve more items than the limit.

Returns

items in this folder matching search

Return type

generator of DriveItem or Pagination

class O365.drive.DriveItem(*, parent=None, con=None, **kwargs)[source]

Bases: O365.utils.utils.ApiComponent

A DriveItem representation. Groups all functionality

__init__(*, parent=None, con=None, **kwargs)[source]

Create a DriveItem

Parameters
  • parent (Drive or drive.Folder) – parent for this operation

  • con (Connection) – connection to use if no parent specified

  • protocol (Protocol) – protocol to use if no parent specified (kwargs)

  • main_resource (str) – use this resource instead of parent resource (kwargs)

copy(target=None, name=None)[source]

Asynchronously creates a copy of this DriveItem and all it’s child elements.

Parameters
  • target (drive.Folder or Drive) – target location to move to. If it’s a drive the item will be moved to the root folder.

  • name – a new name for the copy.

Return type

CopyOperation

delete()[source]

Moves this item to the Recycle Bin

Returns

Success / Failure

Return type

bool

get_drive()[source]

Returns this item drive :return: Drive of this item :rtype: Drive or None

get_parent()[source]

the parent of this DriveItem

Returns

Parent of this item

Return type

Drive or drive.Folder

get_permissions()[source]

Returns a list of DriveItemPermissions with the permissions granted for this DriveItem.

Returns

List of Permissions

Return type

list[DriveItemPermission]

get_thumbnails(size=None)[source]

Returns this Item Thumbnails. Thumbnails are not supported on SharePoint Server 2016.

Parameters

size – request only the specified size: ej: “small”, Custom 300x400 px: “c300x400”, Crop: “c300x400_Crop”

Returns

Thumbnail Data

Return type

dict

get_version(version_id)[source]

Returns a version for specified id

Returns

a version object of specified id

Return type

DriveItemVersion

get_versions()[source]

Returns a list of available versions for this item

Returns

list of versions

Return type

list[DriveItemVersion]

property is_file

Returns if this DriveItem is a File

property is_folder

Returns if this DriveItem is a Folder

property is_image

Returns if this DriveItem is a Image

property is_photo

Returns if this DriveItem is a Photo

move(target)[source]

Moves this DriveItem to another Folder. Can’t move between different Drives.

Parameters

target (drive.Folder or DriveItem or str) – a Folder, Drive item or Item Id string. If it’s a drive the item will be moved to the root folder.

Returns

Success / Failure

Return type

bool

share_with_invite(recipients, require_sign_in=True, send_email=True, message=None, share_type='view')[source]

Sends an invitation to access or edit this DriveItem

Parameters
  • recipients (list[str] or list[Contact] or str or Contact) – a string or Contact or a list of the former representing recipients of this invitation

  • require_sign_in (bool) – if True the recipients invited will need to log in to view the contents

  • send_email (bool) – if True an email will be send to the recipients

  • message (str) – the body text of the message emailed

  • share_type (str) – ‘view’: will allow to read the contents. ‘edit’ will allow to modify the contents

Returns

link to share

Return type

DriveItemPermission

Creates or returns a link you can share with others

Parameters
  • share_type (str) – ‘view’ to allow only view access, ‘edit’ to allow editions, and ‘embed’ to allow the DriveItem to be embedded

  • share_scope (str) – ‘anonymous’: anyone with the link can access. ‘organization’ Only organization members can access

Returns

link to share

Return type

DriveItemPermission

update(**kwargs)[source]

Updates this item

Parameters

kwargs – all the properties to be updated. only name and description are allowed at the moment.

Returns

Success / Failure

Return type

bool

class O365.drive.DriveItemPermission(*, parent=None, con=None, **kwargs)[source]

Bases: O365.utils.utils.ApiComponent

A Permission representation for a DriveItem

__init__(*, parent=None, con=None, **kwargs)[source]

Permissions for DriveItem

Parameters
  • parent (DriveItem) – parent for this operation

  • con (Connection) – connection to use if no parent specified

  • protocol (Protocol) – protocol to use if no parent specified (kwargs)

  • main_resource (str) – use this resource instead of parent resource (kwargs)

delete()[source]

Deletes this permission. Only permissions that are not inherited can be deleted.

Returns

Success / Failure

Return type

bool

update_roles(roles='view')[source]

Updates the roles of this permission

Returns

Success / Failure

Return type

bool

class O365.drive.DriveItemVersion(*, parent=None, con=None, **kwargs)[source]

Bases: O365.utils.utils.ApiComponent, O365.drive.DownloadableMixin

A version of a DriveItem

__init__(*, parent=None, con=None, **kwargs)[source]

Version of DriveItem

Parameters
  • parent (DriveItem) – parent for this operation

  • con (Connection) – connection to use if no parent specified

  • protocol (Protocol) – protocol to use if no parent specified (kwargs)

  • main_resource (str) – use this resource instead of parent resource (kwargs)

download(to_path=None, name=None, chunk_size='auto', convert_to_pdf=False)[source]

Downloads this version. You can not download the current version (last one).

Returns

Success / Failure

Return type

bool

restore()[source]

Restores this DriveItem Version. You can not restore the current version (last one).

Returns

Success / Failure

Return type

bool

class O365.drive.File(**kwargs)[source]

Bases: O365.drive.DriveItem, O365.drive.DownloadableMixin

A File

__init__(**kwargs)[source]

Create a DriveItem

Parameters
  • parent (Drive or drive.Folder) – parent for this operation

  • con (Connection) – connection to use if no parent specified

  • protocol (Protocol) – protocol to use if no parent specified (kwargs)

  • main_resource (str) – use this resource instead of parent resource (kwargs)

property extension
class O365.drive.Folder(*args, **kwargs)[source]

Bases: O365.drive.DriveItem

A Folder inside a Drive

__init__(*args, **kwargs)[source]

Create a DriveItem

Parameters
  • parent (Drive or drive.Folder) – parent for this operation

  • con (Connection) – connection to use if no parent specified

  • protocol (Protocol) – protocol to use if no parent specified (kwargs)

  • main_resource (str) – use this resource instead of parent resource (kwargs)

create_child_folder(name, description=None)[source]

Creates a Child Folder

Parameters
  • name (str) – the name of the new child folder

  • description (str) – the description of the new child folder

Returns

newly created folder

Return type

drive.Folder

download_contents(to_folder=None)[source]

This will download each file and folder sequentially. Caution when downloading big folder structures

Parameters

to_folder (drive.Folder) – folder where to store the contents

get_child_folders(limit=None, *, query=None, order_by=None, batch=None)[source]

Returns all the folders inside this folder

Parameters
  • limit (int) – max no. of folders to get. Over 999 uses batch.

  • query (Query or str) – applies a OData filter to the request

  • order_by (Query or str) – orders the result set based on this condition

  • batch (int) – batch size, retrieves items in batches allowing to retrieve more items than the limit.

Returns

folder items in this folder

Return type

generator of DriveItem or Pagination

get_items(limit=None, *, query=None, order_by=None, batch=None)[source]

Returns generator all the items inside this folder

Parameters
  • limit (int) – max no. of folders to get. Over 999 uses batch.

  • query (Query or str) – applies a OData filter to the request

  • order_by (Query or str) – orders the result set based on this condition

  • batch (int) – batch size, retrieves items in batches allowing to retrieve more items than the limit.

Returns

items in this folder

Return type

generator of DriveItem or Pagination

search(search_text, limit=None, *, query=None, order_by=None, batch=None)[source]

Search for DriveItems under this folder The search API uses a search service under the covers, which requires indexing of content.

As a result, there will be some time between creation of an item and when it will appear in search results.

Parameters
  • search_text (str) – The query text used to search for items. Values may be matched across several fields including filename, metadata, and file content.

  • limit (int) – max no. of folders to get. Over 999 uses batch.

  • query (Query or str) – applies a OData filter to the request

  • order_by (Query or str) – orders the result set based on this condition

  • batch (int) – batch size, retrieves items in batches allowing to retrieve more items than the limit.

Returns

items in this folder matching search

Return type

generator of DriveItem or Pagination

upload_file(item, item_name=None, chunk_size=5242880, upload_in_chunks=False, stream=None, stream_size=None, conflict_handling=None)[source]

Uploads a file

Parameters
  • item (str or Path) – path to the item you want to upload

  • item_name (str or Path) – name of the item on the server. None to use original name

  • chunk_size – Only applies if file is bigger than 4MB or upload_in_chunks is True. Chunk size for uploads. Must be a multiple of 327.680 bytes

  • upload_in_chunks – force the method to upload the file in chunks

  • stream (io.BufferedIOBase) – (optional) an opened io object to read into. if set, the to_path and name will be ignored

  • stream_size (int) – size of stream, required if using stream

  • conflict_handling (str) – How to handle conflicts. NOTE: works for chunk upload only (>4MB or upload_in_chunks is True) None to use default (overwrite). Options: fail | replace | rename

Returns

uploaded file

Return type

DriveItem

class O365.drive.Image(**kwargs)[source]

Bases: O365.drive.File

An Image

__init__(**kwargs)[source]

Create a DriveItem

Parameters
  • parent (Drive or drive.Folder) – parent for this operation

  • con (Connection) – connection to use if no parent specified

  • protocol (Protocol) – protocol to use if no parent specified (kwargs)

  • main_resource (str) – use this resource instead of parent resource (kwargs)

property dimensions

Dimension of the Image

Returns

width x height

Return type

str

class O365.drive.Photo(**kwargs)[source]

Bases: O365.drive.Image

Photo Object. Inherits from Image but has more attributes

__init__(**kwargs)[source]

Create a DriveItem

Parameters
  • parent (Drive or drive.Folder) – parent for this operation

  • con (Connection) – connection to use if no parent specified

  • protocol (Protocol) – protocol to use if no parent specified (kwargs)

  • main_resource (str) – use this resource instead of parent resource (kwargs)

class O365.drive.Storage(*, parent=None, con=None, **kwargs)[source]

Bases: O365.utils.utils.ApiComponent

Parent Class that holds drives

__init__(*, parent=None, con=None, **kwargs)[source]

Create a storage representation

Parameters
  • parent (Account) – parent for this operation

  • con (Connection) – connection to use if no parent specified

  • protocol (Protocol) – protocol to use if no parent specified (kwargs)

  • main_resource (str) – use this resource instead of parent resource (kwargs)

drive_constructor

alias of Drive

get_default_drive(request_drive=False)[source]

Returns a Drive instance

Parameters

request_drive – True will make an api call to retrieve the drive data

Returns

default One Drive

Return type

Drive

get_drive(drive_id)[source]

Returns a Drive instance

Parameters

drive_id – the drive_id to be retrieved

Returns

Drive for the id

Return type

Drive

get_drives()[source]

Returns a collection of drives