library to use MS graph API
Project description
Installation
Use pip:
pip install py-msgraph
or
pip install git+https://github.com/shineum/py_msgraph.git
Prerequisite
To use MS graph API, MS application is necessary and tenant_id, client_id and client_secret are prepared. It is needed to assign the permissions in the MS application depending on the APIs.
Here are reference URLs.
# Set up a Tenant
https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-create-new-tenant
# Register an application
https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app
# Graph API Permissions
https://learn.microsoft.com/en-us/graph/permissions-reference
Getting Started
Initialize MSGraphServiceClient instance.
from py_msgraph import MSGraphServiceClient
config = {
'tenant_id': '<tentant_id>',
'client_id': '<client_id>',
'client_secret': '<client_secret>'
}
client: MSGraphServiceClient = MSGraphServiceClient(config)
Usages
Get data
To get data, use "get_data" method or "get_data_raw" method.
json_data = client.get_data('<api_name>', '<options - optional>', '<version: api version - optional>')
raw_response = client.get_data_raw('<api_name>', '<options - optional>', '<version: api version - optional>')
ex)
data = client.get_data('users', {'$filter': "userPrincipalName eq 'youremail@yourdomain.com'", '$select': 'id'})
print(data)
user_email = "youremail@yourdomain.com"
raw_response = client.get_data_raw(f"/users/{user_email}/photo/$value")
res_body = raw_response.content
Post request
To send post request, use "post_data" method.
result = client.post_data('<api_name>', '<data: request body - optional>', '<headers: headers - optional>', '<version: api version - optional>', '<files: attachment - optional>')
ex)
user_id = "<user guid>"
group_id = "<group guid>"
req_body = {
"@odata.id": f"https://graph.microsoft.com/v1.0/users/{user_id}"
}
result = client.post_data(f"groups/{group_id}/members/$ref", req_body)
print(result)
Others
This library also support put, patch and delete methods.
result = client.put_data('<api_name>', '<data: request body - optional>', '<headers: headers - optional>', '<version: api version - optional>', '<files: attachment - optional>')
result = client.patch_data('<api_name>', '<data: request body - optional>', '<headers: headers - optional>', '<version: api version - optional>', '<files: attachment - optional>')
result = client.delete_data('<api_name>', '<data: request body - optional>', '<headers: headers - optional>', '<version: api version - optional>', '<files: attachment - optional>')
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_msgraph-0.0.4.tar.gz.
File metadata
- Download URL: py_msgraph-0.0.4.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c2e7fb191cbe3d5b06e5b623c0fc87e317c7a8e46f491c54a23b1e903e4e7bc
|
|
| MD5 |
f35f96acd6007ca468bd25884ba09fd4
|
|
| BLAKE2b-256 |
d10dfbbf48bd53e3d8c3dcb36ce9dbabd95feeabc43ec66d4781cbf0bdfc7074
|
File details
Details for the file py_msgraph-0.0.4-py3-none-any.whl.
File metadata
- Download URL: py_msgraph-0.0.4-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a4cec6da8090353cfc0ca59c1329abfebf916ede9a74131bbec64e6ef59180d
|
|
| MD5 |
ffae5b9ba9846e008d70e5b68e48570d
|
|
| BLAKE2b-256 |
4fb4784f0d65e52df2348d0653d7dfc7706fd5a02b597103bd87946dcdc0ef72
|