
Product
Announcing Precomputed Reachability Analysis in Socket
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
microsoftgraph-python
Advanced tools
Microsoft graph API wrapper for Microsoft Graph written in Python.
To use Microsoft Graph to read and write resources on behalf of a user, your app must get an access token from the Microsoft identity platform and attach the token to requests that it sends to Microsoft Graph. The exact authentication flow that you will use to get access tokens will depend on the kind of app you are developing and whether you want to use OpenID Connect to sign the user in to your app. One common flow used by native and mobile apps and also by some Web apps is the OAuth 2.0 authorization code grant flow.
See Get access on behalf of a user
client.get_me()
=> client.users.get_me()
.client.get_me_events()
=> client.calendar.list_events()
..data
attribute for e.g r = client.users.get_me()
then r.data
.api_version
in the client instantiation.r = client.users.get_me()
then r.original
or the response handled by the library r.data
.r.status_code
and r.throttling
.requests_hooks
in the client instantiation. If you are using Django and want to log in database every request made through this library, see django-requests-logger.paginate
parameter in client initialization. Defaults to True
.pip install microsoftgraph-python
from microsoftgraph.client import Client
client = Client('CLIENT_ID', 'CLIENT_SECRET', account_type='common') # by default common, thus account_type is optional parameter.
url = client.authorization_url(redirect_uri, scope, state=None)
response = client.exchange_code(redirect_uri, code)
response = client.refresh_token(redirect_uri, refresh_token)
client.set_token(token)
response = client.users.get_me()
response = client.mail.list_messages()
response = client.mail.get_message(message_id)
data = {
subject="Meet for lunch?",
content="The new cafeteria is open.",
content_type="text",
to_recipients=["fannyd@contoso.onmicrosoft.com"],
cc_recipients=None,
save_to_sent_items=True,
}
response = client.mail.send_mail(**data)
response = client.mail.list_mail_folders()
response = client.mail.create_mail_folder(display_name)
response = client.notes.list_notebooks()
response = client.notes.get_notebook(notebook_id)
response = client.notes.list_sections(notebook_id)
response = client.notes.list_pages()
response = client.notes.create_page(section_id, files)
response = client.calendar.list_events(calendar_id)
response = client.calendar.get_event(event_id)
from datetime import datetime, timedelta
start_datetime = datetime.now() + timedelta(days=1) # tomorrow
end_datetime = datetime.now() + timedelta(days=1, hours=1) # tomorrow + one hour
timezone = "America/Bogota"
data = {
"calendar_id": "CALENDAR_ID",
"subject": "Let's go for lunch",
"content": "Does noon work for you?",
"content_type": "text",
"start_datetime": start_datetime,
"start_timezone": timezone,
"end_datetime": end_datetime,
"end_timezone": timezone,
"location": "Harry's Bar",
}
response = client.calendar.create_event(**data)
response = client.calendar.list_calendars()
response = client.calendar.create_calendar(name)
response = client.contacts.get_contact(contact_id)
response = client.contacts.list_contacts()
data = {
"given_name": "Pavel",
"surname": "Bansky",
"email_addresses": [
{
"address": "pavelb@fabrikam.onmicrosoft.com",
"name": "Pavel Bansky"
}
],
"business_phones": [
"+1 732 555 0102"
],
"folder_id": None,
}
response = client.contacts.create_contact(**data)
response = client.contacts.list_contact_folders()
response = client.contacts.create_contact_folder()
response = client.files.drive_root_items()
response = client.files.drive_root_children_items()
response = client.files.drive_specific_folder(folder_id)
response = client.files.drive_get_item(item_id)
response = client.files.drive_download_contents(item_id)
# This example uploads the image in path to a file in the signed-in user's drive under Pictures named upload.jpg.
response = client.files.drive_upload_new_file("/Pictures/upload.jpg", "/mnt/c/Users/i/Downloads/image1.jpg")
# This example uploads the image in path to update an existing item id.
response = client.files.drive_update_existing_file(item_id, "/mnt/c/Users/i/Downloads/image2.jpg")
query = ".xlsx, .xlsm"
response = client.files.search_items(query)
response = client.workbooks.create_session(workbook_id)
response = client.workbooks.refresh_session(workbook_id)
response = client.workbooks.close_session(workbook_id)
response = client.workbooks.list_worksheets(workbook_id)
response = client.workbooks.get_worksheet(workbook_id, worksheet_id)
response = client.workbooks.add_worksheet(workbook_id)
response = client.workbooks.update_worksheet(workbook_id, worksheet_id)
response = client.workbooks.list_charts(workbook_id, worksheet_id)
response = client.workbooks.add_chart(workbook_id, worksheet_id)
response = client.workbooks.list_tables(workbook_id)
response = client.workbooks.add_table(workbook_id)
response = client.workbooks.create_table_column(workbook_id, worksheet_id, table_id)
response = client.workbooks.create_table_row(workbook_id, worksheet_id, table_id)
response = client.workbooks.list_table_rows(workbook_id, table_id)
response = client.workbooks.get_range(workbook_id, worksheet_id)
response = client.workbooks.get_used_range(workbook_id, worksheet_id)
response1 = client.workbooks.create_session(workbook_id)
workbook_session_id = response1.data["id"]
client.set_workbook_session_id(workbook_session_id)
range_address = "A1:D2"
data = {
"values": [
["John", "Doe", "+1 305 1234567", "Miami, FL"],
["Bill", "Gates", "+1 305 1234567", "St. Redmond, WA"],
]
}
response2 = client.workbooks.update_range(workbook_id, worksheet_id, range_address, json=data)
response3 = client.worbooks.close_session(workbook_id)
response = client.webhooks.create_subscription(change_type, notification_url, resource, expiration_datetime, client_state=None)
response = client.webhooks.renew_subscription(subscription_id, expiration_datetime)
response = client.webhooks.delete_subscription(subscription_id)
test/test.py
FAQs
API wrapper for Microsoft Graph written in Python
We found that microsoftgraph-python demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.