Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
5e44e93
feat: implemented better json decoding function
susek555 Dec 21, 2025
177141e
feat: written Teams service in go bridge
susek555 Dec 21, 2025
8442b0c
feat: adjusted update Team patch DTO
susek555 Dec 21, 2025
b0dcf5f
refactor: improved go requests handling
susek555 Dec 23, 2025
be98ae6
feat: implemented most of teams service in python
susek555 Dec 23, 2025
894abbd
feat: implemented update team function in python
susek555 Dec 23, 2025
8e48ff7
feat: Written test to validate get teams request
susek555 Dec 23, 2025
f9fd045
feat: added test to createTeamViaGroup (torture)
susek555 Dec 23, 2025
463e88e
feat: Implemented test to createTeamFromTemplate
susek555 Dec 27, 2025
8689e66
feat: implemented test to ArchiveTeam
susek555 Dec 27, 2025
1166782
feat: Implemented test for UnarchiveTeam integration
susek555 Dec 27, 2025
4daa3b5
feat: implemented integration tests
susek555 Dec 27, 2025
fc4284c
feat: added integration test to check error handling
susek555 Dec 27, 2025
ecfaa87
feat: implemented integration test for UpdateTeam
susek555 Dec 27, 2025
2b0fdd1
feat: implemented part of channels endpoints
susek555 Dec 27, 2025
41e5dff
feat: implemented rest of channel endpoints
susek555 Dec 27, 2025
52e89ac
feat: added channels endpoints to map
susek555 Dec 27, 2025
76eaec0
chore: deleted unnecessary file
susek555 Dec 27, 2025
53de9fa
feat: added models of member and message in python
susek555 Dec 27, 2025
9ce9d63
feat: Wrapped functions for channels and messages
susek555 Dec 28, 2025
83bc2b9
feat: wrapped members management functions
susek555 Dec 28, 2025
2844dec
feat: Added integration test for get_channel
susek555 Dec 28, 2025
ad83352
feat: added test for creating standard channel
susek555 Dec 28, 2025
31b2e3d
feat: added tests to getting messages
susek555 Dec 28, 2025
221ad38
feat: implemented tests for replies
susek555 Dec 29, 2025
e168fc6
feat: added send message in channel test
susek555 Dec 29, 2025
7f20b76
feat: added tests to members management
susek555 Dec 29, 2025
8267c4e
feat: added chats endpoints to bridge
susek555 Dec 29, 2025
be56e37
feat: added chat endpoints to request map
susek555 Dec 29, 2025
de296a6
feat: prepared structure for chat service in python
susek555 Dec 29, 2025
b64f882
feat: resolved chatRef
susek555 Dec 31, 2025
83c5824
feat: added chat endpoints to bridge
susek555 Dec 31, 2025
a3ce10b
feat: adjusted channels endpoints to lib changes
susek555 Dec 31, 2025
e3da1b6
feat: adjusted requests map
susek555 Dec 31, 2025
b83ea84
refactor: requests schema
susek555 Dec 31, 2025
2a0944b
chore: tried to fix resolving user bug (failed)
susek555 Jan 1, 2026
8f30680
feat: added majority of chats request in python client
susek555 Jan 1, 2026
e1202fd
feat: implemented get mentions handling
susek555 Jan 1, 2026
3935f7f
feat: adjusted client creation in bridge
susek555 Jan 1, 2026
39c9c88
chore: adjusted python client creation
susek555 Jan 1, 2026
2e1c804
chore: adjusted fake client creating
susek555 Jan 1, 2026
a152178
fix: real client init
susek555 Jan 1, 2026
f7f5759
feat: implemented test for list chats
susek555 Jan 2, 2026
33da757
feat: implemented test for create group chat endpoint
susek555 Jan 2, 2026
c36f619
feat: implemented test for list_members in chat
susek555 Jan 2, 2026
b8549ad
feat: implemented membership management tests
susek555 Jan 2, 2026
8e5491e
feat: added list chat messages test
susek555 Jan 2, 2026
76801ab
feat: added message management tests
susek555 Jan 2, 2026
8d75893
feat: implemented get message in chat test
susek555 Jan 2, 2026
c69a7ed
feat: implemented test for list All my messeges
susek555 Jan 2, 2026
c7f7935
feat: implemented tests for pinned messages
susek555 Jan 2, 2026
0f5713d
feat: implemented tests for get mentions
susek555 Jan 2, 2026
854263a
chore: cleaned mock server code formatting a bit
susek555 Jan 2, 2026
26c325c
feat: commented and formatted channels service
susek555 Jan 7, 2026
19b9f1f
feat: added docstrings for chat service
susek555 Jan 7, 2026
0dd0eae
style: ignored ruff line too long warnings
susek555 Jan 7, 2026
652653d
chore: adjusted go channels requests to new lib version
susek555 Jan 7, 2026
757a703
chore: adjusted chats and teams in go bridge
susek555 Jan 7, 2026
72fe0af
feat: added new data models to python
susek555 Jan 7, 2026
dd97bde
chore: adjusted update team python and test
susek555 Jan 7, 2026
5d0e60b
chore: adjusted list channels messages
susek555 Jan 7, 2026
712e3df
chore: adjusted list replies in channels
susek555 Jan 7, 2026
b3d9bea
chore: adjusted list messages in chats
susek555 Jan 7, 2026
6ec5db7
chore: adjusted create team from template to lib changes
susek555 Jan 7, 2026
cf8e812
docs: added docstrings for team service
susek555 Jan 8, 2026
426bcbb
docs: added comments for channel and chat models
susek555 Jan 8, 2026
63d26bb
docs: added docstrings for member and mention models
susek555 Jan 8, 2026
07b2da5
fix: tests after changing models fields to snake_case
susek555 Jan 8, 2026
372aac6
docs: added docstrings for message models
susek555 Jan 8, 2026
c7fb49d
docs: added docstrings for team models
susek555 Jan 8, 2026
46c7046
docs: client init docstrings
susek555 Jan 8, 2026
7ab77a8
feat: improved lib closing to ensure cache operations
susek555 Jan 8, 2026
3aec827
docs: docstrings in for client configs
susek555 Jan 8, 2026
d7bf4c1
chore: added env template
susek555 Jan 8, 2026
d41b007
docs: Generated docs using mkdocstrings lib
susek555 Jan 8, 2026
30782b7
docs: added example flow charts
susek555 Jan 8, 2026
1983fe1
docs: added part of README
susek555 Jan 8, 2026
3560098
docs: added rest of README file
susek555 Jan 8, 2026
2ec801f
chore: removed docs dir from python release branch
susek555 Jan 8, 2026
5a83154
fix: typo
susek555 Jan 8, 2026
f179f0c
docs: updated main project README
susek555 Jan 8, 2026
e4f8523
docs: added go reference
susek555 Jan 8, 2026
8a9f6d4
chore: adjusted test for listPinned messages
susek555 Jan 11, 2026
fdf54e2
fix: tried to fix resolving id from header
susek555 Jan 11, 2026
3596740
feat: added searchmessages options structs
susek555 Jan 12, 2026
354c67c
feat: added new functions to go bridge
susek555 Jan 12, 2026
cf62781
feat: added search messages structures to python
susek555 Jan 12, 2026
35d3db7
feat: added new search functions to python lib
susek555 Jan 12, 2026
56c466b
docs: added new search structs to docs
susek555 Jan 12, 2026
5cc79e9
test: added test for get chat
susek555 Jan 12, 2026
552cbab
test: finally added test for search in chats
susek555 Jan 13, 2026
9e95730
test: added test for search in channels
susek555 Jan 13, 2026
dec2fae
chore: cleaned tests
susek555 Jan 13, 2026
3c16502
chore: removed unnecessary comments
susek555 Jan 13, 2026
50e9956
docs: README fixes
susek555 Jan 13, 2026
ed2d7cb
chore: replaced interface{} with any
susek555 Jan 13, 2026
4444fb5
refactor: passed context.background from main
susek555 Jan 13, 2026
44eaca4
docs: solved todo in python docs readme
susek555 Jan 13, 2026
386a231
docs: fixed index.md
susek555 Jan 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: Python Integration Tests

on:
pull_request:
branches: [ main ]
branches: [main]
types: [review_requested, ready_for_review]
push:
branches: [ main ]
branches: [main]
repository_dispatch:
types: [verify-new-go-lib-version]

Expand Down Expand Up @@ -237,6 +237,8 @@ jobs:

# clean up unneeded files
rm -rf python_release/tests
rm -rf python_release/docs
rm python_release/mkdocs.yml
find python_release -type d -name "__pycache__" -exec rm -rf {} +
rm -rf python_release/.venv

Expand Down
124 changes: 123 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,123 @@
# lib-python
# Teams API Python Wrapper

[![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Documentation](https://img.shields.io/badge/docs-online-green)](https://pzsp-teams.github.io/lib-python/)

<br>

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

```bash
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:

```ini
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](https://github.com/pzsp-teams/lib-python/tree/main/.env.template).

### 2. Basic usage

Here is a minimal example showing how to initialize the client and list joined teams:

```python
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](https://pzsp-teams.github.io/lib-python/)

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

```python
client.close()
```

## 📄 License
This project is licensed under the MIT License - see the [LICENSE](https://github.com/pzsp-teams/lib-python/blob/main/LICENSE) file for details.

## Port
This lib is also available in [GO](https://github.com/pzsp-teams/lib)
27 changes: 17 additions & 10 deletions go/bridge/main.go
Comment thread
KamilMarszalek marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"encoding/json"
"fmt"
"os"
"context"

jsonClientLib "github.com/pzsp-teams/lib-python/internal/json-client"
jsonModel "github.com/pzsp-teams/lib-python/internal/json-model"
"github.com/pzsp-teams/lib"
)

var client *jsonClientLib.TeamsJSONClient
Expand Down Expand Up @@ -51,19 +53,24 @@ func main() {
continue
}

switch req.Method {
case "listChannels":
channels, err := client.ListChannels(req.Params)
if err != nil {
respondError(writer, err)
} else {
respondResult(writer, channels)
}
default:
handler, exists := jsonClientLib.Handlers[req.Method]
if !exists {
respondError(writer, fmt.Errorf("unknown method"))
continue
}

result, err := handler(client, context.Background(), req.Params)
if err != nil {
respondError(writer, err)
}
respondResult(writer, result)
continue
}
respondError(writer, fmt.Errorf("unknown request type"))

if req.Type == "close" {
lib.Close()
respondResult(writer, "closed")
return
}
}
}
4 changes: 2 additions & 2 deletions go/bridge/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type response struct {
Result interface{} `json:"result,omitempty"`
Result any `json:"result,omitempty"`
Error string `json:"error,omitempty"`
}

Expand All @@ -29,7 +29,7 @@ func respondError(writer *bufio.Writer, err error) {
writer.Flush()
}

func respondResult(writer *bufio.Writer, result interface{}) {
func respondResult(writer *bufio.Writer, result any) {
response := response{
Result: result,
}
Expand Down
35 changes: 19 additions & 16 deletions go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@ go 1.25.5

require (
github.com/microsoft/kiota-abstractions-go v1.9.3
github.com/microsoftgraph/msgraph-sdk-go v1.90.0
github.com/pzsp-teams/lib v0.0.0-20251213104555-e41d3adf599f
github.com/microsoftgraph/msgraph-sdk-go v1.93.0
github.com/mitchellh/mapstructure v1.5.0
github.com/pzsp-teams/lib v0.0.0-20260112132712-1335fb93c11f
)

require (
al.essio.dev/pkg/shellescape v1.5.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.19.1 // indirect
al.essio.dev/pkg/shellescape v1.6.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.20.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2 // indirect
github.com/AzureAD/microsoft-authentication-extensions-for-go/cache v0.1.1 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.6.0 // indirect
github.com/danieljoos/wincred v1.2.2 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/danieljoos/wincred v1.2.3 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
github.com/godbus/dbus/v5 v5.2.2 // indirect
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/keybase/go-keychain v0.0.0-20230523030712-b5615109f100 // indirect
github.com/keybase/go-keychain v0.0.1 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/microsoft/kiota-authentication-azure-go v1.3.1 // indirect
github.com/microsoft/kiota-http-go v1.5.4 // indirect
Expand All @@ -30,13 +32,14 @@ require (
github.com/microsoft/kiota-serialization-text-go v1.1.3 // indirect
github.com/microsoftgraph/msgraph-sdk-go-core v1.4.0 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/std-uritemplate/std-uritemplate/go/v2 v2.0.3 // indirect
github.com/std-uritemplate/std-uritemplate/go/v2 v2.0.8 // indirect
github.com/zalando/go-keyring v0.2.6 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/otel v1.37.0 // indirect
go.opentelemetry.io/otel/metric v1.37.0 // indirect
go.opentelemetry.io/otel/trace v1.37.0 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/text v0.28.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/otel v1.39.0 // indirect
go.opentelemetry.io/otel/metric v1.39.0 // indirect
go.opentelemetry.io/otel/trace v1.39.0 // indirect
golang.org/x/net v0.48.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.39.0 // indirect
golang.org/x/text v0.32.0 // indirect
)
Loading