Client Reference
Main lib entry point.
teams_lib_pzsp2_z1.client.TeamsClient
The main entry point for interacting with the Microsoft Teams library.
This class manages the lifecycle of the underlying Go subprocess, handles Inter-Process Communication (IPC) via JSON over stdin/stdout, and exposes high-level services for Teams, Channels, and Chats.
Architecture:
The Python library acts as a frontend wrapper. It spawns a compiled Go binary
(teamsClientLib) as a subprocess. Commands are serialized to JSON and sent
to the Go process, which executes the actual Microsoft Graph API calls and
returns the results.
Attributes:
| Name | Type | Description |
|---|---|---|
channels |
ChannelsService
|
Service for managing channels. |
teams |
TeamsService
|
Service for managing teams. |
chats |
ChatsService
|
Service for managing chats and messages. |
Source code in teams_lib_pzsp2_z1/client.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
Functions
__init__(auto_init=True, env_path=None, cache_mode=config.CacheMode.DISABLED, cache_path=None)
Initializes the TeamsClient and spawns the Go subprocess.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auto_init
|
bool
|
If True, automatically calls |
True
|
env_path
|
str | None
|
Path to the |
None
|
cache_mode
|
CacheMode
|
The caching strategy to use (e.g., DISABLED, IN_MEMORY, DISK). Defaults to DISABLED. |
DISABLED
|
cache_path
|
str | None
|
File path for the cache (required if cache_mode is DISK). Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the operating system is not supported (only Windows/Linux). |
Source code in teams_lib_pzsp2_z1/client.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
close()
Gracefully closes the Go backend, ensuring cache is synced.
Sends a 'close' command to the Go process, which triggers lib.Close()
to wait for background cache operations. Then terminates the process.
Source code in teams_lib_pzsp2_z1/client.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
execute(cmd_type, method=None, config=None, params=None)
Executes a command on the Go subprocess via JSON-IPC.
This is the low-level bridge method used by services to communicate with the backend. It handles serialization, thread-safe writing to stdin, reading from stdout, and error propagation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd_type
|
str
|
The type of command (e.g., "init", "request"). |
required |
method
|
str | None
|
The specific API method to call (e.g., "listChannels"). Required if cmd_type is "request". |
None
|
config
|
dict | None
|
Configuration payload (used primarily for initialization). |
None
|
params
|
dict | None
|
Parameters for the method call (e.g., teamRef, body). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The 'result' field from the Go response. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the Go process crashes, closes the pipe, returns an empty response, or explicitly reports an error in the "error" field. |
Source code in teams_lib_pzsp2_z1/client.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
init_client(cache_mode=config.CacheMode.DISABLED, cache_path=None)
Initializes the Go backend with authentication and cache configuration.
This method sends the 'init' command to the Go process, which sets up the MSAL token provider and the Graph Service Client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_mode
|
CacheMode
|
The caching strategy. |
DISABLED
|
cache_path
|
str | None
|
Path to the cache file (if applicable). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The initialization result from the Go process. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the Go process reports an initialization error. |
Source code in teams_lib_pzsp2_z1/client.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
init_fake_client(mock_server_url)
Initializes the Go backend in test mode using a mock server.
This bypasses real MSAL authentication and directs Graph API calls to the provided local URL. [For testing purposes only]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mock_server_url
|
str
|
The URL of the mock HTTP server. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The result of the initialization. |
Source code in teams_lib_pzsp2_z1/client.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |