Create a virtual environment for your python function(s).
$ mkvirtualenv -a $PWD -p `which python3` py3cloundfunc
Install dependencies locally
$ pip install -r requirements.txt
Run the app
$ python main.py
View it in the browser
$ open http://localhost:8080
Deploy it
$ gcloud functions deploy hello_pubsub --runtime python37 --trigger-resource TOPIC_NAME --trigger-event google.pubsub.topic.publish