Skip to main content

Adaptive Cards Framework

Baseline

What are Adaptive Cards?

Adaptive Cards are platform-agnostic snippets of UI, authored in JSON, that apps and services can openly exchange. When delivered to a specific app, the JSON is transformed into native UI that automatically adapts to its surroundings. It helps design and integrate light-weight UI for all major platforms and frameworks.

Why do I need a framework?

Building an application that effectively serves Adaptive Cards can be complex and time-consuming. Without a framework, you'd need to thoroughly navigate the entire Adaptive Cards documentation to ensure proper implementation, which can slow down development and hinder scalability. While tools like the designer.io page can assist with prototyping and creating JSON components, relying solely on these can limit your application's growth potential. By leveraging a framework, you streamline the process, allowing you to focus on crafting your cards with confidence and efficiency, without the worry of underlying technical details.

About

adaptive-cards-io is a Python package designed to simplify the creation, manipulation, and integration of Adaptive Cards in your applications. Adaptive Cards are a powerful way to build lightweight, responsive user interfaces that seamlessly adapt to different platforms and environments. With adaptive-cards-io, you can efficiently generate and manage these cards, ensuring they are optimized and correctly formatted for your specific needs.

This package offers a streamlined approach, allowing developers to focus on designing and deploying Adaptive Cards without getting bogged down by the intricacies of the underlying JSON structure. Whether you're building prototypes or scaling up to a production environment, adaptive-cards-io provides the tools and framework to enhance productivity and reduce development time.

Installation

  1. Make sure PIP is up-to-date:
python3 -m pip install --upgrade pip
  1. Install the package:
python3 -m pip install adaptive-cards-io

Usage

Importing

from adaptive_cards import *

By importing everything, all of the following will become available in your python module:

Enumerators

  • MaterialType
  • ActionType
  • InputType
  • MaterialColor
  • MaterialHeight
  • MaterialOrientation
  • HorizontalAlignment
  • VerticalAlignment
  • MaterialSpacing
  • ActionTheme
  • ActionMode
  • ActionRole
  • BackgroundFillMode
  • AssociatedInputs
  • TargetFreezing
  • ContainerTheme
  • ColumnWidth
  • TextTheme
  • FontType
  • TextSize
  • FontWeight
  • ImageSize
  • ImageTheme
  • MediaMimeType
  • CaptionMimeType
  • ChoiceSetMode
  • InputTextMode

Building Blocks

  • Material
  • MaterialDynamic
  • MaterialMapping
  • MaterialLayout
  • AdaptiveCardMaterial
  • BackgroundImage
  • AdaptiveCardAction

Units

  • Weight
  • Seconds
  • Pixels

Base

  • AdaptiveCardLayout
  • AdaptiveCard

Actions

  • ActionSubmit
  • ActionOpenUrl
  • ActionShowCard
  • ActionToggleVisibility
  • TargetElement
  • ActionExecute
  • ActionSetLayout
  • ActionSet
  • MSTeams
  • ActionData

Containers

  • ContainerStyle
  • ContainerLayout
  • Container
  • ColumnLayout
  • Column
  • ColumnSetLayout
  • ColumnSet
  • FactSetLayout
  • Fact
  • FactSet
  • ImageSetLayout
  • ImageSet
  • TableLayout
  • TableCell
  • TableRow
  • GridStyle
  • Table
  • CarouselPage
  • Carousel

Inputs

  • InputValidation
  • InputLayout
  • AdaptiveCardInput
  • InputChoice
  • InputChoiceSet
  • InputTextValidation
  • InputText
  • InputNumber
  • InputDate
  • InputTime
  • InputToggle

General

  • TextLayout
  • TextStyle
  • TextBlock
  • ImageLayout
  • ImageStyle
  • Image
  • MediaLayout
  • MediaSource
  • MediaCaptions
  • Media

Example

from adaptive_cards import *
import json

official_example = AdaptiveCard(
    version=1.5,
    schema="http://adaptivecards.io/schemas/adaptive-card.json",
    body=[
        TextBlock("${title}", style=TextStyle(size=TextSize.MEDIUM, weight=FontWeight.BOLDER)),
        ColumnSet(
            columns=[
                Column(
                    layout=ColumnLayout(width=ColumnWidth.AUTO),
                    items=[
                        Image(
                            "${creator.profileImage}",
                            style=ImageStyle(theme=ImageTheme.PERSON),
                            layout=ImageLayout(size=ImageSize.SMALL),
                            alternate_text="${creator.name}"
                        )
                    ]
                ),
                Column(
                    items=[
                        TextBlock("${creator.name}", style=TextStyle(weight=FontWeight.BOLDER)),
                        TextBlock(
                            "Created {{DATE(${createdUtc},SHORT)}}", 
                            style=TextStyle(subtle=True),
                            layout=TextLayout(spacing=MaterialSpacing.NONE)
                        )
                    ]
                )
            ]
        ),
        TextBlock("${description}"),
        FactSet(
            facts=[
                Fact(title="${key}:", value="${value}").using("${properties}"),
            ]
        )
    ],
    actions=[
        ActionShowCard(
            title="Set due date",
            card=AdaptiveCard(
                schema="http://adaptivecards.io/schemas/adaptive-card.json",
                body=[
                    InputDate(id="dueDate"),
                    InputText(id="comment", placeholder="Add a comment", multiline=True)
                ],
                actions=[ActionSubmit(title="OK")]
            )
        ),
        ActionOpenUrl(title="View", url="${viewUrl}")
    ]
)

print(json.dumps(official_example.__dict__, indent=4))

Output

{
    "type": "AdaptiveCard",
    "body": [
        {
            "type": "TextBlock",
            "text": "${title}",
            "wrap": true,
            "size": "Medium",
            "weight": "Bolder"
        },
        {
            "type": "ColumnSet",
            "columns": [
                {
                    "type": "Column",
                    "items": [
                        {
                            "type": "Image",
                            "url": "${creator.profileImage}",
                            "altText": "${creator.name}",
                            "size": "Small",
                            "style": "Person"
                        }
                    ],
                    "width": "auto"
                },
                {
                    "type": "Column",
                    "items": [
                        {
                            "type": "TextBlock",
                            "text": "${creator.name}",
                            "wrap": true,
                            "weight": "Bolder"
                        },
                        {
                            "type": "TextBlock",
                            "text": "Created {{DATE(${createdUtc},SHORT)}}",
                            "wrap": true,
                            "spacing": "None",
                            "isSubtle": true
                        }
                    ]
                }
            ]
        },
        {
            "type": "TextBlock",
            "text": "${description}",
            "wrap": true
        },
        {
            "type": "FactSet",
            "facts": [
                {
                    "$data": "${properties}",
                    "title": "${key}:",
                    "value": "${value}"
                }
            ]
        }
    ],
    "actions": [
        {
            "type": "Action.ShowCard",
            "title": "Set due date",
            "card": {
                "type": "AdaptiveCard",
                "body": [
                    {
                        "type": "Input.Date",
                        "id": "dueDate"
                    },
                    {
                        "type": "Input.Text",
                        "id": "comment",
                        "placeholder": "Add a comment",
                        "isMultiline": true
                    }
                ],
                "version": "1.6",
                "actions": [
                    {
                        "type": "Action.Submit",
                        "title": "OK",
                        "associatedInputs": "auto"
                    }
                ],
                "$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
            }
        },
        {
            "type": "Action.OpenUrl",
            "title": "View",
            "url": "${viewUrl}"
        }
    ],
    "version": "1.5",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
}

Metadata

Release files for adaptive-cards-io 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for adaptive-cards-io 1.4.0
File Size Uploaded
adaptive_cards_io-1.4.0.tar.gz 15.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for adaptive-cards-io 1.4.0
File Interpreter ABI Platform
adaptive_cards_io-1.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 32.2 kB

Release files / adaptive_cards_io-1.4.0.tar.gz

Download URL adaptive_cards_io-1.4.0.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0598b79219d3d1404a92312c8ee77e3353fd8d6f3129a4efc89ca623501d5d65
BLAKE2b-256 checksum
How to use checksums
645068f7f38a7cb5e96ad85dcd45c51c4444502ec4ee1ae5a8c9c64a248a80f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / adaptive_cards_io-1.4.0-py3-none-any.whl

Download URL adaptive_cards_io-1.4.0-py3-none-any.whl
Size 16.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2101c5c997857f1aad12ae10c0dc8a7d80cc96c560f4d17588eaed74d206dc17
BLAKE2b-256 checksum
How to use checksums
a2263ba876acd4d14d72cda75412ec66e8205639766df22bd9cb8f1683a588ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release history Release notifications | RSS feed

This release

1.4.0 This release

2 release files

1.3.3

2 release files

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.0

1 release file

1.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page