-
Notifications
You must be signed in to change notification settings - Fork 0
16 document the library #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 177141e
feat: written Teams service in go bridge
susek555 8442b0c
feat: adjusted update Team patch DTO
susek555 b0dcf5f
refactor: improved go requests handling
susek555 be98ae6
feat: implemented most of teams service in python
susek555 894abbd
feat: implemented update team function in python
susek555 8e48ff7
feat: Written test to validate get teams request
susek555 f9fd045
feat: added test to createTeamViaGroup (torture)
susek555 463e88e
feat: Implemented test to createTeamFromTemplate
susek555 8689e66
feat: implemented test to ArchiveTeam
susek555 1166782
feat: Implemented test for UnarchiveTeam integration
susek555 4daa3b5
feat: implemented integration tests
susek555 fc4284c
feat: added integration test to check error handling
susek555 ecfaa87
feat: implemented integration test for UpdateTeam
susek555 2b0fdd1
feat: implemented part of channels endpoints
susek555 41e5dff
feat: implemented rest of channel endpoints
susek555 52e89ac
feat: added channels endpoints to map
susek555 76eaec0
chore: deleted unnecessary file
susek555 53de9fa
feat: added models of member and message in python
susek555 9ce9d63
feat: Wrapped functions for channels and messages
susek555 83bc2b9
feat: wrapped members management functions
susek555 2844dec
feat: Added integration test for get_channel
susek555 ad83352
feat: added test for creating standard channel
susek555 31b2e3d
feat: added tests to getting messages
susek555 221ad38
feat: implemented tests for replies
susek555 e168fc6
feat: added send message in channel test
susek555 7f20b76
feat: added tests to members management
susek555 8267c4e
feat: added chats endpoints to bridge
susek555 be56e37
feat: added chat endpoints to request map
susek555 de296a6
feat: prepared structure for chat service in python
susek555 b64f882
feat: resolved chatRef
susek555 83c5824
feat: added chat endpoints to bridge
susek555 a3ce10b
feat: adjusted channels endpoints to lib changes
susek555 e3da1b6
feat: adjusted requests map
susek555 b83ea84
refactor: requests schema
susek555 2a0944b
chore: tried to fix resolving user bug (failed)
susek555 8f30680
feat: added majority of chats request in python client
susek555 e1202fd
feat: implemented get mentions handling
susek555 3935f7f
feat: adjusted client creation in bridge
susek555 39c9c88
chore: adjusted python client creation
susek555 2e1c804
chore: adjusted fake client creating
susek555 a152178
fix: real client init
susek555 f7f5759
feat: implemented test for list chats
susek555 33da757
feat: implemented test for create group chat endpoint
susek555 c36f619
feat: implemented test for list_members in chat
susek555 b8549ad
feat: implemented membership management tests
susek555 8e5491e
feat: added list chat messages test
susek555 76801ab
feat: added message management tests
susek555 8d75893
feat: implemented get message in chat test
susek555 c69a7ed
feat: implemented test for list All my messeges
susek555 c7f7935
feat: implemented tests for pinned messages
susek555 0f5713d
feat: implemented tests for get mentions
susek555 854263a
chore: cleaned mock server code formatting a bit
susek555 26c325c
feat: commented and formatted channels service
susek555 19b9f1f
feat: added docstrings for chat service
susek555 0dd0eae
style: ignored ruff line too long warnings
susek555 652653d
chore: adjusted go channels requests to new lib version
susek555 757a703
chore: adjusted chats and teams in go bridge
susek555 72fe0af
feat: added new data models to python
susek555 dd97bde
chore: adjusted update team python and test
susek555 5d0e60b
chore: adjusted list channels messages
susek555 712e3df
chore: adjusted list replies in channels
susek555 b3d9bea
chore: adjusted list messages in chats
susek555 6ec5db7
chore: adjusted create team from template to lib changes
susek555 cf8e812
docs: added docstrings for team service
susek555 426bcbb
docs: added comments for channel and chat models
susek555 63d26bb
docs: added docstrings for member and mention models
susek555 07b2da5
fix: tests after changing models fields to snake_case
susek555 372aac6
docs: added docstrings for message models
susek555 c7fb49d
docs: added docstrings for team models
susek555 46c7046
docs: client init docstrings
susek555 7ab77a8
feat: improved lib closing to ensure cache operations
susek555 3aec827
docs: docstrings in for client configs
susek555 d7bf4c1
chore: added env template
susek555 d41b007
docs: Generated docs using mkdocstrings lib
susek555 30782b7
docs: added example flow charts
susek555 1983fe1
docs: added part of README
susek555 3560098
docs: added rest of README file
susek555 2ec801f
chore: removed docs dir from python release branch
susek555 5a83154
fix: typo
susek555 f179f0c
docs: updated main project README
susek555 e4f8523
docs: added go reference
susek555 8a9f6d4
chore: adjusted test for listPinned messages
susek555 fdf54e2
fix: tried to fix resolving id from header
susek555 3596740
feat: added searchmessages options structs
susek555 354c67c
feat: added new functions to go bridge
susek555 cf62781
feat: added search messages structures to python
susek555 35d3db7
feat: added new search functions to python lib
susek555 56c466b
docs: added new search structs to docs
susek555 5cc79e9
test: added test for get chat
susek555 552cbab
test: finally added test for search in chats
susek555 9e95730
test: added test for search in channels
susek555 dec2fae
chore: cleaned tests
susek555 3c16502
chore: removed unnecessary comments
susek555 50e9956
docs: README fixes
susek555 ed2d7cb
chore: replaced interface{} with any
susek555 4444fb5
refactor: passed context.background from main
susek555 44eaca4
docs: solved todo in python docs readme
susek555 386a231
docs: fixed index.md
susek555 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,123 @@ | ||
| # lib-python | ||
| # Teams API Python Wrapper | ||
|
|
||
| [](https://www.python.org/) | ||
| [](LICENSE) | ||
| [](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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.