Registry / communication / pymsteams

pymsteams

JSON →
library0.2.5pypypi✓ verified 27d ago

PyMSTeams is a Python library designed to format messages and post them to Microsoft Teams via webhooks. It simplifies the creation of rich Connector Cards with text, sections, facts, images, and actions. The current version is 0.2.5, and it has an active but irregular release cadence, with updates typically addressing minor bugs, dependency bumps, or new features.

pip install pymsteams
INSTALL
IMPORT
SIG · PYMSTEAMS
P
pymsteams
communicationpythonv0.2.5
Install
2.5s avg
Import
354ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.366s · 21.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.5s · import 0.342s · 22MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

connectorcard
from pymsteams import connectorcard
import pymsteams; connector = pymsteams.Teams(webhook_url)

This quickstart demonstrates how to create a basic Teams message with a title and a section, and send it using a webhook URL. The webhook URL is retrieved from an environment variable for security.

import pymsteams import os # Get your Microsoft Teams webhook URL from an environment variable # Example: https://outlook.office.com/webhook/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/IncomingWebhook/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx webhook_url = os.environ.get('TEAMS_WEBHOOK_URL', '') if not webhook_url: print("Error: TEAMS_WEBHOOK_URL environment variable not set.") else: myTeamsMessage = pymsteams.Teams(webhook_url) myTeamsMessage.text("Hello, Teams! This is a test message from PyMSTeams.") myTeamsMessage.title("PyMSTeams Quickstart Alert") myTeamsMessage.addSection( pymsteams.cardsection() .addFact("Status", "Success") .addFact("Environment", "Production") .addFact("Timestamp", "2024-04-09 10:30:00") ) try: myTeamsMessage.send() print("Message sent successfully!") except Exception as e: print(f"Failed to send message: {e}")
Debug
Known issues
breakingSending messages exceeding the Microsoft Teams API size limit (typically 28KB per card) will now raise a `TeamsWebhookException`.
fix
Implement `try-except pymsteams.TeamsWebhookException` around your `send()` calls and ensure your message content is within size limits. Consider breaking large messages into multiple cards.
affects: >=0.1.14
gotchaThe `send()` method's success validation was relaxed in recent versions. Previously, it strictly checked for HTTP 200 OK. Now, it validates on any 2xx HTTP status code (e.g., 202 Accepted).
fix
Be aware that a successful `send()` call might now reflect status codes other than 200. If strict 200 OK validation is required, you can manually check `myTeamsMessage.last_http_response.status_code` after `send()`.
affects: >=0.2.2
breakingVersions 0.2.5 and higher of `pymsteams` explicitly require Python 3.9 or newer.
fix
Ensure your Python environment is running version 3.9 or higher before installing or using `pymsteams`.
affects: >=0.2.5
Upgrade
Version history
0.2.5latest on PyPI · released Jan 7, 2025
Audit
Dependencies
requestsrequiredUsed for making HTTP POST requests to Microsoft Teams webhooks.
Agent activity
23 hits · last 30 days
node
20
OpenAI (training)
1
Resources
pymsteams — pip install pymsteams · libregistry