Skip to content

Commit b723f04

Browse files
[Tables] fixing readme (Azure#19179)
1 parent e8b6637 commit b723f04

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

sdk/tables/azure-data-tables/README.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The Azure Data Tables SDK can access an Azure Storage or CosmosDB account.
2222
### Install the package
2323
Install the Azure Data Tables client library for Python with [pip][pip_link]:
2424
```bash
25-
pip install --pre azure-data-tables
25+
pip install azure-data-tables
2626
```
2727

2828
#### Create the client
@@ -59,8 +59,12 @@ az storage account keys list -g MyResourceGroup -n MyStorageAccount
5959

6060
Use the key as the credential parameter to authenticate the client:
6161
```python
62-
from azure.data.tables import TableServiceClient
63-
service = TableServiceClient(endpoint="https://<my_account_name>.table.core.windows.net", credential="<account_access_key>")
62+
from azure.core.credentials import AzureNamedKeyCredential
63+
from azure.data.tables import TableServiceClient
64+
65+
credential = AzureNamedKeyCredential("my_account_name", "my_access_key")
66+
67+
service = TableServiceClient(endpoint="https://<my_account_name>.table.core.windows.net", credential=credential)
6468
```
6569

6670
##### Creating the client from a connection string
@@ -72,28 +76,29 @@ az storage account show-connection-string -g MyResourceGroup -n MyStorageAccount
7276
```
7377

7478
```python
75-
from azure.data.tables import TableServiceClient
76-
connection_string = "DefaultEndpointsProtocol=https;AccountName=<my_account_name>;AccountKey=<my_account_key>;EndpointSuffix=core.windows.net"
77-
service = TableServiceClient.from_connection_string(conn_str=connection_string)
79+
from azure.data.tables import TableServiceClient
80+
connection_string = "DefaultEndpointsProtocol=https;AccountName=<my_account_name>;AccountKey=<my_account_key>;EndpointSuffix=core.windows.net"
81+
service = TableServiceClient.from_connection_string(conn_str=connection_string)
7882
```
7983

8084
##### Creating the client from a SAS token
8185
To use a [shared access signature (SAS) token][azure_sas_token], provide the token as a string. If your account URL includes the SAS token, omit the credential parameter. You can generate a SAS token from the Azure Portal under [Shared access signature](https://docs.microsoft.com/rest/api/storageservices/create-service-sas) or use one of the `generate_*_sas()`
8286
functions to create a sas token for the account or table:
8387

8488
```python
85-
from datetime import datetime, timedelta
86-
from azure.data.tables import TableServiceClient, generate_account_sas, ResourceTypes, AccountSasPermissions
87-
88-
sas_token = generate_account_sas(
89-
account_name="<account-name>",
90-
account_key="<account-access-key>",
91-
resource_types=ResourceTypes(service=True),
92-
permission=AccountSasPermissions(read=True),
93-
expiry=datetime.utcnow() + timedelta(hours=1)
94-
)
95-
96-
table_service_client = TableServiceClient(endpoint="https://<my_account_name>.table.core.windows.net", credential=sas_token)
89+
from datetime import datetime, timedelta
90+
from azure.data.tables import TableServiceClient, generate_account_sas, ResourceTypes, AccountSasPermissions
91+
from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential
92+
93+
credential = AzureNamedKeyCredential("my_account_name", "my_access_key")
94+
sas_token = generate_account_sas(
95+
credential,
96+
resource_types=ResourceTypes(service=True),
97+
permission=AccountSasPermissions(read=True),
98+
expiry=datetime.utcnow() + timedelta(hours=1),
99+
)
100+
101+
table_service_client = TableServiceClient(endpoint="https://<my_account_name>.table.core.windows.net", credential=AzureSasCredential(sas_token))
97102
```
98103

99104

0 commit comments

Comments
 (0)