Azure Table Storage Tutorial - Python Azure Tables SDK with NBA Stats API
Published Jun 05 2023 11:24 AM 3,231 Views

The NBA playoffs start on 15 April following the conclusion of the Play-In Tournament on 14 April. In this tutorial, we use the nba_api Python API Client for to fetch NBA teams stats and then run the Python Azure Tables SDK to create Azure table and entries. Finally, with Azure Storage Explorer we can easily build search query and visualize the results.


To illustrate Azure Tables Python SDK usage using NBA API, followed by querying Azure Table Storage with Azure Storage Explorer's Query Builder.


For this example, you would need:

  • An Azure Table Storage


  1. Install nba_api
  2. Install Azure Tables client library for Python
  3. Python code to retrieve data, create table, and insert entries
  4. Run
  5. Visualize the NBA table (with Azure Storage Explorer)
  6. Sample query (with Azure Storage Explorer)


[STEP 1]: Install nba_api



pip install nba_api



[STEP 2]: Install Azure Tables client library for Python



pip install azure-data-tables



[STEP 3]: Python code to retrieve data, create table, and insert entries



  • replace STORAGE_CONNECTION_STRING with your storage connection string.
  • I use "state" as PartitionKey and "abbreviation" as RowKey.
  • This article describes best practice when choosing partition & row key for entities.
  • The response from calling teams.get_teams() is like the following:



      "full_name":"Atlanta Hawks",
      "full_name":"Boston Celtics",
      "full_name":"Cleveland Cavaliers",



from nba_api.stats.static import teams

# Retrieve Data

result = teams.get_teams()

print("- NBA Stats Retrieved")

# Create Table

from import TableServiceClient
table_service_client = TableServiceClient.from_connection_string(conn_str=STORAGE_CONNECTION_STRING)
table_name = "NBA"
table_client = table_service_client.create_table(table_name=table_name)

print("- Table created")

# Create Entity

from import TableServiceClient

for team in result:
    my_entity = {
        u'PartitionKey': team['state'],
        u'RowKey': team['abbreviation'],
        u'id': team['id'],
        u'city': team['city'],
        u'state': team['state'],
        u'nickname': team['nickname'],
        u'full_name': team['full_name'],
        u'year_founded': team['year_founded'],
        u'abbreviation': team['abbreviation']
    entity = table_client.create_entity(entity=my_entity)

print("- Entity created")



[STEP 4]: Run



PS C:\Users\xxxxxx> python .\
- NBA Stats Retrieved
- Table created
- Entity created




[STEP 5]: Visualize the NBA table (with Azure Storage Explorer)


The NBA table contains data of the 30 NBA teams with the following info:

  • ID
  • City Name
  • State Name
  • Nickname
  • Full Name
  • Year Founded
  • Abbreviation



[STEP 6]: Sample query (with Azure Storage Explorer)


Query Example: To find out all NBA teams that are based in California and were founded in 1948.


1. Click the "Query" button on the upper-left corner of the table.



2. Use Query Builder to build the query. Then click ▶ to execute.



3. Result is Lakers (LAL) & Kings (SAC).



This example shows how to use the nba_api to retrieve NBA teams stats and the Azure Tables Python SDK to work with Azure Table storage. The Azure Tables client library for Python provides a simple and intuitive API for working with Azure Table Storage, with methods for creating and managing table clients, table operations, and entities.




Version history
Last update:
‎Jun 05 2023 04:40 AM
Updated by: