Skip to main content

AdaptiveCards

Author adaptive cards in pure python

Introduction

Adaptive Cards are a great way to extend your bot interactions. However, writing the JSON required to specify the card layout by hand can be cumbersome and error prone. And while using a designer is a good way to manually create cards this does not cover cards that are generated by code. AdaptiveCards allows you to author cards in native python without ever touching the underlying json.

A code sample says more then a thousand words so the following code snippet ...

from adaptivecards.adaptivecard import AdaptiveCard
from adaptivecards.elements import TextBlock
from adaptivecards.containers import Column, ColumnSet, Container

card = AdaptiveCard()
card.body = [
    Container(items=[
        TextBlock(text='Hello from adaptivecards', font_type='Default', size='Medium'),
        ColumnSet(columns=[
            Column(
                width='stretch',
                items=[
                    TextBlock(text='author', weight="Bolder", wrap=True),
                    TextBlock(text='version', weight="Bolder", wrap=True),
                ]
            ),
            Column(
                width='stretch',
                items=[
                    TextBlock(text='Huu Hoa NGUYEN', wrap=True),
                    TextBlock(text='0.1.0', wrap=True),
                ]
            )
        ])
    ]),
    TextBlock(text='more information can be found at [https://pypi.org/project/adaptivecards/](https://pypi.org/project/adaptivecards/)',
              wrap=True)
]
json_str = str(card)
print(json_str)

... produces this json ...

{
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "body": [
    {
      "items": [
        {
          "fontType": "Default",
          "size": "Medium",
          "text": "Hello from adaptivecards",
          "type": "TextBlock"
        },
        {
          "columns": [
            {
              "items": [
                {
                  "text": "author",
                  "type": "TextBlock",
                  "weight": "Bolder",
                  "wrap": true
                },
                {
                  "text": "version",
                  "type": "TextBlock",
                  "weight": "Bolder",
                  "wrap": true
                }
              ],
              "type": "Column",
              "width": "stretch"
            },
            {
              "items": [
                {
                  "text": "Huu Hoa NGUYEN",
                  "type": "TextBlock",
                  "wrap": true
                },
                {
                  "text": "0.1.0",
                  "type": "TextBlock",
                  "wrap": true
                }
              ],
              "type": "Column",
              "width": "stretch"
            }
          ],
          "type": "ColumnSet"
        }
      ],
      "type": "Container"
    },
    {
      "text": "more information can be found at [https://pypi.org/project/adaptivecards/](https://pypi.org/project/adaptivecards/)",
      "type": "TextBlock",
      "wrap": true
    }
  ],
  "type": "AdaptiveCard",
  "version": "1.2"
}

when render in Teams will look like screenshot example 1

Features

  • Supports all components, options and features of adaptive cards version 1.4
  • Create adaptive cards from pure python

Installation

You can install AdaptiveCards using pip by issuing

$ pip install adaptivecards

For more information on how to use this package please check the project documentation at https://github.com/huuhoa/adaptivecards.

Authors & Maintainers

Credits

The following resources were influential in the creation of this project:

License

This project is licensed to you under the terms of the MIT License.

Metadata

Release files for adaptivecards 0.4.1

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

Source distribution (sdist)

Source distribution for adaptivecards 0.4.1
File Size Uploaded Provenance
adaptivecards-0.4.1.tar.gz 8.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for adaptivecards 0.4.1
File Interpreter ABI Platform
adaptivecards-0.4.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 17.9 kB

Release files / adaptivecards-0.4.1.tar.gz

Download URL adaptivecards-0.4.1.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e5d55b4129fc2a41ff1e787a1350bc3af91f4b91390beafa8026cc8310b53636
BLAKE2b-256 checksum
How to use checksums
9c12dc6eaf89482c7ea71bef32e0d935a452ea183a4751336a1ee048429adc93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

Release files / adaptivecards-0.4.1-py2.py3-none-any.whl

Download URL adaptivecards-0.4.1-py2.py3-none-any.whl
Size 9.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9bbad959d99b304bb7566d6542ff5d2e9ab0d8c15fe2dae768930c8c91701df7
BLAKE2b-256 checksum
How to use checksums
5dc6926bb98fbaf619a018c652a49fae51cee42e8ab1f983017a09d2eaad6f45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

Security for adaptivecards 0.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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