O365 - Microsoft Graph and Office 365 API made easy
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Full calendar functionality including event creation, scheduling, attendee management, recurring events, meeting rooms, and calendar sharing across multiple calendars.
Access calendar services for the authenticated user or other users with proper permissions.
def schedule(self, resource: str = None) -> Schedule:
"""
Get a schedule instance for calendar operations.
Parameters:
- resource: user resource identifier (defaults to authenticated user)
Returns:
- Schedule: Schedule instance for calendar operations
"""
class Schedule:
def __init__(self, parent: Account, main_resource: str = None): ...
def get_default_calendar(self) -> Calendar:
"""Get the user's default calendar."""
def get_calendars(self, limit: int = None) -> list[Calendar]:
"""
Get all accessible calendars.
Parameters:
- limit: maximum number of calendars to return
Returns:
- list[Calendar]: List of calendar objects
"""
def get_calendar(self, calendar_id: str = None, calendar_name: str = None) -> Calendar:
"""
Get a specific calendar by ID or name.
Parameters:
- calendar_id: calendar identifier
- calendar_name: calendar display name
Returns:
- Calendar: Calendar object
"""Manage calendars including creation, sharing, and permissions.
def new_calendar(self, calendar_name: str) -> Calendar:
"""
Create a new calendar.
Parameters:
- calendar_name: name for the new calendar
Returns:
- Calendar: Created calendar object
"""
class Calendar:
@property
def name(self) -> str:
"""Calendar display name."""
@property
def color(self) -> str:
"""Calendar color identifier."""
@property
def owner(self) -> str:
"""Calendar owner email address."""
@property
def can_edit(self) -> bool:
"""Whether the user can edit this calendar."""
@property
def can_share(self) -> bool:
"""Whether the user can share this calendar."""
def delete(self) -> bool:
"""Delete this calendar."""
def update(self) -> bool:
"""Save changes to the calendar."""Create, retrieve, update, and delete calendar events.
def get_events(self, limit: int = None, include_recurring: bool = True, **filters) -> list[Event]:
"""
Get events from calendars.
Parameters:
- limit: maximum number of events to return
- include_recurring: whether to include recurring event instances
- filters: OData query filters (start_time, end_time, subject, etc.)
Returns:
- list[Event]: List of event objects
"""
def new_event(self, subject: str = None, start: datetime = None, end: datetime = None) -> Event:
"""
Create a new event.
Parameters:
- subject: event subject/title
- start: event start datetime
- end: event end datetime
Returns:
- Event: New event object
"""
class Event:
@property
def subject(self) -> str:
"""Event subject/title."""
@property
def body(self) -> str:
"""Event body/description."""
@property
def start(self) -> datetime:
"""Event start datetime."""
@property
def end(self) -> datetime:
"""Event end datetime."""
@property
def location(self) -> str:
"""Event location."""
@property
def is_all_day(self) -> bool:
"""Whether this is an all-day event."""
@property
def organizer(self) -> Recipient:
"""Event organizer information."""
@property
def attendees(self) -> list[Attendee]:
"""Event attendees list."""
@property
def importance(self) -> str:
"""Event importance level (Low, Normal, High)."""
@property
def sensitivity(self) -> str:
"""Event sensitivity (Normal, Personal, Private, Confidential)."""
def save(self) -> bool:
"""Save changes to the event."""
def delete(self) -> bool:
"""Delete this event."""
def accept(self, send_response: bool = True) -> bool:
"""Accept the event invitation."""
def decline(self, send_response: bool = True) -> bool:
"""Decline the event invitation."""
def tentative(self, send_response: bool = True) -> bool:
"""Respond tentatively to the event invitation."""Manage event attendees and their responses.
class Attendee:
@property
def address(self) -> str:
"""Attendee email address."""
@property
def name(self) -> str:
"""Attendee display name."""
@property
def response_status(self) -> str:
"""Response status (None, Accepted, Declined, TentativelyAccepted)."""
@property
def response_time(self) -> datetime:
"""When the attendee responded."""
@property
def type(self) -> str:
"""Attendee type (Required, Optional, Resource)."""
def add_attendees(self, attendees: list) -> bool:
"""
Add attendees to the event.
Parameters:
- attendees: list of email addresses or Attendee objects
Returns:
- bool: True if successful
"""
def remove_attendees(self, attendees: list) -> bool:
"""
Remove attendees from the event.
Parameters:
- attendees: list of email addresses or Attendee objects
Returns:
- bool: True if successful
"""Create and manage recurring event patterns.
class RecurrencePattern:
@property
def type(self) -> str:
"""Recurrence type (Daily, Weekly, Monthly, Yearly)."""
@property
def interval(self) -> int:
"""Recurrence interval."""
@property
def days_of_week(self) -> list[str]:
"""Days of week for weekly recurrence."""
@property
def day_of_month(self) -> int:
"""Day of month for monthly recurrence."""
@property
def month(self) -> int:
"""Month for yearly recurrence."""
class RecurrenceRange:
@property
def start_date(self) -> date:
"""Recurrence start date."""
@property
def end_date(self) -> date:
"""Recurrence end date."""
@property
def number_of_occurrences(self) -> int:
"""Number of occurrences."""
@property
def type(self) -> str:
"""Range type (EndDate, NoEnd, Numbered)."""
class Event:
@property
def recurrence_pattern(self) -> RecurrencePattern:
"""Event recurrence pattern."""
@property
def recurrence_range(self) -> RecurrenceRange:
"""Event recurrence range."""
def make_recurring(self, pattern_type: str, interval: int = 1, **kwargs) -> bool:
"""
Make the event recurring.
Parameters:
- pattern_type: 'daily', 'weekly', 'monthly', or 'yearly'
- interval: recurrence interval
- kwargs: additional recurrence parameters
Returns:
- bool: True if successful
"""Check availability and schedule meetings based on attendee availability.
def get_free_busy(self, attendees: list[str], start_time: datetime,
end_time: datetime, interval: int = 30) -> dict:
"""
Get free/busy information for attendees.
Parameters:
- attendees: list of attendee email addresses
- start_time: period start time
- end_time: period end time
- interval: time slot interval in minutes
Returns:
- dict: Free/busy information for each attendee
"""
def find_meeting_times(self, attendees: list[str], duration: int,
max_candidates: int = 20, **constraints) -> list[dict]:
"""
Find available meeting times for attendees.
Parameters:
- attendees: list of attendee email addresses
- duration: meeting duration in minutes
- max_candidates: maximum number of suggestions
- constraints: time constraints (earliest_time, latest_time, etc.)
Returns:
- list[dict]: Suggested meeting times with confidence scores
"""Find and book meeting rooms and other resources.
def get_rooms(self, room_list: str = None) -> list[Room]:
"""
Get available meeting rooms.
Parameters:
- room_list: specific room list to query
Returns:
- list[Room]: Available meeting rooms
"""
def get_room_lists(self) -> list[RoomList]:
"""
Get available room lists.
Returns:
- list[RoomList]: Available room lists
"""
class Room:
@property
def address(self) -> str:
"""Room email address."""
@property
def name(self) -> str:
"""Room display name."""
@property
def capacity(self) -> int:
"""Room capacity."""
@property
def equipment(self) -> list[str]:
"""Available equipment in the room."""from O365 import Account
from datetime import datetime, timedelta
account = Account(credentials)
schedule = account.schedule()
# Get events for the next week
start_time = datetime.now()
end_time = start_time + timedelta(days=7)
events = schedule.get_events(
start_time__gte=start_time,
end_time__lte=end_time
)
for event in events:
print(f"Subject: {event.subject}")
print(f"Start: {event.start}")
print(f"End: {event.end}")
print(f"Location: {event.location}")
print("---")from datetime import datetime, timedelta
# Create a new meeting
meeting = schedule.new_event()
meeting.subject = "Project Review Meeting"
meeting.body = "Weekly project status review"
meeting.location = "Conference Room A"
# Set meeting time (tomorrow at 2 PM)
tomorrow = datetime.now() + timedelta(days=1)
meeting.start = tomorrow.replace(hour=14, minute=0, second=0, microsecond=0)
meeting.end = meeting.start + timedelta(hours=1)
# Add attendees
meeting.add_attendees([
'team.member1@company.com',
'team.member2@company.com',
'manager@company.com'
])
# Save and send invitations
if meeting.save():
print("Meeting created and invitations sent!")# Create a recurring weekly meeting
weekly_standup = schedule.new_event()
weekly_standup.subject = "Weekly Standup"
weekly_standup.start = datetime(2023, 10, 2, 9, 0) # Monday 9 AM
weekly_standup.end = weekly_standup.start + timedelta(minutes=30)
# Make it recurring (every Monday for 12 weeks)
weekly_standup.make_recurring(
pattern_type='weekly',
interval=1,
days_of_week=['Monday'],
end_date=weekly_standup.start.date() + timedelta(weeks=12)
)
weekly_standup.add_attendees(['team@company.com'])
weekly_standup.save()from datetime import datetime, timedelta
# Find available meeting times for next week
attendees = [
'person1@company.com',
'person2@company.com',
'person3@company.com'
]
next_week = datetime.now() + timedelta(days=7)
suggestions = schedule.find_meeting_times(
attendees=attendees,
duration=60, # 1 hour meeting
earliest_time=next_week.replace(hour=9),
latest_time=next_week.replace(hour=17),
max_candidates=10
)
for suggestion in suggestions:
print(f"Suggested time: {suggestion['start_time']}")
print(f"Confidence: {suggestion['confidence']}")
print("---")# Find and book a meeting room
rooms = schedule.get_rooms()
available_rooms = []
for room in rooms:
if room.capacity >= 10: # Need room for 10 people
available_rooms.append(room)
if available_rooms:
# Create meeting with room
meeting = schedule.new_event()
meeting.subject = "Large Team Meeting"
meeting.location = available_rooms[0].name
# Add the room as a required attendee
meeting.add_attendees([available_rooms[0].address])
meeting.save()Install with Tessl CLI
npx tessl i tessl/pypi-o365