Skip to content

Releases: vgrem/Office365-REST-Python-Client

v 2.2.0

12 Aug 19:30
Compare
Choose a tag to compare

Changelog

Finally the initial support for SharePoint API Batch requests has been introduced. All insert/update/delete operations are supported.

The following example how current user and web objects could be retrieved by grouping two operations and submitting it as a single request to the server:

client = ClientContext(site_url).with_credentials(user_credentials)
current_user = client.web.currentUser
client.load(current_user)
current_web = client.web
client.load(current_web)
client.execute_batch()

which offers a new way of improving the performance.

Among another improvements and changes:

  • improved support for Office365 auth with ADFS by @liuliqiu

  • style enforcement (flake8), code formatting (isort) configuration by @domdinicola

  • ClientRuntimeContext.execute_query_retry method which implements Retry pattern

v 2.1.10.1

01 Jul 20:29
Compare
Choose a tag to compare

The list of changes:

  • #216 bug fixed. Credit goes to @liuliqiu
  • improved support for SharePoint API permissions and sharing namespaces

v 2.1.10

21 Jun 10:41
Compare
Choose a tag to compare

The list of changes

API support for Fluent interface

ctx = ClientContext(settings['url']).with_credentials(credentials)

target_web = ctx.web.load().execute_query()  #method chaining
print(target_web.url)

Support for addressing Web and File resources by absolute Url

abs_file_url = "https://{tenant}.sharepoint.com/sites/team/Shared Documents/sample.docx".format(tenant=tenant)
user_credentials = UserCredential(username, password)

with open(local_path, 'wb') as local_file:
    file = File.from_url(abs_file_url).with_credentials(user_credentials).download(local_file).execute_query()
print("'{0}' file has been downloaded".format(file.serverRelativeUrl))

Support for SharePoint Search API

According to Documentation

Search in SharePoint includes a Search REST service you can use to add search functionality to your client and mobile applications by
using any technology that supports REST web requests.

Example

The following example demonstrates how to construct a search for a documents (via Keyword Query Language syntax) and print file url (Path managed property)

from office365.runtime.auth.userCredential import UserCredential
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.search.searchRequest import SearchRequest
from office365.sharepoint.search.searchService import SearchService
from settings import settings


ctx = ClientContext.connect_with_credentials(site_url,
                                             UserCredential(username, password))

search = SearchService(ctx)
request = SearchRequest("IsDocument:1")
result = search.post_query(request)
ctx.execute_query()
relevant_results = result.PrimaryQueryResult.RelevantResults
for i in relevant_results['Table']['Rows']:
    cells = relevant_results['Table']['Rows'][i]['Cells']
    print(cells[6]['Value'])

Support for SharePoint TenantAdministration namespace

The following example demonstrates how to create a site collection via Tenant.CreateSite method:

admin_site_url = "https://{0}-admin.sharepoint.com/".format(tenant)
credentials = UserCredential(username, password)
client = ClientContext(admin_site_url).with_credentials(credentials)
tenant = Tenant(client)

props = SiteCreationProperties(target_site_url, user_principal_name)
site_props = tenant.ensure_site(props)
client.execute_query()

Improved support for SharePoint fields namespace

Creating list item and setting multi lookup field value:

create_info = {
            "Title": "New task"
        }
multi_lookup_value = FieldMultiLookupValue()
multi_lookup_value.add(FieldLookupValue(lookup_id))
new_item = self.target_list.add_item(create_info)
new_item.set_property("Predecessors", multi_lookup_value)
client.load(items)
client.execute_query()

Updating list item with multi choice field value:

multi_choice_value = FieldMultiChoiceValue(["In Progress"])
item_to_update.set_property("TaskStatuses", multi_choice_value)
item_to_update.update()
client.execute_query()

Bug fixes

  • #210: connect to Office 365 with federated accounts, credit goes to @liuliqiu

  • #206: SharePoint Session API upload

v 2.1.9

04 Jun 00:18
Compare
Choose a tag to compare

The list of changes

  • initial support for Microsoft Teams API
  • improved support for working with paged data
  • introduced support for certificate authentication for SharePoint API
  • improvements and model updates for SharePoint and OneDrive APIs

and more

Initial support for [Microsoft Teams API

The support for Microsoft Teams API has been introduced, the following example demonstrates how how create a new team under a group which corresponds to Create team endpoint

tenant_name = "contoso.onmicrosoft.com"
client = GraphClient(tenant_name, get_token)
new_team = client.groups[group_id].add_team()
client.execute_query()

where

def get_token(auth_ctx):
    """Acquire token via client credential flow (ADAL Python library is utilized)
    :type auth_ctx: adal.AuthenticationContext
    """
    token = auth_ctx.acquire_token_with_client_credentials(
        "https://graph.microsoft.com",
        client_id,
        client_secret)
    return token

Improved support for working with paged data

Here is an example which demonstrates how to retrieve data from a SharePoint list which contains more then 5k items:

def print_progress(items_read):
    print("Items read: {0}".format(items_read))


ctx = ClientContext.connect_with_credentials(site_url,
                                             ClientCredential(client_id,client_secret))

list_source = ctx.web.lists.get_by_title("Contacts_Large")
items = list_source.items
items.page_loaded += print_progress  # page load event
items.page_size = 400  # specify custom page size (default is 100)
ctx.load(items)
ctx.execute_query()

#print("Items count: {0}".format(len(items)))
for item in items:
    print("{0}".format(item.properties['Title']))

Support for certificate authentication for SharePoint API

The example demonstrates how to connect to SharePoint Online with certificate credentials:

ctx = ClientContext.connect_with_certificate(site_url,
                                             client_id,
                                             thumbprint,
                                             certificate_path)

current_web = ctx.web
ctx.load(current_web)
ctx.execute_query()
print("{0}".format(current_web.url))

Refer how-to page for a more details

Improvements and model updates for SharePoint and OneDrive APIs

In terms of file and folder operations the following methods have been introduced:

  • File.download(file_object) - download a file content into a file object (SharePoint API)
  • Folder.copyto(new_folder_url, overwrite) - copy a folder (SharePoint API)
  • Folder.moveto(new_folder_url, flags) move a folder (SharePoint API)
  • DriveItem.download(file_object) - downloads a file content into a file object (OneDrive API)
  • DriveItem.get_content() - downloads a file content (OneDrive API)

Bug fixes for 2.1.8 and publish package to PyPi

15 Apr 21:37
a3b3e0e
Compare
Choose a tag to compare

Bug fixes (#183) and publish package to PyPi (PR #184)

v 2.1.8

30 Mar 23:54
Compare
Choose a tag to compare

Support for simplified methods to authenticate against SharePoint

Now for user credentials flow, instead of

ctx_auth = AuthenticationContext(url=site_url)
ctx_auth.acquire_token_for_user(username,password):
ctx = ClientContext(site_url, ctx_auth)

an authenticated client could be initialized like this:

ctx = ClientContext.connect_with_credentials(site_url, UserCredential(username,password))

and for client credentials flow (aka SharePoint App-Only) instead of

ctx_auth = AuthenticationContext(url=site_url)
ctx_auth.acquire_token_for_app(client_id,client_secret):
ctx = ClientContext(site_url, ctx_auth)

like this:

ctx = ClientContext.connect_with_credentials(site_url, ClientCredential(client_id,client_secret))

Introduced support for provision modern Team & Communication sites (#179)

Examples

Create a Team Site

client = ClientContext.connect_with_credentials(url,ClientCredential(client_id,client_secret))
site_manager = GroupSiteManager(client)
info = site_manager.create_group_ex("Team Site", "teamsite", True, None)
client.execute_query()

Create a Communication site

client = ClientContext.connect_with_credentials(url,ClientCredential(client_id,client_secret))
site_manager = SPSiteManager(client)
request = SPSiteCreationRequest("CommSite", "https://contoso.sharepoint.com/sites/commsite")
response = site_manager.create(request)
client.execute_query()

Bug fixes and feature requests

  • #174 and #28 - a bug which prevented to authenticate successfully with user credentials on not root site collections or a sub sites
  • #181 - missing types
  • #178 - introduced support for provision modern Team & Communication sites

v 2.1.7

21 Feb 22:41
Compare
Choose a tag to compare
  • Support for SAML-based federated authentication with SharePoint Online

  • Bug fixes and feature requests: #170 #171

v 2.1.6-1

09 Feb 12:52
Compare
Choose a tag to compare

Mainly unit testing bug fixes for Travis CI

v 2.1.6

03 Feb 15:50
Compare
Choose a tag to compare

The list of changes:

One Drive API:

SharePoint API:

support for chunk file upload, for example:


ctx = ClientContext(site_url, ctx_auth)
size_1Mb = 1000000
local_path = "./data/big_buck_bunny.mp4"
target_url = "/Shared Documents"

result_file = ctx.web.get_folder_by_server_relative_url(target_url)
       .files.create_upload_session(local_path, size_1Mb, print_upload_progress)
ctx.execute_query()

v 2.1.5

06 Dec 22:30
14c3955
Compare
Choose a tag to compare

Release changes:

  • GraphClient client has been introduced for working with Microsoft Graph endpoint
  • CAML query builder has been introduced (credit goes to @domdinicola)