This is a work in progress package for utilizing Microsoft Graph for O365.
This project serves the purpose as a personal development project as well as a hopefully useful tool for the community.
Currently this project only supports SharePoint actions since this is my current need and not all SharePoint actions are implemented.
I'm using Protocol to define specific interfaces so others can create their own implmentations.
import msgraph
conn = msgraph.SharepointConnection()
sp = msgraph.SharepointGraphClient(conn)
response = sp.sites("YourSite/YourSubSite").lists("YourList").items().get()
The SharepointConnection object utilizes refresh tokens to gain authorization. The constructor of this object takes the following:
tenant_id- Your Microsoft Tenant IDclient_id- Your Client ID setup in Azureclient_secret- Your Client Secret created with your Client IDrefresh_token- An issued refresh token generated with the tenant and client info.scope- The authorization scope. The Client ID should have the same scope that's being requested.
When conn.headers is called, the SharepointConnection object checks if the current authorization is expired and will call conn.get_sharepoint_authorization(). Expiration is tracked internally on conn.expires property.
Extends the SharepointGraphClientBase class.
Implements the ISharepointGraphClient protocol.
conn:SharepointConnection- Required
This method adds an object that implements the IGraphResponse protocol to the list of requests that have been handled by the client.
This method returns a SharepointSite object and uses the passed in relative_site_url for building the Graph URI. The returning of a SharepointSite object is intended to be used to chain method calls together for readability of the Graph request.
Implements the ISharepointSite protocol.
relative_site_url:str- Requiredclient:SharepointGraphClientBase- Required
list_name:str- Optional
filter_func:Callable[...,list[IGraphFilter]]- Required
library_name:str- Required
url:str- Optional
Returns a string relative to the organization root for the relative_site_url passed to the constructor.
sites/root:/sites/relative_site_url:/
Calling filters() from SharepointSite object returns the instance of SharepointSite since this implements the get() method found on IGraphAction protocol.
Calling get() will return a GraphResponseBase which has the Response object from requests.models package. Sends HTTP request to the endpoint generated with the build_url() method.
Implements the ISharepointList protocol.
parent:ISharepointSite- Requiredclient:SharepointGraphClientBase- Requiredlist_name:str- Optional
item(id) -> ISharepointListItem
id:int- Required
items() -> ISharepointListItem
filters(filter_func) -> IGraphAction
filter_func:Callable[...,list[IGraphFilter]]- Required
get(url) -> IGraphResponse
url:str- Optional
build_url() -> str
build_filter_query() - str