Microsoft Teams AdaptiveCards API Wrapper

raw JSON →
0.9.5 verified Fri May 01 auth: no python maintenance

msteamsapi is a Python wrapper for sending AdaptiveCards to Microsoft Teams via webhooks. Current version 0.9.5 supports Python 2.7+ and 3.9+. Release cadence is irregular; last release was in 2023.

pip install msteamsapi
error AttributeError: module 'msteamsapi' has no attribute 'TeamsWebhook'
cause Incorrect import path, e.g., from msteamsapi import msteamsapi
fix
Use: from msteamsapi import TeamsWebhook
error TypeError: __init__() missing 1 required positional argument: 'url'
cause Instantiating TeamsWebhook without providing the webhook URL.
fix
Pass the URL as a string: TeamsWebhook(url='https://outlook.office.com/webhook/...')
deprecated Python 2 support is deprecated, though still present. Future versions may drop it.
fix Use Python 3.9+ and upgrade to newer versions when available.
gotcha The library uses 'url' parameter name, not 'webhook_url'. Common mistake.
fix Use keyword argument 'url=' when initializing TeamsWebhook.
gotcha AdaptiveCards must be properly formatted; the library does not validate card structure. Malformed cards will fail silently.
fix Test your card JSON with the Microsoft AdaptiveCard designer before sending.

Send a simple text message to a Teams channel using a webhook URL.

from msteamsapi import TeamsWebhook
import os

webhook_url = os.environ.get('TEAMS_WEBHOOK_URL', '')
webhook = TeamsWebhook(url=webhook_url)
webhook.send_text('Hello from msteamsapi!')