Send a Message to Microsoft Teams from Python
Sending messages to Microsoft Teams from Python can be an effective way of monitoring an a long running Python program.
Create a new channel in your Team if desired. A new channel will prevent Python generated notices from taking over other conversation channels.
Add a new connector on your desired channel.
Find the Webhook connector and configure.
The configuration required is just a name for the webhook and optionally an image.
Click create and copy the resulting webhook URL.
That’s all the configuration needed in Teams. Next, add some code your Python project so that it can write a message to Teams.
Install pymsteams with pip.
pip install pymsteams
Add this code to your Python project to enable writing messages to Teams, substitute the URL for your webhook:
import pymsteams
myTeamsMessage = pymsteams.connectorcard("INSERT WEBHOOK URL HERE")
Use this code to generate messages:
myTeamsMessage.text("This message was generated from Python!")
myTeamsMessage.send()