Skip to main content

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>')

Metadata

Release files for py-msgraph 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-msgraph 0.0.4
File Size Uploaded Provenance Actions
py_msgraph-0.0.4.tar.gz 4.0 kB Without provenance Details for py_msgraph-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for py-msgraph 0.0.4
File Interpreter ABI Platform Actions
py_msgraph-0.0.4-py3-none-any.whl Python 3 none any Details for py_msgraph-0.0.4-py3-none-any.whl

Total release size: 9.0 kB

Release files / py_msgraph-0.0.4.tar.gz

Download URL py_msgraph-0.0.4.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6c2e7fb191cbe3d5b06e5b623c0fc87e317c7a8e46f491c54a23b1e903e4e7bc
BLAKE2b-256 checksum
How to use checksums
d10dfbbf48bd53e3d8c3dcb36ce9dbabd95feeabc43ec66d4781cbf0bdfc7074
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.2

Release files / py_msgraph-0.0.4-py3-none-any.whl

Download URL py_msgraph-0.0.4-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a4cec6da8090353cfc0ca59c1329abfebf916ede9a74131bbec64e6ef59180d
BLAKE2b-256 checksum
How to use checksums
4fb4784f0d65e52df2348d0653d7dfc7706fd5a02b597103bd87946dcdc0ef72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.2

Security for py-msgraph 0.0.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page