Storage I / O notes in Python with Azure Functions

Introduction

Azure Functions supports the Python runtime. However, I couldn't find a way to trigger the input to the storage → Functions processing → Output to the storage, so I will make a note as a memorandum.

procedure

  1. Describe the information of Azure storage to bind.

json:local.settings.json


{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=<Storage account>;AccountKey=<Account key>;EndpointSuffix=core.windows.net"
  }
}
  1. Enter the input source and output destination paths.

function.json


{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "inputblob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "container/input/{name}",
      "connection": ""
    },
    {
      "name": "outputblob",
      "type": "blob",
      "direction": "out",
      "path": "container/output/{name}.csv",
      "connection": ""
    }
  ]
}
  1. Write the process in a Python script.

__init__.py


def main(inputblob: func.InputStream, outputblob: func.Out[str]):
    logging.info(f"Python blob trigger function processed blob. v2.0\n"
                 f"Name: {inputblob.name}\n"
                 f"Blob Size: {inputblob.length} bytes\n")

    input_text = inputblob.read(size=-1).decode("utf-8")
    #What you want to do
    output_text = input_text += "hoge"

    outputblob.set(output_text)

This will output the file to the path "container / output / {name} .csv" set in 2. In this case, the file name will be the input file name with ".csv" at the end.

Recommended Posts

Storage I / O notes in Python with Azure Functions
[Azure Functions / Python] Chain functions with Queue Storage binding
Use Python and MeCab with Azure Functions
I tried non-blocking I / O Eventlet behavior in Python
Basics of I / O screen using tkinter in python3
I was addicted to scraping with Selenium (+ Python) in 2020
I want to work with a robot in python.
I tried scraping with Python
Getting Started with Python Functions
I wrote python in Japanese
Scraping with selenium in Python
Working with LibreOffice in Python
Web scraping notes in python3
Scraping with chromedriver in python
Debugging with pdb in Python
I made blackjack with python!
Working with sounds in Python
Scraping with Selenium in Python
Overriding library functions in Python
Scraping with Tor in Python
Tweet with image in Python
Combined with permutations in Python
I tried gRPC with Python
I tried scraping with python
I understand Python in Japanese!
Get Evernote notes in Python
I made blackjack with Python.
What I learned in Python
Python functions learned in chemoinformatics
I made wordcloud with Python.
I made a simple typing game with tkinter in Python
Tips for developing apps with Azure Cosmos DB in Python
How to specify Cache-Control for blob storage in Azure Storage in Python
I made a puzzle game (like) with Tkinter in Python
Number recognition in images with Python
Azure Functions: Try Durable Functions for Python
Testing with random numbers in Python
[python] Manage functions in a list
GOTO in Python with Sublime Text 3
Working with LibreOffice in Python: import
I can't install python3 with pyenv-vertualenv
CSS parsing with cssutils in Python
I want to solve APG4b with Python (only 4.01 and 4.04 in Chapter 4)
I tried web scraping with python.
What I was addicted to with json.dumps in Python base64 encoding
Numer0n with items made in Python
Open UTF-8 with BOM in Python
I made a fortune with Python.
I sent an SMS with Python
Use rospy with virtualenv in Python3
I wrote Fizz Buzz in Python
Using global variables in python functions
10 functions of "language with battery" python
Use Python in pyenv with NeoVim
Use Azure Blob Storage from Python
I learned about processes in Python
I played with PyQt5 and Python3
Heatmap with Dendrogram in Python + matplotlib
Read files in parallel with Python
I wrote the queue in Python
Notes on using rstrip with python.