Bridge to Go client for Teams API
Project description
Teams API Python Wrapper
A high-performance Python wrapper for the Microsoft Teams Graph API. It leverages a compiled Go (Golang) backend to handle heavy lifting, concurrency, and caching, while providing a clean, fully typed Pythonic interface.
🚀 Key Features
- Performance of Go: Uses a compiled Go subprocess for efficient API communication and state management.
- Pythonic Interface: Fully typed using
dataclassesandEnums. Native support for IDE autocompletion and type checkers (mypy). - Intelligent Cache: Background caching of Team/Channel IDs to minimize API throttling and latency (handled transparently by the backend).
- Simplified Auth: Wraps MSAL authentication flows configuration.
📦 Installation
pip install teams-lib-pzsp2-z1
🛠️ Architecture
This library acts as a bridge. When initialized, it spawns a dedicated Go subprocess (teamsClientLib) and communicates via JSON-RPC over stdin/stdout.
The TeamsClient aggregates domain-specific services:
-
client.teams: Manage team lifecycles (create, list, delete).
-
client.channels: Manage standard and private channels.
-
client.chats: Handle messages, mentions, and chat participants.
💻 Quick Start
1. Configuration
Create a .env in your project with your Azure AD credentials:
CLIENT_ID=your-client-id-uuid
TENANT_ID=your-tenant-id-uuid
EMAIL=user@example.com
SCOPES=User.Read,Team.ReadBasic.All,Channel.ReadBasic.All
AUTH_METHOD=DEVICE_CODE [or INTERACTIVE]
Scopes needed by all functions could be found in .env.template.
2. Basic usage
Here is a minimal example showing how to initialize the client and list joined teams:
from teams_lib_pzsp2_z1.client import TeamsClient
from teams_lib_pzsp2_z1.config import CacheMode
def main():
# Initialize the client.
# This spawns the Go subprocess and performs authentication.
client = TeamsClient()
try:
print("Fetching teams...")
teams = client.teams.list_my_joined()
for team in teams:
print(f"Team: {team.display_name} | ID: {team.id}")
# Example: List channels in the first team
channels = client.channels.list_channels(team.id)
print(f" -> Found {len(channels)} channels.")
except RuntimeError as e:
print(f"An error occurred: {e}")
finally:
# Crucial: Close the client to ensure background cache writes finish
# and the Go subprocess is terminated gracefully.
client.close()
if __name__ == "__main__":
main()
📚 Documentation
Full API reference, architecture details, and configuration guides are available here:
Authentication
The library loads credentials from environment variables. Ensure your Azure App Registration has the necessary API Permissions (e.g., Team.ReadBasic.All, Channel.ReadBasic.All) granted in the Azure Portal.
Supported Authentication Methods (AUTH_METHOD):
-
INTERACTIVE: Opens a browser window automatically.
-
DEVICE_CODE: Prints a code to the console to login via microsoft.com/devicelogin.
Cache & Lifecycle
If caching is enabled (SYNC or ASYNC), the Go backend stores metadata locally (e.g., teams_cache.json) to speed up reference resolution.
⚠️ Important: client.close()
Because the Go backend might be running background goroutines (especially for Async Cache), you must call client.close() before your script exits. This ensures:
-
Pending cache writes are flushed to disk.
-
The Go subprocess is terminated correctly.
client.close()
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file teams_lib_pzsp2_z1-0.1.19.tar.gz.
File metadata
- Download URL: teams_lib_pzsp2_z1-0.1.19.tar.gz
- Upload date:
- Size: 34.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f3d0e01b5aa8f95ac7dd21de3b3d90f52797960c4882e2e30640a4ed48c63b2
|
|
| MD5 |
49b7303ef2dbe09f9b3200a427a50437
|
|
| BLAKE2b-256 |
9265bb62a80964454c6e5f01798c13d369602f4706adeb3fabafeee6530bf9f4
|
Provenance
The following attestation bundles were made for teams_lib_pzsp2_z1-0.1.19.tar.gz:
Publisher:
publish.yml on pzsp-teams/lib-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
teams_lib_pzsp2_z1-0.1.19.tar.gz -
Subject digest:
3f3d0e01b5aa8f95ac7dd21de3b3d90f52797960c4882e2e30640a4ed48c63b2 - Sigstore transparency entry: 834925946
- Sigstore integration time:
-
Permalink:
pzsp-teams/lib-python@fc7a19e5ed4243a54116200e8a43e999c97180ad -
Branch / Tag:
refs/heads/python-release - Owner: https://github.com/pzsp-teams
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fc7a19e5ed4243a54116200e8a43e999c97180ad -
Trigger Event:
push
-
Statement type:
File details
Details for the file teams_lib_pzsp2_z1-0.1.19-py3-none-any.whl.
File metadata
- Download URL: teams_lib_pzsp2_z1-0.1.19-py3-none-any.whl
- Upload date:
- Size: 34.4 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc001fcb94b13b0eb3daa49b260cb9e480ef644a1869cb0bfad3d05e1fa04be1
|
|
| MD5 |
b3edae5dc638363466731dede0d5c1cb
|
|
| BLAKE2b-256 |
15708b37e97ad50ec601fcf29430928ce89e99208bdb41751d8c5eb5a4352b55
|
Provenance
The following attestation bundles were made for teams_lib_pzsp2_z1-0.1.19-py3-none-any.whl:
Publisher:
publish.yml on pzsp-teams/lib-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
teams_lib_pzsp2_z1-0.1.19-py3-none-any.whl -
Subject digest:
bc001fcb94b13b0eb3daa49b260cb9e480ef644a1869cb0bfad3d05e1fa04be1 - Sigstore transparency entry: 834925960
- Sigstore integration time:
-
Permalink:
pzsp-teams/lib-python@fc7a19e5ed4243a54116200e8a43e999c97180ad -
Branch / Tag:
refs/heads/python-release - Owner: https://github.com/pzsp-teams
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fc7a19e5ed4243a54116200e8a43e999c97180ad -
Trigger Event:
push
-
Statement type: