Client for Microsoft Exchange Web Services (EWS) providing Django-style ORM interface for Exchange mailboxes.
—
Specialized date and time functionality designed for Exchange compatibility, including timezone handling, UTC conversion, and Exchange-specific datetime formats.
class EWSDateTime:
def __init__(self, year: int, month: int, day: int, hour: int = 0, minute: int = 0, second: int = 0, microsecond: int = 0, tzinfo: EWSTimeZone = None):
"""Create an Exchange-aware datetime."""
@classmethod
def from_datetime(cls, dt: datetime) -> EWSDateTime:
"""Create EWSDateTime from Python datetime."""
@classmethod
def now(cls, tz: EWSTimeZone = None) -> EWSDateTime:
"""Get current datetime."""
def to_timezone(self, tz: EWSTimeZone) -> EWSDateTime:
"""Convert to different timezone."""
def astimezone(self, tz: EWSTimeZone) -> EWSDateTime:
"""Convert to timezone (alias for to_timezone)."""
def to_datetime(self) -> datetime:
"""Convert to Python datetime."""
class EWSDate:
def __init__(self, year: int, month: int, day: int):
"""Create an Exchange-aware date."""
@classmethod
def from_date(cls, d: date) -> EWSDate:
"""Create EWSDate from Python date."""
@classmethod
def today(cls) -> EWSDate:
"""Get today's date."""
def to_date(self) -> date:
"""Convert to Python date."""class EWSTimeZone:
def __init__(self, key: str, name: str = None, bias: int = None):
"""Create an Exchange timezone."""
@classmethod
def from_pytz(cls, tz) -> EWSTimeZone:
"""Create from pytz timezone."""
@classmethod
def localzone(cls) -> EWSTimeZone:
"""Get local system timezone."""
key: str
name: str
bias: int
# UTC timezone constant
UTC: EWSTimeZone
def UTC_NOW() -> EWSDateTime:
"""Get current UTC datetime."""Usage examples:
from exchangelib import EWSDateTime, EWSTimeZone, UTC, UTC_NOW
from datetime import datetime, timedelta
# Create Exchange datetimes
meeting_time = EWSDateTime.from_datetime(
datetime(2024, 12, 15, 14, 30, 0)
)
# Work with timezones
eastern = EWSTimeZone.from_pytz(pytz.timezone('US/Eastern'))
pacific = EWSTimeZone.from_pytz(pytz.timezone('US/Pacific'))
eastern_time = meeting_time.to_timezone(eastern)
pacific_time = meeting_time.to_timezone(pacific)
# Use UTC
utc_now = UTC_NOW()
utc_meeting = EWSDateTime.now(UTC)
# Calendar item with timezone
appointment = CalendarItem(
account=account,
subject='Cross-timezone Meeting',
start=eastern_time,
end=eastern_time + timedelta(hours=1),
start_timezone=eastern,
end_timezone=eastern
)Install with Tessl CLI
npx tessl i tessl/pypi-exchangelib