Microsoft Teams Cards

raw JSON →
2.0.0 verified Sat May 09 auth: no python

A Python library for building Adaptive Cards and other card types used in Microsoft Teams bot messages. Part of the Microsoft Teams SDK (teams.py). Current version 2.0.0 (stable pre-release series v2.0.0a*). Active development with alpha releases publishing frequently.

pip install microsoft-teams-cards
error ModuleNotFoundError: No module named 'microsoft_teams'
cause Installed an older version of the package (e.g., v1.x) that used `microsoft.teams` namespace but you tried to import `microsoft_teams`.
fix
Install version 2.0.0a8 or later with pip install microsoft-teams-cards>=2.0.0a8. Then import from microsoft_teams.cards.
error AttributeError: module 'microsoft.teams.cards' has no attribute 'AdaptiveCard'
cause Using old-style dict-based card creation instead of the class-based API introduced in v2.0.0a31.
fix
Use the class AdaptiveCard from microsoft.teams.cards (or microsoft_teams.cards) and populate it via methods like add_text_block().
error pydantic.error_wrappers.ValidationError: 1 validation error for AdaptiveCard ...
cause Passing a raw dict to `CardFactory.adaptive_card_attachment()` instead of an `AdaptiveCard` instance. The factory in v2.0.0a31+ validates inputs.
fix
Create an AdaptiveCard instance first: card = AdaptiveCard(...) then CardFactory.adaptive_card_attachment(card).
breaking Breaking change in v2.0.0a31: `CardFactory` methods like `adaptive_card_attachment()` now require explicit card object instead of dict. Update your code to pass a card instance.
fix Use `CardFactory.adaptive_card_attachment(AdaptiveCard(...))` instead of `CardFactory.adaptive_card_attachment({'type':'AdaptiveCard',...})`.
deprecated The import path `microsoft.teams.cards` is deprecated as of v2.0.0a8. Use `microsoft_teams.cards` instead, but note that v2.0.0a8 still supports the old path with a warning.
fix Replace `from microsoft.teams.cards import ...` with `from microsoft_teams.cards import ...`.
gotcha Python 3.12+ only. Requires `python >=3.12, <3.15`. Installing on Python 3.11 or earlier will fail.
fix Use Python 3.12 or 3.13. Check your Python version with `python --version`.

Create a simple Adaptive Card and output its attachment representation.

from microsoft.teams.cards import AdaptiveCard, CardFactory

card = AdaptiveCard(version='1.5')
card.add_text_block('Hello, Teams!')
card.add_submit_action('Submit', data={'key': 'value'})

# Get card as attachment for bot activity
attachment = CardFactory.adaptive_card_attachment(card)
print(attachment)