TableClient クラス

Azure Tables アカウント内の特定のテーブルと対話するクライアント。

資格情報から TableClient を作成します。

継承
azure.data.tables._base_client.TablesBaseClient
TableClient

コンストラクター

TableClient(endpoint: str, table_name: str, *, credential: AzureNamedKeyCredential | AzureSasCredential | TokenCredential | None = None, **kwargs)

パラメーター

endpoint
str
必須

Azure Tables アカウントの URL。

table_name
str
必須

テーブル名。

credential
AzureNamedKeyCredential または AzureSasCredential または TokenCredential または None

認証に使用する資格情報。 アカウント URL に SAS トークンが既に含まれている場合、これは省略可能です。 値には、AzureNamedKeyCredential (azure-core)、AzureSasCredential (azure-core)、または azure-identity からの TokenCredential 実装のいずれかを指定できます。

api_version
str

この要求に使用する操作のバージョンを指定します。 既定値は "2019-02-02" です。

変数

account_name
str

Tables アカウントの名前。

table_name
str

テーブルの名前。

scheme
str

Tables アカウントへの完全な URL のスキーム コンポーネント。

url
str

ストレージ エンドポイント。

api_version
str

サービス API のバージョン。

メソッド

close

このメソッドは、クライアントによって開かれたソケットを閉じる方法です。 コンテキスト マネージャーで を使用する場合は使用する必要はありません。

create_entity

テーブルにエンティティを挿入します。

create_table

現在のアカウントの下に新しいテーブルを作成します。

delete_entity

テーブル内の指定したエンティティを削除します。 エンティティまたは PartitionKey-RowKey ペアリングが見つからない場合、エラーは発生しません。

delete_table

現在のアカウントのテーブルを削除します。 テーブルが存在しない場合、エラーは発生しません

from_connection_string

接続文字列から TableClient を作成します。

from_table_url

特定のテーブルと対話するクライアント。

AzureSasCredential (azure-core)、または azure-identity からの TokenCredential 実装。 :p aramtype 資格情報:

~azure.core.credentials.AzureNamedKeyCredential または ~azure.core.credentials.AzureSasCredential または None

get_entity

テーブル内の 1 つのエンティティを取得します。

get_table_access_policy

Shared Access Signature で使用できるテーブルで指定された格納されているアクセス ポリシーに関する詳細を取得します。

list_entities

テーブル内のエンティティを一覧表示します。

query_entities

テーブル内のエンティティを一覧表示します。

set_table_access_policy

Shared Access Signature で使用できるテーブルの格納されているアクセス ポリシーを設定します。

submit_transaction

操作の一覧を 1 つのトランザクションとしてコミットします。

これらの操作のいずれかが失敗した場合、トランザクション全体が拒否されます。

update_entity

テーブル内のエンティティを更新します。

upsert_entity

テーブルにエンティティを更新/マージまたは挿入します。

close

このメソッドは、クライアントによって開かれたソケットを閉じる方法です。 コンテキスト マネージャーで を使用する場合は使用する必要はありません。

close() -> None

create_entity

テーブルにエンティティを挿入します。

create_entity(entity: TableEntity | Mapping[str, Any], **kwargs) -> Dict[str, Any]

パラメーター

entity
Union[TableEntity, Mapping[str, Any]]
必須

テーブル エンティティのプロパティ。

戻り値

サービスから返されるディクショナリ マッピング操作のメタデータ

の戻り値の型 :

例外

エンティティを作成してテーブルに追加する


   try:
       resp = table_client.create_entity(entity=self.entity)
       print(resp)
   except ResourceExistsError:
       print("Entity already exists")

create_table

現在のアカウントの下に新しいテーブルを作成します。

create_table(**kwargs) -> TableItem

戻り値

作成されたテーブルを表す TableItem。

の戻り値の型 :

例外

エンティティが既に存在する場合

TableClient オブジェクトからテーブルを作成する


   with TableClient.from_connection_string(
       conn_str=self.connection_string, table_name=self.table_name
   ) as table_client:
       try:
           table_item = table_client.create_table()
           print("Created table {}!".format(table_item.name))
       except ResourceExistsError:
           print("Table already exists")

delete_entity

テーブル内の指定したエンティティを削除します。 エンティティまたは PartitionKey-RowKey ペアリングが見つからない場合、エラーは発生しません。

delete_entity(partition_key: str, row_key: str, **kwargs) -> None

パラメーター

partition_key
str
必須

エンティティのパーティション キー。

row_key
str
必須

エンティティの行キー。

entity
Union[TableEntity, Mapping[str, str]]
必須

削除するエンティティ

etag
str

エンティティの Etag

match_condition
MatchConditions

操作を実行する条件。 サポートされる値には、MatchConditions.IfNotModified、MatchConditions.無条件が含まれます。 既定値は無条件です。

戻り値

なし

例外

テーブルのエンティティの削除


   table_client.delete_entity(row_key=self.entity["RowKey"], partition_key=self.entity["PartitionKey"])
   print("Successfully deleted!")

delete_table

現在のアカウントのテーブルを削除します。 テーブルが存在しない場合、エラーは発生しません

delete_table(**kwargs) -> None

戻り値

なし

例外

TableClient オブジェクトからテーブルを削除する


   with TableClient.from_connection_string(
       conn_str=self.connection_string, table_name=self.table_name
   ) as table_client:
       table_client.delete_table()
       print("Deleted table {}!".format(table_client.table_name))

from_connection_string

接続文字列から TableClient を作成します。

from_connection_string(conn_str: str, table_name: str, **kwargs) -> TableClient

パラメーター

conn_str
str
必須

Azure Tables アカウントへの接続文字列。

table_name
str
必須

テーブル名。

戻り値

テーブル クライアント。

の戻り値の型 :

connection_stringから TableServiceClient を認証する


   from azure.data.tables import TableClient

   with TableClient.from_connection_string(
       conn_str=self.connection_string, table_name="tableName"
   ) as table_client:
       print("Table name: {}".format(table_client.table_name))

from_table_url

特定のテーブルと対話するクライアント。

AzureSasCredential (azure-core)、または azure-identity からの TokenCredential 実装。 :p aramtype 資格情報:

~azure.core.credentials.AzureNamedKeyCredential または ~azure.core.credentials.AzureSasCredential または None

from_table_url(table_url: str, *, credential: AzureNamedKeyCredential | AzureSasCredential | None = None, **kwargs) -> TableClient

パラメーター

table_url
必須

戻り値

テーブル クライアント。

の戻り値の型 :

get_entity

テーブル内の 1 つのエンティティを取得します。

get_entity(partition_key: str, row_key: str, **kwargs) -> TableEntity

パラメーター

partition_key
str
必須

エンティティのパーティション キー。

row_key
str
必須

エンティティの行キー。

select
str または list[str]

返すエンティティの必要なプロパティを指定します。

戻り値

サービスから返されるディクショナリ マッピング操作のメタデータ

の戻り値の型 :

例外

テーブルから 1 つのエンティティを取得する


   # Get Entity by partition and row key
   got_entity = table.get_entity(partition_key=my_entity["PartitionKey"], row_key=my_entity["RowKey"])
   print("Received entity: {}".format(got_entity))

get_table_access_policy

Shared Access Signature で使用できるテーブルで指定された格納されているアクセス ポリシーに関する詳細を取得します。

get_table_access_policy(**kwargs) -> Dict[str, TableAccessPolicy | None]

戻り値

SignedIdentifiers の辞書

の戻り値の型 :

例外

list_entities

テーブル内のエンティティを一覧表示します。

list_entities(**kwargs) -> ItemPaged[TableEntity]

パラメーター

results_per_page
int

サービス要求ごとに返されるエンティティの数。

select
str または list[str]

返すエンティティの必要なプロパティを指定します。

戻り値

の反復子 TableEntity

の戻り値の型 :

例外

テーブル内に保持されているすべてのエンティティを一覧表示する


   # Query the entities in the table
   entities = list(table.list_entities())
   for i, entity in enumerate(entities):
       print("Entity #{}: {}".format(entity, i))

query_entities

テーブル内のエンティティを一覧表示します。

query_entities(query_filter: str, **kwargs) -> ItemPaged[TableEntity]

パラメーター

query_filter
str
必須

特定のエンティティを返すフィルターを指定します。 フィルターの書式設定の詳細については、 サンプルドキュメントを参照してください。

results_per_page
int

サービス要求ごとに返されるエンティティの数。

select
str または list[str]

返すエンティティの必要なプロパティを指定します。

parameters
dict[str, Any]

追加のユーザー定義パラメーターを使用してクエリを書式設定するためのディクショナリ

戻り値

の反復子 TableEntity

の戻り値の型 :

例外

テーブル内に保持されているクエリ エンティティ


   with TableClient.from_connection_string(self.connection_string, self.table_name) as table_client:
       try:
           print("Basic sample:")
           print("Entities with name: marker")
           parameters = {"name": "marker"}
           name_filter = "Name eq @name"
           queried_entities = table_client.query_entities(
               query_filter=name_filter, select=["Brand", "Color"], parameters=parameters
           )

           for entity_chosen in queried_entities:
               print(entity_chosen)

           print("Sample for querying entities withtout metadata:")
           print("Entities with name: marker")
           parameters = {"name": "marker"}
           name_filter = "Name eq @name"
           headers = {"Accept": "application/json;odata=nometadata"}
           queried_entities = table_client.query_entities(
               query_filter=name_filter, select=["Brand", "Color"], parameters=parameters, headers=headers
           )
           for entity_chosen in queried_entities:
               print(entity_chosen)

           print("Sample for querying entities with multiple params:")
           print("Entities with name: marker and brand: Crayola")
           parameters = {"name": "marker", "brand": "Crayola"}
           name_filter = "Name eq @name and Brand eq @brand"
           queried_entities = table_client.query_entities(
               query_filter=name_filter, select=["Brand", "Color"], parameters=parameters
           )
           for entity_chosen in queried_entities:
               print(entity_chosen)

           print("Sample for querying entities' values:")
           print("Entities with 25 < Value < 50")
           parameters = {"lower": 25, "upper": 50}  # type: ignore
           name_filter = "Value gt @lower and Value lt @upper"
           queried_entities = table_client.query_entities(
               query_filter=name_filter, select=["Value"], parameters=parameters
           )
           for entity_chosen in queried_entities:
               print(entity_chosen)
       except HttpResponseError as e:
           raise

set_table_access_policy

Shared Access Signature で使用できるテーブルの格納されているアクセス ポリシーを設定します。

set_table_access_policy(signed_identifiers: Dict[str, TableAccessPolicy | None], **kwargs) -> None

パラメーター

signed_identifiers
dict[str, TableAccessPolicy] または dict[str, None]
必須

テーブルに対して設定するアクセス ポリシー

戻り値

なし

例外

submit_transaction

操作の一覧を 1 つのトランザクションとしてコミットします。

これらの操作のいずれかが失敗した場合、トランザクション全体が拒否されます。

submit_transaction(operations: Iterable[Tuple[TransactionOperation | str, TableEntity | Mapping[str, Any]] | Tuple[TransactionOperation | str, TableEntity | Mapping[str, Any], Mapping[str, Any]]], **kwargs) -> List[Mapping[str, Any]]

パラメーター

operations
Iterable[Tuple[str, TableEntity, Mapping[str, Any]]]
必須

トランザクションでコミットする操作の一覧。 これは、操作名、操作対象のエンティティ、および必要に応じて、その操作に対する追加の kwargs のディクトを含むタプルのイテラーブルである必要があります。 次に例を示します。


   - ('upsert', {'PartitionKey': 'A', 'RowKey': 'B'})
   - ('upsert', {'PartitionKey': 'A', 'RowKey': 'B'}, {'mode': UpdateMode.REPLACE})

戻り値

トランザクション内の各操作の応答メタデータを含むマッピングの一覧。

の戻り値の型 :

例外

トランザクションを使用して複数の要求を一度に送信する


   from azure.data.tables import TableClient, TableTransactionError
   from azure.core.exceptions import ResourceExistsError

   self.table_client = TableClient.from_connection_string(
       conn_str=self.connection_string, table_name=self.table_name
   )

   try:
       self.table_client.create_table()
       print("Created table")
   except ResourceExistsError:
       print("Table already exists")

   self.table_client.upsert_entity(entity2)
   self.table_client.upsert_entity(entity3)
   self.table_client.upsert_entity(entity4)

   operations = [
       ("upsert", entity1),
       ("delete", entity2),
       ("upsert", entity3),
       ("update", entity4, {"mode": "replace"}),
   ]
   try:
       self.table_client.submit_transaction(operations)  # type: ignore[arg-type]
   except TableTransactionError as e:
       print("There was an error with the transaction operation")
       print(e)

update_entity

テーブル内のエンティティを更新します。

update_entity(entity: TableEntity | Mapping[str, Any], mode: UpdateMode = UpdateMode.MERGE, **kwargs) -> Dict[str, Any]

パラメーター

entity
TableEntity または dict[str, Any]
必須

テーブル エンティティのプロパティ。

mode
UpdateMode
必須

エンティティのマージまたは置換

etag
str

エンティティの Etag

match_condition
MatchConditions

操作を実行する条件。 サポートされる値には、MatchConditions.IfNotModified、MatchConditions.無条件が含まれます。 既定値は無条件です。

戻り値

サービスから返されるディクショナリ マッピング操作のメタデータ

の戻り値の型 :

例外

Table で既に終了しているエンティティを更新する


   # Update the entity
   created["text"] = "NewMarker"
   table.update_entity(mode=UpdateMode.REPLACE, entity=created)

   # Get the replaced entity
   replaced = table.get_entity(partition_key=created["PartitionKey"], row_key=created["RowKey"])
   print("Replaced entity: {}".format(replaced))

   # Merge the entity
   replaced["color"] = "Blue"
   table.update_entity(mode=UpdateMode.MERGE, entity=replaced)

   # Get the merged entity
   merged = table.get_entity(partition_key=replaced["PartitionKey"], row_key=replaced["RowKey"])
   print("Merged entity: {}".format(merged))

upsert_entity

テーブルにエンティティを更新/マージまたは挿入します。

upsert_entity(entity: TableEntity | Mapping[str, Any], mode: UpdateMode = UpdateMode.MERGE, **kwargs) -> Dict[str, Any]

パラメーター

entity
TableEntity または dict[str, Any]
必須

テーブル エンティティのプロパティ。

mode
UpdateMode
必須

エンティティのマージまたは置換

戻り値

サービスから返されるディクショナリ マッピング操作のメタデータ

の戻り値の型 :

例外

エンティティをテーブルに更新/マージまたは挿入する


   # Try Replace and insert on fail
   insert_entity = table.upsert_entity(mode=UpdateMode.REPLACE, entity=entity1)
   print("Inserted entity: {}".format(insert_entity))

   created["text"] = "NewMarker"
   merged_entity = table.upsert_entity(mode=UpdateMode.MERGE, entity=entity)
   print("Merged entity: {}".format(merged_entity))

属性

api_version

要求に使用される Storage API のバージョン。

戻り値

Storage API のバージョン。

url

SAS トークン (使用されている場合) を含む、このエンティティへの完全なエンドポイント URL。

これは、現在 <xref:azure.data.tables.location_mode>の に応じて、プライマリ エンドポイントまたはセカンダリ エンドポイントのいずれかになります。

戻り値

SAS トークンを含む完全なエンドポイント URL (使用されている場合)。

の戻り値の型 :

str