Releases: vgrem/Office365-REST-Python-Client
v 2.2.0
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
v 2.1.10
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
v 2.1.9
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
v 2.1.8
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)
-
GroupSiteManager.create_group_ex - create a Team site
-
SPSiteManager.create - create a Communication site
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
v 2.1.7
v 2.1.6-1
v 2.1.6
The list of changes:
One Drive API:
-
introduced new resources such as
ContentType
,ColumnDefinition
-
support for Resumable file upload
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
Release changes:
GraphClient
client has been introduced for working with Microsoft Graph endpoint- CAML query builder has been introduced (credit goes to @domdinicola)