API Documentation

Cards

class pyadaptivecards.card.AdaptiveCard(body=None, actions=None, selectAction=None, fallbackText=None, lang=None)[source]

AdaptiveCard class that represents a adaptive card python object.

Note

Webex Teams currently supports version 1.1 of adaptive cards and thus only features from that release are supported in this abstraction.

__init__(body=None, actions=None, selectAction=None, fallbackText=None, lang=None)[source]

Creates a new adaptive card object.

Parameters:
  • body (list) – The list of components and containers making up the body of this adaptive card.
  • actions (list) – The list of actions this adaptive card should contain
  • selectAction (action) – The action that should be invoked when this adaptive card is selected. Can be any action other then ‘ShowCard’
  • fallbackText (str) – The text that should be displayed on clients that can’t render adaptive cards
  • lang (str) – The 2-letter ISO-639-1 language used in the card. This is used for localization of date/time functions
to_dict()[source]

Export a dictionary representation of this card/component by parsing all simple and serializable properties.

A simple_component is a single-text property of the exported card (i.e. {‘version’: “1.2”}) while a serializable property is another subcomponent that also implements a to_dict() method.

The to_dict() method is used to recursively create a dict representation of the adaptive card. This dictionary representation can then be converted into json for usage with the API.

Returns:Dictionary representation of this component.
Return type:dict
to_json(pretty=False)

Create json from a serializable component

This function is used to render the json from a component. While all components do support this operation it is mainly used on the AdaptiveCard to generate the json for the attachment.

Parameters:pretty (boolean) – If true, the returned json will be sorted by keys and indented with 4 spaces to make it more human-readable
Returns:A Json representation of this component

Components

This section covers all the different components that can be added to the body of a adaptive card.

class pyadaptivecards.components.Image[source]

Displays a image object

__init__(url, altText=None, backgroundColor=None, height=None, horizontalAlignment=None, selectAction=None, size=None, style=None, width=None, separator=None, spacing=None, id=None)[source]

Create a new image component

Parameters:
  • url (str) – The URL to the image
  • altText (str) – Alternative text describing the image
  • backgroundColor (str) – Background color for transparent images.
  • height (str, BlockElementHeight) – Height of the image either as a pixel value(i.e. ‘50px’) or as an instance of BlockElementHeight
  • horizontalAlignmnet (HorizontalAlignment) – Controls how the component is positioned within its parent.
  • selectAction (OpenUrl, Submit) – Option that is caried out when the card is selected.
  • size (ImageSize) – Controls the approximate size of the image.
  • style (ImageStyle) – The display style of this image.
  • width (str) – Width of the image as a pixel value (i.e. ‘50px’)
  • separator (bool) – Draw a separating line when set to true
  • spacing (Spacing) – Specify the spacing of this component
  • id (str) – The id of this component
class pyadaptivecards.components.TextBlock[source]

Component that contains text.

__init__(text, color=None, horizontalAlignment=None, isSubtle=None, maxLines=None, size=None, weight=None, wrap=None, separator=None, spacing=None, id=None)[source]

Create a new TextBlock component.

Parameters:
  • text (str) – The text to be displayed.
  • color (Colors) – The color of the text.
  • horizontalAlignment (HorizontalAlignment) – Controls how the component is positioned within its parent.
  • isSubtle (bool) – If true, displays text slightly toned down to appear less prominent.
  • maxLines (int) – Specifies the number of lines to display.
  • size (FontSize) – Controls the size of the text.
  • weight (FontWeight) – Controls the weight of a TextBlock element.
  • wrap (bool) – If true, allow text to wrap.
  • separator (bool) – Draw a separating line when set to true.
  • spacing (Spacing) – Specify the spacing of this component.
  • id (str) – The id of this component.
class pyadaptivecards.components.Column[source]

A column contains other components and (together with a ColumnSet) allows to display multiple components under each other.

__init__(items=None, separator=None, spacing=None, selectAction=None, style=None, verticalContentAlignment=None, width=None, id=None)[source]

Create a new column.

Parameters:
  • items (list) – List of components in this column
  • separator (bool) – Draw a separating line when set to true.
  • spacing (Spacing) – Specify the spacing of this component.
  • selectAction (OpenUrl, Submit) – Specifies the action that is invoked when the colum is selected.
  • style (ContainerStyle) – The style of this column.
  • verticalContentAlignment (VerticalContentAlignment) – The vertical alignment of the column content.
  • width (str, int) – The width of this column. Can be “auto”, “stretch” or a number that represents the width in pixels.
  • id (str) – The id of this component.
class pyadaptivecards.components.Fact[source]

Fact component to display a set of facts.

__init__(title, value)[source]

Create a new Fact.

Parameters:
  • title (str) – The title of this fact
  • value (str) – The value of this fact
class pyadaptivecards.components.Choice[source]

Choice component.

Can be used together with a ChoiceSet to display different choices.

__init__(title, value)[source]

Create a new choice.

Parameters:
  • title (str) – The title of the choice
  • value (str) – The value of the choice

Options

Options allow you to configure the look and behaviour of components and containers.

For example lets say you want to change the font size of a text block. You can do so by specifying:

from pyadaptivecards.options import FontSize
from pyadaptivecards.components import TextBlock

block = TextBlock("I am the text", size=FontSize.LARGE)
class pyadaptivecards.options.VerticalContentAlignment[source]

Specifies the vertical alignment of a component or of components in a container.

BOTTOM = 3
CENTER = 2
TOP = 1
class pyadaptivecards.options.Colors[source]

Specifies the color of a textblock

ACCENT = 4
ATTENTION = 7
DARK = 2
DEFAULT = 1
GOOD = 5
LIGHT = 3
WARNING = 6
class pyadaptivecards.options.HorizontalAlignment[source]

Specifies the horizontal alignment of a component

CENTER = 2
LEFT = 1
RIGHT = 3
class pyadaptivecards.options.FontSize[source]

Specifies the font size of a TextBlock

DEFAULT = 1
EXTRALARGE = 5
LARGE = 4
MEDIUM = 3
SMALL = 2
class pyadaptivecards.options.FontWeight[source]

Specifies the font weight of a TextBlock

BOLDER = 3
DEFAULT = 1
LIGHTER = 2
class pyadaptivecards.options.BlockElementHeight[source]

Specifies the way the height of a element is determined.

AUTO = 1
STRETCH = 2
class pyadaptivecards.options.Spacing[source]

Specify the spacing around a component

DEFAULT = 1
EXTRALARGE = 6
LARGE = 5
MEDIUM = 4
NONE = 2
PADDING = 7
SMALL = 3
class pyadaptivecards.options.ImageSize[source]

Specify the size scaling of a Image

AUTO = 1
LARGE = 5
MEDIUM = 4
SMALL = 3
STRETCH = 2
class pyadaptivecards.options.ImageStyle[source]

Specifies the style of the image.

PERSON will make the picture rounded

DEFAULT = 1
PERSON = 2
class pyadaptivecards.options.ContainerStyle[source]

Specifies the style of the container

DEFAULT = 1
EMPHASIS = 2
class pyadaptivecards.options.TextInputStyle[source]

Specifies the type of input that a Text input can expect

EMAIL = 4
TEL = 2
TEXT = 1
URL = 3
class pyadaptivecards.options.ChoiceInputStyle[source]

Specifies the display style for a choice input

COMPACT = 1
EXPANDED = 2

Container

class pyadaptivecards.container.Container[source]

Groups items together.

__init__(items, selectAction=None, style=None, verticalContentAlignment=None, height=None, separator=None, spacing=None, id=None)[source]

Create a new container.

Parameters:
  • items (list) – List of items this container should contain.
  • selectAction (OpenURL, Submit) – Action to be invoked when container is selected.
  • style (ContainerStyle) – Style of this container.
  • verticalContentAlignment (VerticalContentAlignment) – Specifies vertical alignment of the content.
  • height (BlockElementHeight) – Specifies the way the height of this container should be calculated (stretch or auto).
  • separator (bool) – Draw a separating line when set to true
  • spacing (Spacing) – Specify the spacing of this component
  • id (str) – The id of this component
class pyadaptivecards.container.ColumnSet[source]

Set of columns to display content side by side.

__init__(columns=None, selectAction=None, height=None, separator=None, spacing=None, id=None)[source]

Create a new ColumnSet.

Parameters:
  • columns (list) – List of Column elements.
  • selectAction (OpenURL, Submit) – Action to be invoked when container is selected.
  • height (BlockElementHeight) – Specifies the way the height of this container should be calculated (stretch or auto).
  • separator (bool) – Draw a separating line when set to true
  • spacing (Spacing) – Specify the spacing of this component
  • id (str) – The id of this component
class pyadaptivecards.container.FactSet[source]

Set of facts to create a factoide.

__init__(facts, height=None, separator=None, spacing=None, id=None)[source]

Create a new FactSet.

Parameters:
  • facts (list) – List of Fact Elements to be displayed.
  • height (BlockElementHeight) – Specifies the way the height of this container should be calculated (stretch or auto).
  • separator (bool) – Draw a separating line when set to true
  • spacing (Spacing) – Specify the spacing of this component
  • id (str) – The id of this component
class pyadaptivecards.container.ImageSet[source]
__init__(images, imageSize=None, height=None, separator=None, spacing=None, id=None)[source]

Create a new ImageSet.

Parameters:
  • images (list) – List of Image objects to be displayed in a image set.
  • imageSize (ImageSize) – Size of the image.
  • height (BlockElementHeight) – Specifies the way the height of this container should be calculated (stretch or auto).
  • separator (bool) – Draw a separating line when set to true
  • spacing (Spacing) – Specify the spacing of this component
  • id (str) – The id of this component

Inputs

class pyadaptivecards.inputs.Text[source]

Input field that accepts text.

__init__(id, isMultiline=None, maxLength=None, placeholder=None, style=None, value=None, height=None, separator=None, spacing=None)[source]

Create a new text input.

Parameters:
  • id (str) – The id of this input.
  • isMultiline (bool) – If True, multline content is allowed.
  • maxLength (int) – Hint for maximum number of characters (some clients ignore this).
  • placeholder (str) – Placeholder text to be displayed in this input field.
  • style (TextInputStyle) – Style of the text input (i.e. are we expecting a mail or a url)
  • value (str) – Initial value of this field.
  • height (BlockElementHeight) – Specifies the way the height of this container should be calculated (stretch or auto).
  • separator (bool) – Draw a separating line when set to true
  • spacing (Spacing) – Specify the spacing of this component
class pyadaptivecards.inputs.Number[source]

Input field that accepts numbers.

__init__(id, max=None, min=None, placeholder=None, value=None, height=None, separator=None, spacing=None)[source]

Create a new number input.

Parameters:
  • id (str) – The id of this input.
  • max (int) – The maximum accepted value.
  • min (int) – The minimum accepted value.
  • placeholder (str) – Placeholder text to be displayed in this input field.
  • value (int) – Initial value of this field.
  • height (BlockElementHeight) – Specifies the way the height of this container should be calculated (stretch or auto).
  • separator (bool) – Draw a separating line when set to true
  • spacing (Spacing) – Specify the spacing of this component
class pyadaptivecards.inputs.Date[source]

Input field that accepts date inputs.

__init__(id, max=None, min=None, placeholder=None, value=None, height=None, separator=None, spacing=None)[source]

Create a new Date.

Parameters:
  • id (str) – The id of this input.
  • max (str) – The maximum date in ISO-8601 format.
  • min (str) – The minimum date in ISO-8601 format.
  • placeholder (str) – Placeholder text to be displayed in this input field.
  • value (str) – Initial value of this field.
  • height (BlockElementHeight) – Specifies the way the height of this container should be calculated (stretch or auto).
  • separator (bool) – Draw a separating line when set to true
  • spacing (Spacing) – Specify the spacing of this component
class pyadaptivecards.inputs.Time[source]

Input field that accepts time inputs.

__init__(id, max=None, min=None, placeholder=None, value=None, height=None, separator=None, spacing=None)[source]

Create a new time input.

Parameters:
  • id (str) – The id of this input.
  • max (str) – Maximum value for this time field. Might be ignored by the client.
  • min (str) – Minimum value for this time field. Might be ignored by the client.
  • placeholder (str) – Placeholder text to be displayed in this input field.
  • value (str) – Initial value of this field.
  • height (BlockElementHeight) – Specifies the way the height of this container should be calculated (stretch or auto).
  • separator (bool) – Draw a separating line when set to true
  • spacing (Spacing) – Specify the spacing of this component
class pyadaptivecards.inputs.Toggle[source]

Input field that lets a user toggle between multiple values.

__init__(title, id, value=None, valueOff=None, valueOn=None, height=None, separator=None, spacing=None)[source]

Create a new Toggle input.

Parameters:
  • title (str) – Title of this toggle
  • id (str) – The id of this input.
  • value (str) – Initial selected value. Defaults to “false”.
  • valueOn (str) – The value when toggle is on.
  • valueOff (str) – The value when toggle is off.
  • height (BlockElementHeight) – Specifies the way the height of this container should be calculated (stretch or auto).
  • separator (bool) – Draw a separating line when set to true
  • spacing (Spacing) – Specify the spacing of this component
class pyadaptivecards.inputs.Choices[source]

Input field that displays choices to the user.

Note

The adaptive card documentation calls this input a “ChoiceSet”

__init__(choices, id, isMultiSelect=None, style=None, value=None, height=None, separator=None, spacing=None)[source]

Create a new Choices input.

Parameters:
  • choices (list) – List of Choice components to be displayed to the user.
  • id (str) – The id of this input.
  • isMultiSelect (bool) – If True, multiple choices can be selected.
  • style (ChoiceInputStyle) – The style of this choices input.
  • value (str) – The initial choice (or choices). Comma-seperated for multiple initial selections.
  • height (BlockElementHeight) – Specifies the way the height of this container should be calculated (stretch or auto).
  • separator (bool) – Draw a separating line when set to true
  • spacing (Spacing) – Specify the spacing of this component

Actions

class pyadaptivecards.actions.OpenUrl(url, title=None, iconURL=None)[source]

Open a external url when being invoked.

__init__(url, title=None, iconURL=None)[source]

Create a new OpenUrl action.

Parameters:
  • url (str) – The URL that is opened upon being invoked.
  • title (str) – Label for the button or link that represents this action.
  • iconURL (str) – URL to the icon (currently not supported in Webex Teams)
class pyadaptivecards.actions.Submit(data=None, title=None, iconURL=None)[source]

Gather input fields in the card and submit them.

__init__(data=None, title=None, iconURL=None)[source]

Create a new Submit action.

Parameters:
  • data (dict) – Initial data. In html forms this would be hidden fields.
  • title (str) – Label for the button or link that represents this action.
  • iconURL (str) – URL to the icon (currently not supported in Webex Teams).
class pyadaptivecards.actions.ShowCard(card=None, title=None, iconURL=None)[source]

Shows the specified adaptive card when this action/button is clicked.

__init__(card=None, title=None, iconURL=None)[source]

Create a new ShowCard action.

Parameters:
  • card (AdaptiveCard) – The adaptive card that is shown.
  • title (str) – Label for the button or link that represents this action.
  • iconURL (str) – URL to the icon (currently not supported in Webex Teams).