adaptive-cards-py
raw JSON → 0.4.2 verified Mon Apr 27 auth: no python
Python library for building Adaptive Cards using Pydantic models. Version 0.4.2, requires Python >=3.10. Uses Pydantic v2 for validation. Active development.
pip install adaptive-cards-py Common errors
error ImportError: cannot import name 'AdaptiveCard' from 'adaptivecards' ↓
cause Using incorrect package name or import path.
fix
Install adaptive-cards-py and use 'from adaptive_cards import AdaptiveCard'.
error AttributeError: 'AdaptiveCard' object has no attribute 'to_json' ↓
cause Version <0.3.0 used dataclasses and didn't have to_json().
fix
Upgrade to v0.3.0+ or use json.dumps(card.__dict__) for older versions.
Warnings
breaking v0.3.0 replaced dataclasses with Pydantic. If you used dataclass serialization, your code will break. ↓
fix Update to use Pydantic models and .to_json() method.
breaking v0.4.0 restructured modules: elements are now in submodules like adaptive_cards.elements. ↓
fix Use from adaptive_cards.elements import TextBlock instead of from adaptive_cards import TextBlock.
gotcha If you miss the 'type' field in payload when submitting to Teams, the card may not render. This was fixed in v0.2.1. ↓
fix Upgrade to v0.2.1 or later.
Imports
- AdaptiveCard wrong
from adaptivecards import AdaptiveCardcorrectfrom adaptive_cards import AdaptiveCard - TextBlock wrong
from adaptive_cards import TextBlockcorrectfrom adaptive_cards.elements import TextBlock
Quickstart
from adaptive_cards import AdaptiveCard
from adaptive_cards.elements import TextBlock
card = AdaptiveCard()
card.add_item(TextBlock(text='Hello, World!'))
print(card.to_json())