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:
Though you can do this:
token = graph.get_access_token("graph").data
I wouldn't. An Error object has no data attribute, making this a footgun. Check the flag before unwrapping.
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.
Metadata
Release files for msgraph-pywrap 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| msgraph_pywrap-0.1.4.tar.gz | 7.8 kB | Without provenance | Details for msgraph_pywrap-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| msgraph_pywrap-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for msgraph_pywrap-0.1.4-py3-none-any.whl |
Total release size: 14.8 kB
Release files / msgraph_pywrap-0.1.4.tar.gz
| Download URL | msgraph_pywrap-0.1.4.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6e79596473c8a780fe04224a00799c046282be983fbdb6d844aa34a2e19e1472
|
|
BLAKE2b-256 checksum How to use checksums |
eacdd4330eb17545ac9c6f970097daf8bca8b2f6d954d1e3a38d5f8a83872c3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / msgraph_pywrap-0.1.4-py3-none-any.whl
| Download URL | msgraph_pywrap-0.1.4-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3caeec70bcb48dbcf57d0248627f4864f0082ad2220a8f5d33f7e32196b12e3e
|
|
BLAKE2b-256 checksum How to use checksums |
ffb94c06b45518d8f811c8a97e6f9510f8ef6ed57bc45daff07e5639151c61f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Security for msgraph-pywrap 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.