Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
page_type languages products urlFragment
sample
python
azure
azure-table-storage
tables-samples

Samples for Azure Tables client library for Python

These code samples show common scenario operations with the Azure Data Tables client library.

You can authenticate your client with a Tables API key:

These sample programs show common scenarios for the Tables client's offerings.

File Name Description
sample_create_client.py and sample_create_client_async.py Instantiate a table client
sample_create_delete_table.py and sample_create_delete_table_async.py Creating and deleting a table in a storage account
sample_insert_delete_entities.py and sample_insert_delete_entities_async.py Inserting and deleting individual entities in a table
sample_query_tables.py and sample_query_tables_async.py Querying tables in a storage account
sample_update_upsert_merge_entities.py and sample_update_upsert_merge_entities_async.py Updating, upserting, and merging entities
sample_batching.py and sample_batching_async.py Committing many requests in a single batch
sample_copy_table.py and sample_copy_table_async.py Copying a table between Tables table and Storage blob
sample_get_entity_etag_and_timestamp.py and sample_get_entity_etag_and_timestamp_async.py Getting entity's etag and timestamp

Prerequisites

Setup

  1. Install the Azure Data Tables client library for Python with pip:
pip install --pre azure-data-tables
  1. Clone or download this sample repository
  2. Open the sample folder in Visual Studio Code or your IDE of choice.

Running the samples

  1. Open a terminal window and cd to the directory that the samples are saved in.
  2. Set the environment variables specified in the sample file you wish to run.
  3. Follow the usage described in the file, e.g. python sample_create_table.py

Writing Filters

Supported Comparison Operators

Operator URI expression
Equal eq
GreaterThan gt
GreaterThanOrEqual ge
LessThan lt
LessThanOrEqual le
NotEqual ne
And and
Not not
Or or

Formatting and quote characters

Query strings must wrap literal values in single quotes. Literal values containing single quote characters must be escaped with a double single quote.

query_filter = "LastName eq 'O''Connor' and CustomerSince eq datetime'2008-07-10T00:00:00Z'"
table_client.query_entities(query_filter)

Query strings can also be parameterized using a dictionary of values, which will be automatically formatted with single quotes according to data type. When using the parameter dictionary to format filters, any single quote characters in the values will be automatically escaped.

parameters = {
    "last_name": "O'Connor",
    "customer_since": datetime(year=2008, month=7, day=10)
}
query_filter = "LastName eq @last_name and CustomerSince eq @customer_since"
table_client.query_entities(query_filter, parameters=parameters)

For more information on formatting and supported characters, please see the query reference documentation.

Example Filters

Filter on PartitionKey and RowKey:

parameters = {
    "pk": PartitionKey,
    "rk": RowKey
}
query_filter = "PartitionKey eq @pk and RowKey eq @rk"
table_client.query_entities(query_filter, parameters=parameters)

Filter on Properties

parameters = {
    "first": first_name,
    "last": last_name
}
query_filter = "FirstName eq @first or LastName eq @last"
table_client.query_entities(query_filter, parameters=parameters)

Filter with string comparison operators

query_filter = "LastName ge 'A' and LastName lt 'B'"
table_client.query_entities(query_filter)

Filter with numeric properties

query_filter = "Age gt 30"
table_client.query_entities(query_filter)
query_filter = "AmountDue le 100.25"
table_client.query_entities(query_filter)

Filter with boolean properties

query_filter = "IsActive eq true"
table_client.query_entities(query_filter)

Filter with DateTime properties

query_filter = "CustomerSince eq datetime'2008-07-10T00:00:00Z'"
table_client.query_entities(query_filter)

Filter with GUID properties

query_filter = "GuidValue eq guid'a455c695-df98-5678-aaaa-81d3367e5a34'"
table_client.query_entities(query_filter)

Next steps

Check out the API reference documentation to learn more about what you can do with the Azure Data Tables client library.