pypi Office365-REST-Python-Client 2.1.10
v 2.1.10

latest releases: 2.5.9, 2.5.8, 2.5.7...
3 years ago

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

Don't miss a new Office365-REST-Python-Client release

NewReleases is sending notifications on new releases.