Skip to main content

Author adaptive cards in pure python

Project description

PyAdaptiveCards

Author adaptive cards in pure python

PyPi Travis ReadTheDocs PyUp


Introduction

Adaptive Cards are a great way to extend your bots 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. PyAdaptiveCards 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 pyadaptivecards.card import AdaptiveCard
from pyadaptivecards.inputs import Text, Number
from pyadaptivecards.components import TextBlock
from pyadaptivecards.actions import Submit

greeting = TextBlock("Hey hello there! I am a adaptive card")
first_name = Text('first_name', placeholder="First Name")
age = Number('age', placeholder="Age")

submit = Submit(title="Send me!")

card = AdaptiveCard(body=[greeting, first_name, age], actions=[submit])
card_json = card.to_json(pretty=True)
print(card_json)

... produces this json ...

{
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "actions": [
        {
            "title": "Send me!",
            "type": "Action.Submit"
        }
    ],
    "body": [
        {
            "text": "Hey hello there! I am a adaptive card",
            "type": "TextBlock"
        },
        {
            "id": "first_name",
            "placeholder": "First name",
            "type": "Input.Text"
        },
        {
            "id": "age",
            "placeholder": "Age",
            "type": "Input.Number"
        }
    ],
    "type": "AdaptiveCard",
    "version": "1.1"
}

... which looks like this in Webex Teams ...

screenshot of card in webex teams

Features

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

Installation

Provide a step-by-step series of examples and explanations for how to install your project and its dependencies.

Documentation

Please check the project documentation at:

https://pyadaptivecards.readthedocs.io

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 Cisco SampleCode License.

Project details


Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pyadaptivecards, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size pyadaptivecards-0.1.0-py2.py3-none-any.whl (19.0 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size pyadaptivecards-0.1.0.tar.gz (16.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page