Skip to content

Commit

Permalink
Merge pull request #2 from seankane-msft/update-readme
Browse files Browse the repository at this point in the history
Update readme
  • Loading branch information
seankane-msft authored Aug 24, 2020
2 parents b8a7d0a + 6e986a9 commit 4083729
Showing 1 changed file with 91 additions and 46 deletions.
137 changes: 91 additions & 46 deletions sdk/tables/azure-data-tables/README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,50 @@
# Azure Data Tables client library for Python

Azure Data Tables is a NoSQL data storing service that can be accessed from anywhere in the world via authenticated calls using HTTP or HTTPS.
Tables scale as needed to support the amount of data inserted, and allow for the storing of data with non-complex accessing.
Tables scale as needed to support the amount of data inserted, and allow for the storing of data with non-complex accessing.
Azure Data Tables is a NoSQL data storing service that can be accessed from anywhere in the world via authenticated calls using HTTP or HTTPS.
Tables scales as needed to support the amount of data inserted, and allow for the storing of data with non-complex accessing.
The Azure Data Tables client can be used to access Azure Storage or Cosmos accounts.

Common uses of Azure Data Tables include:

* Storing structured data in the form of tables
* Quickly querying data using a clustered index

[Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk) | [Package (PyPI)](https://pypi.org) | [API reference documentation](https://aka.ms/azsdk/python/tables/docs) | [Product documentation](https://docs.microsoft.com/azure/storage/) | [Samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk)
[Source code](source_code) | [Package (PyPI)](Tables_pypi) | [API reference documentation](Tables_ref_docs) | [Product documentation](Tables_product_doc) | [Samples](Tables_samples)

## Getting started

### Prerequisites
* Python 2.7, or 3.5 or later is required to use this package.
* You must have an [Azure subscription](https://azure.microsoft.com/free/) and an
[Azure storage account](https://docs.microsoft.com/azure/storage/common/storage-account-overview) to use this package
or you must have a [Azure Cosmos Account](https://docs.microsoft.com/azure/cosmos-db/account-overview).
* You must have an [Azure subscription](azure_subscription) and an
[Azure storage account](azure_storage_account) to use this package
or an [Azure Cosmos Account](azure_cosmos_account).

### Install the package
Install the Azure Data Tables client library for Python with [pip](https://pypi.org/project/pip/):
Install the Azure Data Tables client library for Python with [pip](pip_link):

```bash
pip install --pre azure-data-tables
```

### Create a storage account
If you wish to create a new cosmos storage account, you can use the [Azure Cosmos DB](https://docs.microsoft.com/azure/cosmos-db/create-cosmosdb-resources-portal)
If you wish to create a new storage account, you can use the
[Azure Portal](https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-portal),
[Azure PowerShell](https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-powershell),
or [Azure CLI](https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-cli):
If you wish to create a new cosmos storage account, you can use [Azure Cosmos DB](azure_create_cosmos).
If you wish to create a new storage account, you can use [Azure Portal](azure_portal_create_account),
[Azure PowerShell](azure_powershell_create_account), or [Azure CLI](azure_cli_create_account):

```bash
# Create a new resource group to hold the storage account -
# if using an existing resource group, skip this step
az group create --name MyResourceGroup --location westus2

# Create the storage account
az storage account create -n mystorageaccount -g MyResourceGroup
az storage account create -n MyStorageAccount -g MyResourceGroup
```

### Create the client
The Azure Data Tables client library for Python allows you to interact with two types of resources: the
account and tables, and entities. Interaction with these resources starts with an instance of a [client](#clients).
To create a client object, you will need the account's table service endpoint URL and a credential that allows
you to access the account:
tables in your account, and the entities within the tables. Interaction with these resources starts with an
instance of a [client](#clients). To create a client object, you will need the account's table service
endpoint URL and a credential that allows you to access the account:

```python
from azure.data.tables import TableServiceClient
Expand All @@ -56,44 +53,44 @@ service = TableServiceClient(account_url="https://<myaccount>.table.core.windows
```

#### Looking up the account URL
You can find the account's table service URL using the
[Azure Portal](https://docs.microsoft.com/azure/storage/common/storage-account-overview#storage-account-endpoints),
[Azure PowerShell](https://docs.microsoft.com/powershell/module/az.storage/get-azstorageaccount),
or [Azure CLI](https://docs.microsoft.com/cli/azure/storage/account?view=azure-cli-latest#az-storage-account-show):
You can find the account's table service URL using the
[Azure Portal](azure_portal_account_url),
[Azure PowerShell](azure_powershell_account_url),
or [Azure CLI](azure_cli_account_url):

```bash
# Get the table service URL for the account
az storage account show -n mystorageaccount -g MyResourceGroup --query "primaryEndpoints.table"
az storage account show -n MyStorageAccount -g MyResourceGroup --query "primaryEndpoints.table"
```

#### Types of credentials
The `credential` parameter may be provided in a number of different forms, depending on the type of
[authorization](https://docs.microsoft.com/azure/storage/common/storage-auth) you wish to use:
1. To use a [shared access signature (SAS) token](https://docs.microsoft.com/azure/storage/common/storage-sas-overview),
[authorization](azure_authorization) you wish to use:
1. 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" or use one of the `generate_sas()`
functions to create a sas token for the account or table:

```python
from datetime import datetime, timedelta
from azure.data.tables import TableServiceClient, generate_account_sas, ResourceTypes, AccountSasPermissions

sas_token = generate_account_sas(
account_name="<account-name>",
account_key="<account-access-key>",
resource_types=ResourceTypes(service=True),
permission=AccountSasPermissions(read=True),
expiry=datetime.utcnow() + timedelta(hours=1)
)

table_service_client = TableServiceClient(account_url="https://<my_account_name>.table.core.windows.net", credential=sas_token)
```

2. To use an account [shared key](https://docs.microsoft.com/rest/api/storageservices/authenticate-with-shared-key/)
(aka account key or access key), provide the key as a string. This can be found in the Azure Portal under the "Access Keys"
2. To use an account [shared key](azure_shared_key)
(aka account key or access key), provide the key as a string. This can be found in the Azure Portal under the "Access Keys"
section or by running the following Azure CLI command:

```az storage account keys list -g MyResourceGroup -n mystorageaccount```
```az storage account keys list -g MyResourceGroup -n MyStorageAccount```

Use the key as the credential parameter to authenticate the client:
```python
Expand All @@ -103,7 +100,7 @@ The `credential` parameter may be provided in a number of different forms, depen

#### Creating the client from a connection string
Depending on your use case and authorization method, you may prefer to initialize a client instance with a
connection string instead of providing the account URL and credential separately. To do this, pass the
connection string instead of providing the account URL and credential separately. To do this, pass the
connection string to the client's `from_connection_string` class method:

```python
Expand All @@ -116,7 +113,7 @@ service = TableServiceClient.from_connection_string(conn_str=connection_string)
The connection string to your account can be found in the Azure Portal under the "Access Keys" section or by running the following CLI command:

```bash
az storage account show-connection-string -g MyResourceGroup -n mystorageaccount
az storage account show-connection-string -g MyResourceGroup -n MyStorageAccount
```

## Key concepts
Expand All @@ -130,23 +127,23 @@ use of a dedicated client object.

### Clients
Two different clients are provided to to interact with the various components of the Table Service:
1. [TableServiceClient](https://aka.ms/azsdk/python/tables/docs) -
1. [TableServiceClient](table_service_client_docs) -
this client represents interaction with the Azure account itself, and allows you to acquire preconfigured
client instances to access the tables within. It provides operations to retrieve and configure the account
properties as well as query, create, and delete tables within the account. To perform operations on a specific table,
retrieve a client using the `get_table_client` method.
2. [TableClient](https://aka.ms/azsdk/python/tables/docs) -
2. [TableClient](table_client_docs) -
this client represents interaction with a specific table (which need not exist yet). It provides operations to
create, delete, or update a table and includes operations to query, get, and upsert entities
within it.

### Entities
* **Create** - Adds an entity to the table.
* **Delete** - Deletes an entity from the table.
* **Update** - Updates an entities information by either merging or replacing the existing entity.
* **Query** - Queries existing entities in a table based off of the QueryOptions (OData).
* **Get** - Gets a specific entity from a table by partition and row key.
* **Upsert** - Merges or replaces an entity in a table, or if the entity does not exist, inserts the entity.
* **Upsert** - Merges or replaces an entity in a table, or if the entity does not exist, inserts the entity.

## Examples

Expand Down Expand Up @@ -193,7 +190,7 @@ entity = table_client.query_entities(filter=my_filter)

## Optional Configuration

Optional keyword arguments can be passed in at the client and per-operation level. The azure-core [reference documentation](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-core/latest/azure.core.html) describes available configurations for retries, logging, transport protocols, and more.
Optional keyword arguments can be passed in at the client and per-operation level. The azure-core [reference documentation](azure_core_ref_docs) describes available configurations for retries, logging, transport protocols, and more.


### Retry Policy configuration
Expand Down Expand Up @@ -231,12 +228,12 @@ the client level to enable it for all requests.

## Troubleshooting
### General
Azure Data Tables clients raise exceptions defined in [Azure Core](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/core/azure-core/README.md).
All Table service operations will throw a `HttpResponseError` on failure with helpful [error codes](https://docs.microsoft.com/rest/api/storageservices/table-service-error-codes).
Azure Data Tables clients raise exceptions defined in [Azure Core](azure_core_readme).
All Table service operations will throw a `HttpResponseError` on failure with helpful [error codes](tables_error_codes).

### Logging
This library uses the standard
[logging](https://docs.python.org/3/library/logging.html) library for logging.
[logging](python_logging) library for logging.
Basic information about HTTP sessions (URLs, headers, etc.) is logged at INFO
level.

Expand Down Expand Up @@ -267,33 +264,81 @@ service_client.get_service_stats(logging_enable=True)

## Next steps

Get started with our [Table samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk).
Get started with our [Table samples](tables_samples).

Several Azure Data Tables Python SDK samples are available to you in the SDK's GitHub repository. These samples provide example code for additional scenarios commonly encountered while working with Tables:

* [table_samples_authentication.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk) - Examples found in this article:
* [table_samples_authentication.py](samples_authentication) - Examples found in this article:
* From a connection string
* From a shared access key
* From a shared access signature token
* [table_samples_service.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk) - Examples found in this article:
* [table_samples_service.py](samples_services) - Examples found in this article:
* Get and set service properties
* List tables in a account
* Create and delete a table from the service
* Get the TableClient
* [table_samples_client.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk) - Examples found in this article:
* [table_samples_client.py](samples_client) - Examples found in this article:
* Client creation
* Create a table
* Create and Delete entities
* Query entities
* Update entities
* Upsert entities

### Additional documentation
For more extensive documentation on Azure Data Tables, see the [Azure Data Tables documentation](https://docs.microsoft.com/azure/storage/tables/) on docs.microsoft.com.
For more extensive documentation on Azure Data Tables, see the [Azure Data Tables documentation](Tables_product_doc) on docs.microsoft.com.

## Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
This project has adopted the [Microsoft Open Source Code of Conduct](msft_oss_coc). For more information see the [Code of Conduct FAQ](msft_oss_coc_faq) or contact [opencode@microsoft.com](contact_msft_oss) with any additional questions or comments.

<!-- LINKS -->
[source_code]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/azure/data/table
<!-- Still needed -->
[Tables_pypi]: https://pypi.org/project/azure-data-tables
[Tables_ref_docs]: https://aka.ms/azsdk/python/tables/docs
[Tables_product_doc]: https://docs.microsoft.com/azure/storage/
[Tables_samples]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/tables/azure-data-tables/samples

[azure_subscription]: https://azure.microsoft.com/free/
[azure_storage_account]: https://azure.microsoft.com/free/
[azure_cosmos_account]: https://docs.microsoft.com/azure/cosmos-db/account-overview
[pip_link]: https://pypi.org/project/pip/

[azure_create_cosmos]: https://docs.microsoft.com/azure/cosmos-db/create-cosmosdb-resources-portal
[azure_portal_create_account]: https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-portal
[azure_powershell_create_account]: https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-powershell
[azure_cli_create_account]: https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-cli

[azure_cli_account_url]:https://docs.microsoft.com/cli/azure/storage/account?view=azure-cli-latest#az-storage-account-show
[azure_powershell_account_url]:https://docs.microsoft.com/powershell/module/az.storage/get-azstorageaccount
[azure_portal_account_url]:https://docs.microsoft.com/azure/storage/common/storage-account-overview#storage-account-endpoints

[azure_authorization]: https://docs.microsoft.com/azure/storage/common/storage-auth
[azure_sas_token]: https://docs.microsoft.com/azure/storage/common/storage-sas-overview
[azure_shared_key]: https://docs.microsoft.com/rest/api/storageservices/authenticate-with-shared-key/

<!-- Still needed -->
[table_service_client_docs]: https://aka.ms/azsdk/python/tables/docs
<!-- Still needed -->
[table_client_docs]: https://aka.ms/azsdk/python/tables/docs

[azure_core_ref_docs]: https://azuresdkdocs.blob.core.windows.net/$web/python/azure-core/latest/azure.core.html
[azure_core_readme]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/core/azure-core/README.md

[python_logging]: https://docs.python.org/3/library/logging.html
[tables_error_codes]: https://docs.microsoft.com/rest/api/storageservices/table-service-error-codes

<!-- Still needed -->
[samples_authentication]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/tables/azure-data-tables/samples/table_samples_authentication.py
<!-- Still needed -->
[samples_services]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/tables/azure-data-tables/samples/table_samples_authentication.py
<!-- Still needed -->
[samples_client]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/tables/azure-data-tables/samples/table_samples_client.py

[msft_oss_coc]:https://opensource.microsoft.com/codeofconduct/
[msft_oss_coc_faq]:https://opensource.microsoft.com/codeofconduct/faq/
[contact_msft_oss]:mailto:opencode@microsoft.com

0 comments on commit 4083729

Please sign in to comment.