Format messages and post to Microsoft Teams.

Microsoft, Teams
pip install pymsteams==0.1.14



CircleCI PyPI version

Python Wrapper Library to send requests to Microsoft Teams Webhooks. Microsoft refers to these messages as Connector Cards. A message can be sent with only the main Connector Card, or additional sections can be included into the message.

This library uses Webhook Connectors for Microsoft Teams. Please visit the following Microsoft Documentation link for instructions on how to obtain the correct url for your Channel:

Please refer to the Microsoft Documentation for the most up to date screenshots.


Install with pip:

pip install pymsteams


Creating ConnectorCard Messages

This is the simplest implementation of pymsteams. It will send a message to the teams webhook url with plain text in the message.

import pymsteams

# You must create the connectorcard object with the Microsoft Webhook URL
myTeamsMessage = pymsteams.connectorcard("<Microsoft Webhook URL>")

# Add text to the message.
myTeamsMessage.text("this is my text")

# send the message.

Optional Formatting Methods for Cards

Add a title

myTeamsMessage.title("This is my message title")

Add a link button

myTeamsMessage.addLinkButton("This is the button Text", "")

Change URL

This is useful in the event you need to post the same message to multiple rooms.

myTeamsMessage.newhookurl("<My New URL>")

Set Color Theme

This sets the theme color of the card. The parameter is expected to be a hex color code without the hash or the string red.

myTeamsMessage.color("<Hex Color Code>")

Preview your object

This is a simple print command to view your connector card message object before sending.


Adding sections to the Connector Card Message

To create a section and add various formatting elements

# create the section
myMessageSection = pymsteams.cardsection()

# Section Title
myMessageSection.title("Section title")

# Activity Elements
myMessageSection.activityTitle("my activity title")
myMessageSection.activitySubtitle("my activity subtitle")
myMessageSection.activityText("This is my activity Text")

# Facts are key value pairs displayed in a list.
myMessageSection.addFact("this", "is fine")
myMessageSection.addFact("this is", "also fine")

# Section Text
myMessageSection.text("This is my section text")

# Section Images
myMessageSection.addImage("", ititle="This Is Fine")

# Add your section to the connector card object before sending

You may also add multiple sections to a connector card message as well.

# Create Section 1
Section1 = pymsteams.cardsection()
Section1.text("My First Section")

# Create Section 2
Section2 = pymsteams.cardsection()
Section2.text("My Second Section")

# Add both Sections to the main card object

# Then send the card

Adding potential actions to the Connector Card Message

To create a actions on which the user can interect with in MS Teams To find out more information on what actions can be used, please visit

myTeamsMessage = pymsteams.connectorcard("<Microsoft Webhook URL>")

myTeamsPotentialAction1 = pymsteams.potentialaction(_name = "Add a comment")
myTeamsPotentialAction1.addInput("TextInput","comment","Add a comment here",False)
myTeamsPotentialAction1.addAction("HttpPost","Add Comment","https://...")

myTeamsPotentialAction2 = pymsteams.potentialaction(_name = "Set due date")
myTeamsPotentialAction2.addInput("DateInput","dueDate","Enter due date")

myTeamsPotentialAction3 = pymsteams.potentialaction(_name = "Change Status")
myTeamsPotentialAction3.choices.addChoices("In progress","0")
myTeamsPotentialAction3.addInput("MultichoiceInput","list","Select a status",False)


myTeamsMessage.summary("Test Message")


Please use Github issues to report any bugs or request enhancements.

Troubleshooting HTTP response

This module is really just a nice wrapper pointed at the Microsoft API. To help troubleshoot missing messages, the requests response content is saved to the connectorcard class attribute last_http_status.

To get the last http status code:

import pymsteams

myTeamsMessage = pymsteams.connectorcard("<Microsoft Webhook URL>")
myTeamsMessage.text("this is my text")

last_status_code = myTeamsMessage.last_http_status.status_code

More info on the Repsponse Conent is available in the requests documentation, link.


If the call to the Microsoft Teams webhook service fails, a TeamsWebhookException will be thrown.


In order to test in your environment with pytest, set the environment variable MS_TEAMS_WEBHOOK to the Microsoft Teams Webhook url you would like to use.

Then, from the root of the repo, install the requirements and run pytest.

pip install -r dev-requirements.txt

This will send two MS Teams messages describing how they are formatted. Manually validate that the message comes through as expected.

Certificate Validation

In some situations, a custom CA bundle must be used. This can be set on class initialization, by setting the verify parameter.

import pymsteams

# set custom ca bundle
msg = pymsteams.connectorcard("<Microsoft Webhook URL>", verify="/path/to/file")

# disable CA validation
msg = pymsteams.connectorcard("<Microsoft Webhook URL>", verify=False)

Set to either the path of a custom CA bundle or False to disable.

The requests documentation can be referenced for full details: