Caution
This project is in public preview. We’ll do our best to maintain compatibility, but there may be breaking changes in upcoming releases.
High-level framework for building Microsoft Teams applications. Handles activity routing, authentication, and provides Microsoft Graph integration.
- Activity Routing: Decorator-based routing for different activity types
- OAuth Integration: Built-in OAuth flow handling for user authentication
- Microsoft Graph Integration: Type-safe Graph client access via
user_graphandapp_graphproperties - Plugin System: Extensible plugin architecture for adding functionality
from microsoft_teams.apps import App, ActivityContext
from microsoft_teams.api import MessageActivity
app = App()
@app.on_message
async def handle_message(ctx: ActivityContext[MessageActivity]):
await ctx.send(f"You said: {ctx.activity.text}")
# Start the app
await app.start()@app.on_message
async def handle_message(ctx: ActivityContext[MessageActivity]):
if ctx.is_signed_in:
try:
# Access user's Graph data
me = await ctx.user_graph.me.get()
await ctx.send(f"Hello {me.display_name}!")
except (ValueError, RuntimeError, ImportError) as e:
await ctx.send(f"Graph access failed: {e}")
else:
# Prompt user to sign in
await ctx.sign_in()Microsoft Graph functionality requires additional dependencies:
pip install microsoft-teams-apps[graph]Or if using uv:
uv add microsoft-teams-apps[graph]If Graph dependencies are not installed, user_graph and app_graph will raise an ImportError when accessed. If the user is not signed in or tokens are unavailable, they will raise ValueError.