Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading Outlook calendar events in Python

I need to get the events for the current day from a personal Outlook calendar. I have found next to no feasible resources online besides maybe Microsoft's tutorial (https://learn.microsoft.com/en-us/graph/tutorials/python), but I do not want to build a Django app. Can anyone provide some other resources?

also: I have seen a lot of ppl calling APIs by using a GET <url> command. I cannot for the life of me understand how or where you can use this? Am I missing something crucial when it comes to using APIs?

like image 516
Dragos Spiridon Avatar asked Dec 09 '25 07:12

Dragos Spiridon


1 Answers

For this purpose without using Microsoft Graph API via request in python, there is a PyPI package named O365.

By the following procedure you can easily read a Microsoft calendar:

  1. install the package: pip install O365
  2. register an application in the Microsoft Azure console and keep the application (client) id as well as client secret — this article can help you up.
  3. check the signInAudience, it should be AzureADandPersonalMicrosoftAccount not PersonalMicrosoftAccount within Microsft Azure Manifest, otherwise, you can edit that.
  4. next you should set delegated permission to what scopes you want, in your case it's Calendars.Read. Here's a snapshot of my configuration in Azure:

enter image description here

Now it's time to dive into the code:

from O365 import Account

CLIENT_ID = "xxx"
CLIENT_SECRET = "xxx"

credentials = (CLIENT_ID, CLIENT_SECRET)
scopes = ['Calendars.Read']
account = Account(credentials)

if not account.is_authenticated:
    account.authenticate(scopes=scopes)
    print('Authenticated!')

schedule = account.schedule()
calendar = schedule.get_default_calendar()
events = calendar.get_events(include_recurring=False) 

for event in events:
    print(event)
like image 163
Benyamin Jafari Avatar answered Dec 11 '25 21:12

Benyamin Jafari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!