【问题标题】:Azure Table Storage vs CosmosDB with Python使用 Python 的 Azure 表存储与 CosmosDB
【发布时间】:2018-06-30 13:10:45
【问题描述】:

我正在尝试通过 python 访问 Azure 表存储。

按照这里的旧演练: https://docs.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-python#install-the-azure-storage-sdk-for-python

但它专门为 Azure 表 (https://github.com/Azure/azure-storage-python) 引用的 Python SDK 已被移动/弃用,以支持 Azure Cosmos DB SDK。

在弃用说明中,他们说要使用此 SDK: https://github.com/Azure/azure-cosmosdb-python

在该 SDK 的文档中,他们将您推荐给 https://azure.microsoft.com/en-us/develop/python/

在该页面上的表存储和链接中,它会将您引回到第一个链接 (!!)

============

1) 我只想用 Python SDK 查询 传统 Azure 表存储(不是 CosmosDB)

2) 理想情况下,Python SDK 还包括 Azure Tables 的加密/解密功能。​​

我错过了什么/那个 python SDK 是否仍然存在于任何地方?

注意: 我看到https://github.com/Azure/azure-cosmosdb-python/tree/master/azure-cosmosdb-table 但这个 SDK 似乎需要 CosmosDB 部署——它无法连接到传统的 AzureTables。我的理解有误吗?

感谢您提供的任何帮助。

【问题讨论】:

  • 嗨,现在有更新吗?
  • 感谢您提供的答案!有助于了解 - 尽管我一直在寻找解释,如果它完全被 cosmos python sdk 吸收/互换,Laurent 的回答很清楚

标签: azure-cosmosdb azure-table-storage azure-sdk-python


【解决方案1】:

Azure 表存储有一个 new python library 预览版,可通过 pip 安装。要安装使用以下 pip 命令

pip install azure-data-tables

此 SDK 能够以 Tables 或 Cosmos 端点为目标(尽管 Cosmos 中有 known issues)。

对于查询 Azure 表存储帐户的用例,有两种查询方法。

查询单个表:

from azure.data.tables import TableClient

table_client = TableClient.from_connection_string(conn_str, table_name="myTableName")
query_filter = "RowKey eq 'row_key_5'"
for entity in table_client.query_entities(filter=query_filter):
    print(entity)

查询表的存储帐户:

from azure.data.tables import TableServiceClient

table_service_client = TableServiceClient.from_connection_string(conn_str, table_name="myTableName")
query_filter = "TableName eq 'myTable'"
for table in table_service_client .query_entities(filter=query_filter):
    print(table.table_name)

有关库的更多示例,请查看Azure GitHub Repository 上托管的示例。

(仅供参考,我在 Microsoft 的 Azure SDK for Python 团队工作)

【讨论】:

    【解决方案2】:

    Azure CosmosDB 表 SDK IS Azure 存储表 SDK。品牌重塑是微软内部重组的一部分,但这是相同的代码和相同的端点,相同的一切。

    Storage SDK 是一个大客户端,它被拆分为 Table/Queue/Blog/Files 包,以便将 Table 的所有权交给 CosmosDB 团队。

    https://docs.microsoft.com/en-us/azure/cosmos-db/table-support

    新的 Azure Cosmos DB Python SDK 是唯一支持 Azure 的 SDK Python中的表存储。此 SDK 与 Azure 表连接 存储和 Azure Cosmos DB 表 API。

    你也可以对比一下代码,你会看到:

    (我在 MS 的 Azure SDK for Python 团队工作)

    【讨论】:

    【解决方案3】:

    确实,Azure 隐藏了部分Table Storage SDK 引导链接,方便了Cosmos DB Table API 的推广。正如您在回答中提到的,Azure 存储 SDK 现在已合并到 Cosmos 菜单中。

    但是,我在 repo 中找到了来自 previous version 的旧 Azure Table Storage Python SDK。

    即使不再更新,您也可以参考上面的链接。

    顺便说一句,您可以从 link 的 Azure 表存储迁移到 Azure Cosmos Table API 的好处。

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2017-10-15
      • 2019-08-03
      • 2019-04-20
      • 2015-05-09
      • 2012-05-02
      • 2013-01-23
      • 2018-07-09
      • 2018-03-20
      • 1970-01-01
      相关资源
      最近更新 更多