TableServiceClient クラス

アカウント レベルで Table Service と対話するクライアント。

このクライアントは、アカウントのプロパティを取得および構成する操作と、アカウント内のテーブルの一覧表示、作成、削除を行う操作を提供します。 特定のテーブルに関連する操作の場合は、 関数を使用してこのエンティティのクライアントを get_table_client 取得できます。

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

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

コンストラクター

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

パラメーター

endpoint
str
必須

テーブル サービス エンドポイントの URL。 URL パス (テーブルなど) に含まれるその他のエンティティは破棄されます。 この URL は、必要に応じて SAS トークンを使用して認証できます。

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

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

api_version
str

要求に使用する Storage API バージョン。 既定値は '2019-02-02' です。 古いバージョンに設定すると、機能の互換性が低下する可能性があります。

endpoint
str
必須

Azure Tables アカウントの URL。

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

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

api_version
str または None

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

共有アクセス キーからの TableServiceClient の認証


   from azure.data.tables import TableServiceClient
   from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential

   # Create a SAS token to use for authentication of a client
   from azure.data.tables import generate_account_sas, ResourceTypes, AccountSasPermissions

   print("Account name: {}".format(self.account_name))
   credential = AzureNamedKeyCredential(self.account_name, self.access_key)  # type: ignore[arg-type]
   sas_token = generate_account_sas(
       credential,
       resource_types=ResourceTypes(service=True),
       permission=AccountSasPermissions(read=True),
       expiry=datetime.utcnow() + timedelta(hours=1),
   )

   with TableServiceClient(
       endpoint=self.endpoint, credential=AzureSasCredential(sas_token)
   ) as token_auth_table_service:
       properties = token_auth_table_service.get_service_properties()
       print("Shared Access Signature: {}".format(properties))

共有アカウント キーからの TableServiceClient の認証


   from azure.data.tables import TableServiceClient
   from azure.core.credentials import AzureNamedKeyCredential

   credential = AzureNamedKeyCredential(self.account_name, self.access_key)  # type: ignore[arg-type]
   with TableServiceClient(endpoint=self.endpoint, credential=credential) as table_service:
       properties = table_service.get_service_properties()
       print("Shared Key: {}".format(properties))

変数

account_name
str

Tables アカウントの名前。

url
str

Tables アカウントの完全な URL。

メソッド

close

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

create_table

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

create_table_if_not_exists

現在存在しない場合は、新しいテーブルを作成します。 テーブルが現在存在する場合は、現在のテーブルが返されます。

delete_table

現在のアカウントのテーブルを削除します。 指定されたテーブルが見つからない場合、エラーは発生しません。

from_connection_string

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

get_service_properties

Analytics および CORS (クロスオリジン リソース共有) ルールのプロパティを含む、アカウントのテーブル サービスのプロパティを取得します。

get_service_stats

Table Service のレプリケーションに関連する統計情報を取得します。 これは、アカウントに対して読み取りアクセス geo 冗長レプリケーションが有効になっている場合にのみ、セカンダリ ロケーション エンドポイントで使用できます。

get_table_client

指定したテーブルと対話するクライアントを取得します。

テーブルがまだ存在している必要はありません。

list_tables

指定されたアカウントのテーブルにクエリを実行します。

query_tables

指定されたアカウントのテーブルにクエリを実行します。

set_service_properties

Analytics および CORS (クロスオリジン リソース共有) ルールのプロパティを含む、アカウントの Table Service エンドポイントのプロパティを設定します。

close

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

close() -> None

create_table

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

create_table(table_name: str, **kwargs) -> TableClient

パラメーター

table_name
str
必須

テーブル名。

戻り値

TableClient

の戻り値の型 :

例外

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


   with TableServiceClient.from_connection_string(self.connection_string) as table_service_client:
       try:
           table_client = table_service_client.create_table(table_name=self.table_name)
           print("Created table {}!".format(table_client.table_name))
       except ResourceExistsError:
           print("Table already exists")

create_table_if_not_exists

現在存在しない場合は、新しいテーブルを作成します。 テーブルが現在存在する場合は、現在のテーブルが返されます。

create_table_if_not_exists(table_name: str, **kwargs) -> TableClient

パラメーター

table_name
str
必須

テーブル名。

戻り値

TableClient

の戻り値の型 :

例外

テーブルが存在しない場合は、TableServiceClient オブジェクトから作成する


   with TableServiceClient.from_connection_string(self.connection_string) as table_service_client:
       table_client = table_service_client.create_table_if_not_exists(table_name=self.table_name)
       print("Table name: {}".format(table_client.table_name))

delete_table

現在のアカウントのテーブルを削除します。 指定されたテーブルが見つからない場合、エラーは発生しません。

delete_table(table_name: str, **kwargs) -> None

パラメーター

table_name
str
必須

テーブル名。

戻り値

なし

例外

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


   with TableServiceClient.from_connection_string(self.connection_string) as table_service_client:
       table_service_client.delete_table(table_name=self.table_name)
       print("Deleted table {}!".format(self.table_name))

from_connection_string

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

from_connection_string(conn_str: str, **kwargs) -> TableServiceClient

パラメーター

conn_str
str
必須

Azure Storage または Cosmos アカウントへの接続文字列。

戻り値

Table service クライアント。

の戻り値の型 :

connection_stringから TableServiceClient を認証する


   from azure.data.tables import TableServiceClient

   with TableServiceClient.from_connection_string(conn_str=self.connection_string) as table_service:
       properties = table_service.get_service_properties()
       print("Connection String: {}".format(properties))

get_service_properties

Analytics および CORS (クロスオリジン リソース共有) ルールのプロパティを含む、アカウントのテーブル サービスのプロパティを取得します。

get_service_properties(**kwargs) -> Dict[str, object]

戻り値

サービス プロパティのディクショナリ

の戻り値の型 :

例外

get_service_stats

Table Service のレプリケーションに関連する統計情報を取得します。 これは、アカウントに対して読み取りアクセス geo 冗長レプリケーションが有効になっている場合にのみ、セカンダリ ロケーション エンドポイントで使用できます。

get_service_stats(**kwargs) -> Dict[str, object]

戻り値

サービス統計の辞書

の戻り値の型 :

例外

azure.core.exceptions.HttpResponseError:

get_table_client

指定したテーブルと対話するクライアントを取得します。

テーブルがまだ存在している必要はありません。

get_table_client(table_name: str, **kwargs) -> TableClient

パラメーター

table_name
str
必須

テーブル名

戻り値

TableClient オブジェクト。

の戻り値の型 :

list_tables

指定されたアカウントのテーブルにクエリを実行します。

list_tables(**kwargs) -> ItemPaged[TableItem]

パラメーター

results_per_page
int

返された ItemPaged の 1 ページあたりのテーブル数

戻り値

の反復子 TableItem

の戻り値の型 :

例外

ストレージ アカウント内のすべてのテーブルを一覧表示する


   # List all the tables in the service
   list_tables = table_service.list_tables()
   print("Listing tables:")
   for table in list_tables:
       print("\t{}".format(table.name))

query_tables

指定されたアカウントのテーブルにクエリを実行します。

query_tables(query_filter: str, **kwargs) -> ItemPaged[TableItem]

パラメーター

query_filter
str
必須

特定のテーブルを返すフィルターを指定します。

results_per_page
int

戻り値 ItemPaged の 1 ページあたりのテーブル数

parameters
dict[str, Any]

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

戻り値

の反復子 TableItem

の戻り値の型 :

例外

ストレージ アカウント内のテーブルのクエリ


   table_name = "mytable1"
   name_filter = "TableName eq '{}'".format(table_name)
   queried_tables = table_service.query_tables(name_filter)

   print("Queried_tables")
   for table in queried_tables:
       print("\t{}".format(table.name))

set_service_properties

Analytics および CORS (クロスオリジン リソース共有) ルールのプロパティを含む、アカウントの Table Service エンドポイントのプロパティを設定します。

set_service_properties(**kwargs) -> None

パラメーター

analytics_logging
TableAnalyticsLogging

分析のプロパティ

hour_metrics
TableMetrics

時間レベルのメトリック

minute_metrics
TableMetrics

分レベルのメトリック

cors
list[TableCorsRule]

クロスオリジン リソース共有ルール

戻り値

なし

例外

属性

api_version

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

戻り値

Storage API のバージョン。

url

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

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

戻り値

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

の戻り値の型 :

str