Skip to main content

Bridge to Go client for Teams API

Project description

Teams API Python Wrapper

Python License Documentation


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 dataclasses and Enums. 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:

👉 Read the Documentation

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:

  1. Pending cache writes are flushed to disk.

  2. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

teams_lib_pzsp2_z1-0.1.14.tar.gz (34.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

teams_lib_pzsp2_z1-0.1.14-py3-none-any.whl (34.4 MB view details)

Uploaded Python 3

File details

Details for the file teams_lib_pzsp2_z1-0.1.14.tar.gz.

File metadata

  • Download URL: teams_lib_pzsp2_z1-0.1.14.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

Hashes for teams_lib_pzsp2_z1-0.1.14.tar.gz
Algorithm Hash digest
SHA256 0078f8af524d4cdba692bba62d251203822286e3e61da1e49a94ece04aa41e4b
MD5 26b6258d4263f7750b82ed1000581c35
BLAKE2b-256 1682e67f3dcafb7512886c3248e5b9820a36d5f29764b9458c9d78157f953ccf

See more details on using hashes here.

Provenance

The following attestation bundles were made for teams_lib_pzsp2_z1-0.1.14.tar.gz:

Publisher: publish.yml on pzsp-teams/lib-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file teams_lib_pzsp2_z1-0.1.14-py3-none-any.whl.

File metadata

File hashes

Hashes for teams_lib_pzsp2_z1-0.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 7fc371cf868b451bf7172a4714cc96641ce94bd1fba27e13165154ebe95076d5
MD5 d623225db8006d5e9c9e0249d7c59668
BLAKE2b-256 e77b86e29de8f4bcbafb1ceb3ed4489bb7e3ff5a0f8ea7f97032856c52c02868

See more details on using hashes here.

Provenance

The following attestation bundles were made for teams_lib_pzsp2_z1-0.1.14-py3-none-any.whl:

Publisher: publish.yml on pzsp-teams/lib-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page