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.
data = client.get_data('<api_name>', '<options - optional>', '<version: api version - optional>')
ex)
data = client.get_data('users', {'$filter': "userPrincipalName eq 'youremail@yourdomain.com'", '$select': 'id'})
print(data)
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
py-msgraph-0.0.3.tar.gz
(3.9 kB
view hashes)
Built Distribution
Close
Hashes for py_msgraph-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed1e133a66001c8ee8bd813e90559e9b2c6968c9ca9a43df773701dcfb7a4e3a |
|
MD5 | 370cb6e39e03db1d06bf9b0c00879ec1 |
|
BLAKE2b-256 | b3a47e65b425ecb4d81956066c6647cccf5cbc60454908cb7a4d084d277a2a85 |