--- title: "Python" slug: "cloudfunctions-example-python" tags: ["Cloud Functions examples", "Cloud Functions"] updated: 2026-09-17T09:18:17Z published: 2026-09-17T09:18:17Z canonical: "guide.ncloud-docs.com/cloudfunctions-example-python" --- > ## Documentation Index > Fetch the complete documentation index at: https://guide.ncloud-docs.com/llms.txt > Use this file to discover all available pages before exploring further. # Python Available in Classic and VPC This document describes how to create and use python actions in a variety of ways, and includes application examples. ## Create action A code written in python may contain multiple functions, but the main function must be declared as the starting point of a program. With this taken into account, the following is a simple example code hello in Python, printing Hello World along with a name and location. ``` def main(args): name = args.get("name", "World") place = args.get("place", "Naver") greeting = "Hello " + name + " in " + place + "!" print(greeting) return {"payload": greeting} ``` The following is the process of an action called "hello" in the console, using the code written above.  ## Create action by packaging with dependency files When writing codes, there are cases where dependency modules need to be packaged along with one action file. In this case, you can package related files into a single module and create an action using the packaged file. The `main` function, which is the entry point to access the function, must be defined within the __main__.py file. For example, to create an action by packaging together with the helper.py file where functions used by the main action are written, use the following command to compress the action-related files to helloPython.zip. ``` zip -r helloPython.zip __main__.py helper.py ``` You can then use the compressed file created to create the action. ### Create action by packaging with the virtual environment How to create actions by packaging with the virtual environment is explained for each OS environment. #### Linux & Mac To use additional libraries other than libraries provided by Cloud Functions by default, you can use the virtual environment (virtualenv) and package them together. The main function must be defined in the __main__.py file in the same way as the packaging method supported by default, and virtualenv's folder name must be set as "virtualenv". The following is an example of building a virtual environment, and creating an action returning joke using the pyjokes library which is not provided by Cloud Functions. 1. Build a virtualenv environment with the name virtualenv. ``` virtualenv virtualenv source virtualenv/bin/activate pip install pyjokes ``` 2. Write code that calls the `get_joke()` method from __main__.py to return the joke. ``` import pyjokes def main(args): return {"joke": pyjokes.get_joke()} ``` 3. Compress the vendor folder and the __main__.py file together. ``` $ zip -r jokes.zip virtualenv __main__.py ``` 4. Use the compressed file created to create an action. Note The maximum size of an action source code of Cloud Functions is limited to 38 MB. Accordingly, deployment may be restricted if the file size exceeds the limited size due to the large number of libraries used. For the actions not frequently used, their container status may be switched to cold, leading to the increased initial action runtime. #### Windows Since in a Windows environment, it's difficult to support it in the same format as virtualenv in Linux or Mac environments, two packaging methods by building a virtual environment are explained. However, Python or pip must be installed in advance. - Packaging method using Docker: if the development environment allows the use of Docker, then you can create a package by simply configuring a development environment virtually. The packaging sequence is as follows: 1. Install the Docker for Windows(Community Edition) or the Docker Toolbox falling under for the operating system used. (See: [https://www.docker.com/docker-windows](https://www.docker.com/docker-windows)) 2. Write the source code __main__.py. ``` import pyjokes def main(args): return {"joke": pyjokes.get_joke()} ``` 3. Write the requirements.txt file. ``` pyjokes==0.5.0 ``` 4. Use the Docker command to create a ZIP file. - The working path is assumed to be c:\WorkingDir in the following file structure. powershell c:\WorkingDir>dir XXXX-XX-XX 09:07 PM