azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

Azure Table storage support questions

Open twentytwokhz opened this issue 7 years ago • 2 comments

I'm really confused right now with all the changes. Can you please clear some things for me? What is the recommended package to be used now for table storage within azure functions? Note: I'm not referring to table storage bindings which I'm familiar with. Side note: this is related to the idea of retrieving data from an azure table storage inside an azure function. I'm doing this since I cannot control the amount of data being retrieved by using a table binding - aka, all data inside the given function.json partition is retrieve. I want to be able to do that dynamically. Does that make sense?

twentytwokhz avatar Jul 18 '19 16:07 twentytwokhz

Hi @twentytwokhz ! Sorry this issue was lost, and only found today. I took some time to work with the new Azure Table Storage library (currently in preview release here) and verify that you can use this library from within an Azure Function. I used these two guides to create my function:

  1. https://docs.microsoft.com/en-us/azure/azure-functions/create-first-function-cli-python?tabs=azure-cli%2Cpowershell%2Cbrowser - Tutorial on how to create and write the function
  2. https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python - Explains what each file is, you'll need to add azure-data-tables to the requirements.txt file.

Here is a snippet of what my code looks like:

import logging

import azure.functions as func
from azure.data.tables import TableServiceClient, TableClient

conn_str = <my_conn_str>

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    tsc = TableServiceClient.from_connection_string(conn_str)
    tsc.create_table_if_not_exists("sample")

    tc = TableClient.from_connection_string(conn_str, table_name="sample")

    entity = {
        "PartitionKey": "pk",
        "RowKey": "rk001",
        "Value": 10,
        "Value2": "10"
    }

    try:
        resp = tc.create_entity(entity)
        print(resp)
    except Exception as e:
        print(e)
    return "success"

Let me know if you have any other questions!

seankane-msft avatar Nov 23 '20 21:11 seankane-msft

Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

ghost avatar Dec 01 '20 02:12 ghost