microsoft-agents-storage-blob 0.6.0.dev11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ from .blob_storage import BlobStorage
2
+ from .blob_storage_config import BlobStorageConfig
3
+
4
+ __all__ = ["BlobStorage", "BlobStorageConfig"]
@@ -0,0 +1,103 @@
1
+ import json
2
+ from typing import TypeVar, Union
3
+ from io import BytesIO
4
+
5
+ from azure.storage.blob.aio import (
6
+ ContainerClient,
7
+ BlobServiceClient,
8
+ )
9
+
10
+ from microsoft_agents.hosting.core.storage import StoreItem
11
+ from microsoft_agents.hosting.core.storage.storage import AsyncStorageBase
12
+ from microsoft_agents.hosting.core.storage._type_aliases import JSON
13
+ from microsoft_agents.hosting.core.storage.error_handling import (
14
+ ignore_error,
15
+ is_status_code_error,
16
+ )
17
+ from microsoft_agents.storage.blob.errors import blob_storage_errors
18
+
19
+ from .blob_storage_config import BlobStorageConfig
20
+
21
+ StoreItemT = TypeVar("StoreItemT", bound=StoreItem)
22
+
23
+
24
+ class BlobStorage(AsyncStorageBase):
25
+
26
+ def __init__(self, config: BlobStorageConfig):
27
+
28
+ if not config.container_name:
29
+ raise ValueError(str(blob_storage_errors.BlobContainerNameRequired))
30
+
31
+ self.config = config
32
+
33
+ blob_service_client: BlobServiceClient = self._create_client()
34
+ self._container_client: ContainerClient = (
35
+ blob_service_client.get_container_client(config.container_name)
36
+ )
37
+ self._initialized: bool = False
38
+
39
+ def _create_client(self) -> BlobServiceClient:
40
+ if self.config.url: # connect with URL and credentials
41
+ if not self.config.credential:
42
+ raise ValueError(
43
+ blob_storage_errors.InvalidConfiguration.format(
44
+ "Credential is required when using a custom service URL"
45
+ )
46
+ )
47
+ return BlobServiceClient(
48
+ account_url=self.config.url, credential=self.config.credential
49
+ )
50
+
51
+ else: # connect with connection string
52
+ return BlobServiceClient.from_connection_string(
53
+ self.config.connection_string
54
+ )
55
+
56
+ async def initialize(self) -> None:
57
+ """Initializes the storage container"""
58
+ if not self._initialized:
59
+ # This should only happen once - assuming this is a singleton.
60
+ await ignore_error(
61
+ self._container_client.create_container(), is_status_code_error(409)
62
+ )
63
+ self._initialized = True
64
+
65
+ async def _read_item(
66
+ self, key: str, *, target_cls: StoreItemT = None, **kwargs
67
+ ) -> tuple[Union[str, None], Union[StoreItemT, None]]:
68
+ item = await ignore_error(
69
+ self._container_client.download_blob(blob=key),
70
+ is_status_code_error(404),
71
+ )
72
+ if not item:
73
+ return None, None
74
+
75
+ item_rep: str = await item.readall()
76
+ item_JSON: JSON = json.loads(item_rep)
77
+ try:
78
+ return key, target_cls.from_json_to_store_item(item_JSON)
79
+ except AttributeError as error:
80
+ raise TypeError(
81
+ f"BlobStorage.read_item(): could not deserialize blob item into {target_cls} class. Error: {error}"
82
+ )
83
+
84
+ async def _write_item(self, key: str, item: StoreItem) -> None:
85
+ item_JSON: JSON = item.store_item_to_json()
86
+ if item_JSON is None:
87
+ raise ValueError(
88
+ "BlobStorage.write(): StoreItem serialization cannot return None"
89
+ )
90
+ item_rep_bytes = json.dumps(item_JSON).encode("utf-8")
91
+
92
+ # getting the length is important for performance with large blobs
93
+ await self._container_client.upload_blob(
94
+ name=key,
95
+ data=BytesIO(item_rep_bytes),
96
+ overwrite=True,
97
+ length=len(item_rep_bytes),
98
+ )
99
+
100
+ async def _delete_item(self, key: str) -> None:
101
+ await ignore_error(
102
+ self._container_client.delete_blob(blob=key), is_status_code_error(404)
103
+ )
@@ -0,0 +1,28 @@
1
+ from typing import Union
2
+
3
+ from azure.core.credentials import TokenCredential
4
+
5
+
6
+ class BlobStorageConfig:
7
+ """Configuration settings for BlobStorage."""
8
+
9
+ def __init__(
10
+ self,
11
+ container_name: str,
12
+ connection_string: str = "",
13
+ url: str = "",
14
+ credential: Union[TokenCredential, None] = None,
15
+ ):
16
+ """Configuration settings for BlobStorage.
17
+
18
+ container_name: The name of the blob container.
19
+ connection_string: The connection string to the storage account.
20
+ url: The URL of the blob service. If provided, credential must also be provided.
21
+ credential: The TokenCredential to use for authentication when using a custom URL.
22
+
23
+ credential-based authentication is prioritized over connection string authentication.
24
+ """
25
+ self.container_name: str = container_name
26
+ self.connection_string: str = connection_string
27
+ self.url: str = url
28
+ self.credential: Union[TokenCredential, None] = credential
@@ -0,0 +1,15 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
4
+ """
5
+ Error resources for Microsoft Agents Storage Blob package.
6
+ """
7
+
8
+ from microsoft_agents.hosting.core.errors import ErrorMessage
9
+
10
+ from .error_resources import BlobStorageErrorResources
11
+
12
+ # Singleton instance
13
+ blob_storage_errors = BlobStorageErrorResources()
14
+
15
+ __all__ = ["ErrorMessage", "BlobStorageErrorResources", "blob_storage_errors"]
@@ -0,0 +1,42 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
4
+ """
5
+ Blob storage error resources for Microsoft Agents SDK.
6
+
7
+ Error codes are in the range -61100 to -61199.
8
+ """
9
+
10
+ from microsoft_agents.hosting.core.errors import ErrorMessage
11
+
12
+
13
+ class BlobStorageErrorResources:
14
+ """
15
+ Error messages for blob storage operations.
16
+
17
+ Error codes are organized in the range -61100 to -61199.
18
+ """
19
+
20
+ BlobStorageConfigRequired = ErrorMessage(
21
+ "BlobStorage: BlobStorageConfig is required.",
22
+ -61100,
23
+ )
24
+
25
+ BlobConnectionStringOrUrlRequired = ErrorMessage(
26
+ "BlobStorage: either connection_string or container_url is required.",
27
+ -61101,
28
+ )
29
+
30
+ BlobContainerNameRequired = ErrorMessage(
31
+ "BlobStorage: container_name is required.",
32
+ -61102,
33
+ )
34
+
35
+ InvalidConfiguration = ErrorMessage(
36
+ "Invalid configuration: {0}",
37
+ -61103,
38
+ )
39
+
40
+ def __init__(self):
41
+ """Initialize BlobStorageErrorResources."""
42
+ pass
@@ -0,0 +1,156 @@
1
+ Metadata-Version: 2.4
2
+ Name: microsoft-agents-storage-blob
3
+ Version: 0.6.0.dev11
4
+ Summary: A blob storage library for Microsoft Agents
5
+ Author: Microsoft Corporation
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/microsoft/Agents
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Classifier: Operating System :: OS Independent
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: microsoft-agents-hosting-core==0.6.0.dev11
19
+ Requires-Dist: azure-core
20
+ Requires-Dist: azure-storage-blob
21
+ Dynamic: license-file
22
+ Dynamic: requires-dist
23
+
24
+ # Microsoft Agents Storage - Blob
25
+
26
+ [![PyPI version](https://img.shields.io/pypi/v/microsoft-agents-storage-blob)](https://pypi.org/project/microsoft-agents-storage-blob/)
27
+
28
+ Azure Blob Storage integration for Microsoft 365 Agents SDK. This library provides persistent storage for conversation state, user data, and custom agent information using Azure Blob Storage.
29
+
30
+ This library implements the storage interface for the Microsoft 365 Agents SDK using Azure Blob Storage as the backend. It enables your agents to persist conversation state, user preferences, and custom data across sessions. Perfect for production deployments where you need reliable, scalable cloud storage.
31
+
32
+ # What is this?
33
+ This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehensive framework for building enterprise-grade conversational AI agents. The SDK enables developers to create intelligent agents that work across multiple platforms including Microsoft Teams, M365 Copilot, Copilot Studio, and web chat, with support for third-party integrations like Slack, Facebook Messenger, and Twilio.
34
+
35
+ ## Release Notes
36
+ <table style="width:100%">
37
+ <tr>
38
+ <th style="width:20%">Version</th>
39
+ <th style="width:20%">Date</th>
40
+ <th style="width:60%">Release Notes</th>
41
+ </tr>
42
+ <tr>
43
+ <td>0.5.0</td>
44
+ <td>2025-10-22</td>
45
+ <td>
46
+ <a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md">
47
+ 0.5.0 Release Notes
48
+ </a>
49
+ </td>
50
+ </tr>
51
+ </table>
52
+
53
+ ## Packages Overview
54
+
55
+ We offer the following PyPI packages to create conversational experiences based on Agents:
56
+
57
+ | Package Name | PyPI Version | Description |
58
+ |--------------|-------------|-------------|
59
+ | `microsoft-agents-activity` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-activity)](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. |
60
+ | `microsoft-agents-hosting-core` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-core)](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. |
61
+ | `microsoft-agents-hosting-aiohttp` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-aiohttp)](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. |
62
+ | `microsoft-agents-hosting-teams` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-hosting-teams)](https://pypi.org/project/microsoft-agents-hosting-teams/) | Provides classes to host an Agent for Teams. |
63
+ | `microsoft-agents-storage-blob` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-blob)](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. |
64
+ | `microsoft-agents-storage-cosmos` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-storage-cosmos)](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. |
65
+ | `microsoft-agents-authentication-msal` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-authentication-msal)](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. |
66
+
67
+ Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio:
68
+
69
+ | Package Name | PyPI Version | Description |
70
+ |--------------|-------------|-------------|
71
+ | `microsoft-agents-copilotstudio-client` | [![PyPI](https://img.shields.io/pypi/v/microsoft-agents-copilotstudio-client)](https://pypi.org/project/microsoft-agents-copilotstudio-client/) | Direct to Engine client to interact with Agents created in CopilotStudio |
72
+
73
+ ## Installation
74
+
75
+ ```bash
76
+ pip install microsoft-agents-storage-blob
77
+ ```
78
+
79
+ **Benefits:**
80
+ - ✅ No secrets in code
81
+ - ✅ Managed Identity support
82
+ - ✅ Automatic token renewal
83
+ - ✅ Fine-grained access control via Azure RBAC
84
+
85
+ ### Configuration Parameters
86
+
87
+ | Parameter | Type | Required | Description |
88
+ |-----------|------|----------|-------------|
89
+ | `container_name` | `str` | Yes | Name of the blob container to use |
90
+ | `connection_string` | `str` | No* | Storage account connection string |
91
+ | `url` | `str` | No* | Blob service URL (e.g., `https://account.blob.core.windows.net`) |
92
+ | `credential` | `TokenCredential` | No** | Azure credential for authentication |
93
+
94
+ *Either `connection_string` OR (`url` + `credential`) must be provided
95
+ **Required when using `url`
96
+
97
+
98
+ ### Azure Managed Identity
99
+
100
+ When running in Azure (App Service, Functions, Container Apps), use Managed Identity:
101
+
102
+ ```python
103
+ from azure.identity import ManagedIdentityCredential
104
+
105
+ config = BlobStorageConfig(
106
+ container_name="agent-storage",
107
+ url="https://myaccount.blob.core.windows.net",
108
+ credential=ManagedIdentityCredential()
109
+ )
110
+ ```
111
+
112
+ **Azure RBAC Roles Required:**
113
+ - `Storage Blob Data Contributor` - For read/write access
114
+ - `Storage Blob Data Reader` - For read-only access
115
+
116
+ **Benefits of switching to BlobStorage:**
117
+ - ✅ Data persists across restarts
118
+ - ✅ Scalable to millions of items
119
+ - ✅ Multi-instance support (load balancing)
120
+ - ✅ Automatic backups and geo-replication
121
+ - ✅ Built-in monitoring and diagnostics
122
+
123
+ ## Best Practices
124
+
125
+ 1. **Use Token Authentication in Production** - Avoid storing connection strings; use Managed Identity or DefaultAzureCredential
126
+ 2. **Initialize Once** - Call `storage.initialize()` during app startup, not on every request
127
+ 3. **Implement Retry Logic** - Handle transient failures with exponential backoff
128
+ 4. **Monitor Performance** - Use Azure Monitor to track storage operations
129
+ 5. **Set Lifecycle Policies** - Configure automatic cleanup of old data in Azure Portal
130
+ 6. **Use Consistent Naming** - Establish key naming conventions (e.g., `user:{id}`, `conversation:{id}`)
131
+ 7. **Batch Operations** - Read/write multiple items together when possible
132
+
133
+ ## Key Classes Reference
134
+
135
+ - **`BlobStorage`** - Main storage implementation using Azure Blob Storage
136
+ - **`BlobStorageConfig`** - Configuration settings for connection and authentication
137
+ - **`StoreItem`** - Base class for data models (inherit to create custom types)
138
+
139
+ # Quick Links
140
+
141
+ - 📦 [All SDK Packages on PyPI](https://pypi.org/search/?q=microsoft-agents)
142
+ - 📖 [Complete Documentation](https://aka.ms/agents)
143
+ - 💡 [Python Samples Repository](https://github.com/microsoft/Agents/tree/main/samples/python)
144
+ - 🐛 [Report Issues](https://github.com/microsoft/Agents-for-python/issues)
145
+
146
+ # Sample Applications
147
+
148
+ |Name|Description|README|
149
+ |----|----|----|
150
+ |Quickstart|Simplest agent|[Quickstart](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/README.md)|
151
+ |Auto Sign In|Simple OAuth agent using Graph and GitHub|[auto-signin](https://github.com/microsoft/Agents/blob/main/samples/python/auto-signin/README.md)|
152
+ |OBO Authorization|OBO flow to access a Copilot Studio Agent|[obo-authorization](https://github.com/microsoft/Agents/blob/main/samples/python/obo-authorization/README.md)|
153
+ |Semantic Kernel Integration|A weather agent built with Semantic Kernel|[semantic-kernel-multiturn](https://github.com/microsoft/Agents/blob/main/samples/python/semantic-kernel-multiturn/README.md)|
154
+ |Streaming Agent|Streams OpenAI responses|[azure-ai-streaming](https://github.com/microsoft/Agents/blob/main/samples/python/azureai-streaming/README.md)|
155
+ |Copilot Studio Client|Console app to consume a Copilot Studio Agent|[copilotstudio-client](https://github.com/microsoft/Agents/blob/main/samples/python/copilotstudio-client/README.md)|
156
+ |Cards Agent|Agent that uses rich cards to enhance conversation design |[cards](https://github.com/microsoft/Agents/blob/main/samples/python/cards/README.md)|
@@ -0,0 +1,10 @@
1
+ microsoft_agents/storage/blob/__init__.py,sha256=5IxnH_hkyJrp5Gdk92cfK78d39m_DAEyjX-iFr9g1Do,137
2
+ microsoft_agents/storage/blob/blob_storage.py,sha256=oVIiXIVQ64csXZtCCCa6Gj4fCcyStPoUlH40tA2W-_I,3692
3
+ microsoft_agents/storage/blob/blob_storage_config.py,sha256=wKK7WJAdy4FIIx5HCVIDNecPefZB5Hy6jM82gKdCBF8,1009
4
+ microsoft_agents/storage/blob/errors/__init__.py,sha256=NwwZ_tWm6azLlfZ-HtGN7Mmt-Hc-npivp4c77X69GXs,433
5
+ microsoft_agents/storage/blob/errors/error_resources.py,sha256=NQbiy51rmy0HqTBHGtV28KSP-EvNAIsT1kUqqILM9ug,1023
6
+ microsoft_agents_storage_blob-0.6.0.dev11.dist-info/licenses/LICENSE,sha256=ws_MuBL-SCEBqPBFl9_FqZkaaydIJmxHrJG2parhU4M,1141
7
+ microsoft_agents_storage_blob-0.6.0.dev11.dist-info/METADATA,sha256=ARw7KKbws5SM5aQSD25ZNlhyM7SS2iognH_Fc3p28o8,8483
8
+ microsoft_agents_storage_blob-0.6.0.dev11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ microsoft_agents_storage_blob-0.6.0.dev11.dist-info/top_level.txt,sha256=lWKcT4v6fTA_NgsuHdNvuMjSrkiBMXohn64ApY7Xi8A,17
10
+ microsoft_agents_storage_blob-0.6.0.dev11.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
@@ -0,0 +1 @@
1
+ microsoft_agents