Author adaptive cards in pure python
Project description
PyAdaptiveCards
Author adaptive cards in pure python
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 ...
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
- Marcel Neidinger mneiding@cisco.com
Credits
The following resources were influential in the creation of this project:
- This package was created with Cookiecutter and a derivative of theaudreyr/cookiecutter-pypackage project template.
License
This project is licensed to you under the terms of the Cisco SampleCode License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyadaptivecards-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13fd487de9394600c2f0624aca32660c4fc977e2dcd815ca4edadda3ba4b35f6 |
|
MD5 | 3f8f5555b2cf1258c8dfb9dc9e6ec668 |
|
BLAKE2b-256 | a23b183bdf98621f3168775465c12e06955d1f9fcdb285300a0f1feb3d75c761 |