Skip to main content

Microsoft Graph Python Client Library

Table of Contents

Overview

Microsoft Graph is the gateway to data and intelligence in Microsoft 365. It provides a unified programmability model that you can use to access the tremendous amount of data in Microsoft 365, Windows 10, and Enterprise Mobility + Security. This project utilizes python to help users interact with and manage data on Microsoft Graph API.

Setup

Setup - Requirements Install:

For this particular project, you only need to install the dependencies, to use the project. The dependencies are listed in the requirements.txt file and can be installed by running the following command:

pip install -r requirements.txt

After running that command, the dependencies should be installed.

Setup - Local Install:

If you are planning to make modifications to this project or you would like to access it before it has been indexed on PyPi. I would recommend you either install this project in editable mode or do a local install. For those of you, who want to make modifications to this project. I would recommend you install the library in editable mode.

If you want to install the library in editable mode, make sure to run the setup.py file, so you can install any dependencies you may need. To run the setup.py file, run the following command in your terminal.

pip install -e .

If you don't plan to make any modifications to the project but still want to use it across your different projects, then do a local install.

pip install .

This will install all the dependencies listed in the setup.py file. Once done you can use the library wherever you want.

Setup - PyPi Install:

To install the library, run the following command from the terminal.

pip install

Setup - PyPi Upgrade:

To upgrade the library, run the following command from the terminal.

pip install --upgrade

Usage

Here is a simple example of using the ms_graph library.

from pprint import pprint
from ms_graph.client import MicrosoftGraphClient
from configparser import ConfigParser

# Specify your scopes when you want access certain resources.
scopes = [
    'Calendars.ReadWrite',
    'Files.ReadWrite.All',
    'User.ReadWrite.All',
    'Notes.ReadWrite.All',
    'Directory.ReadWrite.All',
    'User.Read.All',
    'Directory.Read.All',
    'Directory.ReadWrite.All',
    'offline_access',
    'openid',
    'profile'
]

# Initialize the Parser.
config = ConfigParser()

# Read the file.
config.read('config/config.ini')

# Get the specified credentials.
client_id = config.get('graph_api', 'client_id')
client_secret = config.get('graph_api', 'client_secret')
redirect_uri = config.get('graph_api', 'redirect_uri')

# Initialize the Client.
graph_client = MicrosoftGraphClient(
    client_id=client_id,
    client_secret=client_secret,
    redirect_uri=redirect_uri,
    scope=scopes,
    credentials='config/ms_graph_state.jsonc'
)

# Login to the Client.
graph_client.login()


# Grab the User Services.
user_services = graph_client.users()

# List the Users.
pprint(user_services.list_users())


# Grab the Drive Services.
drive_services = graph_client.drives()

# List the Root Drive.
pprint(drive_services.get_root_drive())

Support These Projects

Patreon: Help support this project and future projects by donating to my Patreon Page. I'm always looking to add more content for individuals like yourself, unfortuantely some of the APIs I would require me to pay monthly fees.

YouTube: If you'd like to watch more of my content, feel free to visit my YouTube channel Sigma Coding.

Release files for ms-graph-python-client 0.1.0

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

Source distribution (sdist)

Source distribution for ms-graph-python-client 0.1.0
File Size Uploaded
ms-graph-python-client-0.1.0.tar.gz 22.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ms-graph-python-client 0.1.0
File Interpreter ABI Platform
ms_graph_python_client-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 51.5 kB

Release files / ms-graph-python-client-0.1.0.tar.gz

Download URL ms-graph-python-client-0.1.0.tar.gz
Size 22.5 kB
Tags Source
SHA-256 checksum
How to use checksums
bdc291c93d7a9249ae182e52f7b5b870149fbd3745ae74159ff9d514ba927fed
BLAKE2b-256 checksum
How to use checksums
e067f85ab3dbe61c21233dc3f97d5e0499d3b75c441add69d33dce7c20e5126c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Release files / ms_graph_python_client-0.1.0-py3-none-any.whl

Download URL ms_graph_python_client-0.1.0-py3-none-any.whl
Size 29.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e7050f12dde08c80d8315c5d0fe31af1a473c5f624df51c4bc68cb8f8100282
BLAKE2b-256 checksum
How to use checksums
979fd26d2a4d07805b0cd06287c2708d05eb27bc378c1ca1641ab42081625596
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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