Skip to main content

Utility for abstracting connections to Microsoft's Graph API and Sharepoint.

Project description

Project Msgraph

Python module/utility that abstracts away some interactions with Microsoft's Graph API. Currently includes ways to get sharepoint site IDs with an user-provided domain, get sharepoint drive IDs, generate access tokens with three different scopes, upload files and send e-mails with attachments. Before using this utility, make sure your app has user consent through Microsoft, as well as Microsoft Graph permissions. For further information, check the following documentation:

Microsoft Permissions Consent Overview

Microsoft Permissions Reference

Features

  • Acquire access tokens for Microsoft Graph, Outlook or custom audiences
  • Retrieve SharePoint site and drive IDs
  • Upload files to SharePoint document libraries
  • Send e-mails through parameters and a function, add N attachments, send to N e-mail addresses.
  • Download files from sharepoint folders
  • Non-halting error handling: This module will attempt to return an error object instead of raising exceptions. If this is ever not the case, please let me know!

Usage

Install the package via pip, like so:

pip install msgraph-pywrap

Setup the class like so:

from msgraph.msgraph import Msgraph

credentials = {
    "clientid": "foo",
    "tenantid": "bar",
    "clientsecret": "foz",
    "audience": "foo.sharepoint.com",
    "refresh_token": "bazbazbaz"
}

graph = Msgraph(credentials)

From here, you'll have access to the rest of the methods.

For example, here's how you'd get an access token with the Graph API scope, with proper handling:

token_response = graph.get_access_token("graph")

if token_response.is_ok:
    token = token_response.unwrap()
else:
    ...
    # Process upon failure goes here:

Or, if you're sure all will be fine:

token = graph.get_access_token("graph").data

Just remember to either unwrap the response, or get the data property of the success response in order to actually access the data you want to return.

Let's send an e-mail through Outlook!

from msgraph.msgraph import Msgraph

credentials = {
    "clientid": "foo",
    "tenantid": "bar",
    "clientsecret": "foz",
    "audience": "foo.sharepoint.com",
    "refresh_token": "bazbazbaz"
}

graph = Msgraph(credentials)

token_response = graph.get_access_token("outlook")

if token_response.is_ok:
    token = token_response.unwrap()
else:
    ...
    # Process error here:

result_mail = graph.send_email(token, "any subject", "any message", ["target@emails.com"], ["path/to/attachment"])

if result_mail.is_ok:
    print("E-mail sent!")
else:
    ...
    # Process error here:

Most functions will follow this pattern, read the docstrings for the parameters required.

Any bugs found, feel free to open an issue.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

msgraph_pywrap-0.1.3.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

msgraph_pywrap-0.1.3-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file msgraph_pywrap-0.1.3.tar.gz.

File metadata

  • Download URL: msgraph_pywrap-0.1.3.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for msgraph_pywrap-0.1.3.tar.gz
Algorithm Hash digest
SHA256 a30cc1fd97b04e634aa08b86bc01e83993dce9670baa13a4b94157a74818d70b
MD5 988b33b99137ac9de9e6d8a20af433a9
BLAKE2b-256 e0d42499da767f17b45081dcea4f0c8d140fad32151a18c2f4913da1cd1051b0

See more details on using hashes here.

File details

Details for the file msgraph_pywrap-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: msgraph_pywrap-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for msgraph_pywrap-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d277cc2adf0af105f5ee67a1cfa6c3f03150484e3ade18288d573cf0ebeff401
MD5 5ee668626f7a152a0ffabaf112d59930
BLAKE2b-256 bfa7c2fe2e0791544c2fc33958bb3a129972be11e72d19d53839bbfad4481046

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page