Skip to main content

A library and cli tool for interfacing with Microsoft's Graph API.

Project description

msgapi : Microsoft GraphAPI library

A python library and tool for interfacing with Microsoft's Graph API.


pip install msgapi


There is an example graph config file supplied with some defaults at msgapi/etc/graph_config.ini . You can fill in your GraphAPI details directly or copy that file and complete it. The msgapi.config.GRAPH_CONFIG object (and the cli tool) will load configurations along the following paths:

GRAPH_CONFIG_TEMPLATE = os.path.join(HOME_PATH, ETC_DIR, 'graph_config.ini')
GLOBAL_GRAPH_CONFIG = '/etc/msgraph/graph_config.ini'
USER_GRAPH_CONFIG = os.path.join(os.path.expanduser("~"),'.config', 'msgapi', 'graph_config.ini')
# Later configs override earlier configs

You can also supply your configurations to the msgapi.GraphAPI object like so:

graph_config = msgapi.config.load_config(['/your/config/path'])
client_app = msgapi.GraphAPI(graph_config)

On the CLI it's "msgraphi"

A CLI tool is included named msgraphi. The tool was written to take advantage of "resource configurations" to allow for quick and dynamic evaluation/use of the stupid number of MS graph rest resources that are available for consumption. These resource configurations are dynamically added to msgraphi as cli arguments. See the resource configuration section for more details.

There are also some built in methods available via the cli tool that are defined in the Such as scramble-password and some email related functionality.

Also, a -raw request resource available on the cli that allows you to pass resoure requests directly to the GraphAPI client request method.

Resource Configurations

There were so many ms graph api resources to test for various things I made a resource config parser so I could evaluate resources quickly and save them for future use. This way code doesn't have to be written to test things or for data carving on the command line.

There is a template

There is a template with some more explainations for how these fields are parsed and evaluated at msgapi/etc/resource_configuration_template.ini:

; The name you want to give this resource, usually something very similar to the REST resource name itself
; A description of the resource, perhaps with link to MS documentation too

# Use the arguments section to define any required or optional arguments you
# want to pass to the REST resource as parameters
; comma seperated list of required arguments that MUST be supplied to the resource at run time
; comma seperated list of optional arguments that can be overridden, but MUST have defaults defined
; example optional:
; Then you'd have to have a riskState and riskLevel key in this section, with a value defined for each, like so:

# The argument_help section should contain helpful descriptions of arguments defined in the arguments section
; example
#riskLastUpdatedDateTime=The date and time that the risky user was last updated. Ex: 2020-03-19T00:00:00.000Z

# The resource section describes the MS Graph API resource and how to query it. The parameters key is not required.
; The MS Graph API version. (required) example: beta or v1.0 
; The location of the resource. (required) example: riskyUsers or 'security/alerts'
; The format of how you would like to pass any parameters to this resource
; note that you have to include the '/' or '?$' depending on your needs
; example:
#parameters=?$filter=riskLevel eq microsoft.graph.riskLevel'{riskLevel}' and riskState eq microsoft.graph.riskState'{riskState}' and riskLastUpdatedDateTime gt {riskLastUpdatedDateTime}

Example resource config

Showing msgapi/resource_configurations/riskyUsers.ini:

description=List risky users and their properties. (

# optinal argument defauls

riskLastUpdatedDateTime=The date and time that the risky user was last updated. Ex: 2020-03-19T00:00:00.000Z
riskState=possible values are confirmedSafe, remediated, atRisk, unknownFutureValue
riskLevel=possible values are low, medium, high, hidden

parameters=?$filter=riskLevel eq microsoft.graph.riskLevel'{riskLevel}' and riskState eq microsoft.graph.riskState'{riskState}' and riskLastUpdatedDateTime gt {riskLastUpdatedDateTime}
There are several resource configurations included:
$ grep -r msgapi/resource_configurations/ -e name


Thanks to Kyle Piper for writing the initial GraphAPI and GraphConfig classes. This library was started by swiping those classes from the code Kyle wrote for ACE located here: There are also several functions in this projects that were written by Kyle 👏.

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

msgapi-1.0.0.tar.gz (14.5 kB view hashes)

Uploaded source

Built Distribution

msgapi-1.0.0-py3-none-any.whl (18.2 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page