简体   繁体   English

使用 Python Azure 函数处理存储在 blob 存储中的 csv 文件

[英]Process csv file stored in blob storage using Python Azure functions

I have a csv file with 'n' number of records stored in blob storage.我有一个 csv 文件,其中存储在 blob 存储中的记录数为“n”。 I want to read the new records being added to the csv file, process it and stored it back to another container in the blob storage.我想读取添加到 csv 文件中的新记录,对其进行处理并将其存储回 blob 存储中的另一个容器。 I want to achieve this flow using Python Azure Functions.我想使用 Python Azure Functions 来实现这个流程。 I am unable to write the code for inbound and outbound in the Python Azure Functions.我无法在 Python Azure Functions 中编写入站和出站代码。

Please help.请帮忙。 Thanks谢谢

Below is the code that worked for me.下面是对我有用的代码。 I'm using HTTP Trigger to achieve your requirement.我正在使用 HTTP 触发器来满足您的要求。

function.json函数.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "blob",
      "direction":"in",
      "name": "inputblob",
      "path": "input/input.csv",
      "connection": "storageacc_STORAGE"
    },
    {
      "type": "blob",
      "direction":"out",
      "name": "outputblob",
      "path": "output/output.csv",
      "connection": "storageacc_STORAGE"
    }
  ]
}

init .py初始化.py

import csv
import logging

import azure.functions as func


def main(req: func.HttpRequest, inputblob: func.InputStream,outputblob: func.Out[bytes]) -> func.InputStream:
    
    # Reading from the input binding
    input_file = inputblob.read()
    
    # Processing the csv file

    # Writing to output binding
    outputblob.set(input_file)    

local.settings.json local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "storageacc_STORAGE": "<Your_Connection_String>"
  }
}

RESULTS:结果:

在此处输入图像描述

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 python 创建 csv 文件并将其上传到 azure blob 存储 - Create and upload csv file to azure blob storage using python 如何使用日志分析工作区查询存储在 Azure Blob 存储中的 CSV 文件列? - How to query column of CSV file stored in Azure blob storage using log analytics workspace? 如何使用 Azure 函数从 Blob 存储中读取 json 文件 Python - How to read json file from blob storage using Azure Functions Blob Trigger with Python 使用 python 将文件上传到 azure blob 存储 - Uploading file to azure blob storage using python 如何在 Python 中使用 Azure Functions 的 Azure Blob 存储绑定将 JSON 数据上传到 Azure 存储 blob - How to upload JSON data to Azure storage blob using Azure Blob storage bindings for Azure Functions in Python 使用 python azure 函数从 azure blob 存储读取文件 - Read files from azure blob storage using python azure functions 无法使用 Azure 函数节点将文件上传到 Azure blob 存储 - Cannot upload file to Azure blob storage using Azure functions Node 打开存储在Azure Blob存储中的pdf文件(使用字节) - Open a pdf file(using bytes) stored in Azure Blob storage 使用 Python 从 azure blob 存储下载文件(csv、excel) - Download files (csv, excel) from azure blob storage using Python 使用pyspark从Azure Blob存储读取(txt,csv)文件 - Reading (txt , csv) FIle from Azure blob storage using pyspark
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM