Office365-rest-python-client

Latest version: v2.5.9

Safety actively analyzes 629765 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 7 of 9

2.1.61

Mainly unit testing bug fixes for Travis CI

2.1.10.1

The list of changes:

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

2.1.10

The list of changes


API support for [Fluent interface](https://en.wikipedia.org/wiki/Fluent_interface#Python)


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](https://docs.microsoft.com/en-us/sharepoint/dev/general-development/sharepoint-search-rest-api-overview)

> 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](https://docs.microsoft.com/en-us/sharepoint/dev/general-development/keyword-query-language-kql-syntax-reference?redirectedfrom=MSDN) 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](https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-csom/dn174891(v=office.15))

The following example demonstrates how to create a site collection via [`Tenant.CreateSite method`](https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-csom/dn174769(v=office.15)):


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

2.1.9

The list of changes

- initial support for [Microsoft Teams API](https://docs.microsoft.com/en-us/graph/api/resources/teams-api-overview?view=graph-rest-1.0)
- improved support for working with [paged data](https://docs.microsoft.com/en-us/graph/paging)
- 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](https://docs.microsoft.com/en-us/graph/api/team-put-teams?view=graph-rest-1.0&tabs=http)


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](https://github.com/vgrem/Office365-REST-Python-Client/blob/master/examples/sharepoint/ConnectionWithCert.md) 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)

2.1.8.1

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

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](https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs)) 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](https://support.office.com/en-us/article/create-a-team-site-in-sharepoint-ef10c1e7-15f3-42a3-98aa-b5972711777d)

- SPSiteManager.create - create a [Communication site](https://docs.microsoft.com/en-us/sharepoint/dev/apis/site-creation-rest)

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

Page 7 of 9

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.