It became Public Beta, but it seems that Python support is not yet available, so I will try to use it.
I haven't written Node.js, but I wrote Gugu like this.
index.js
const spawnSync = require('child_process').spawnSync;
exports.helloWorld = function helloWorld(req, res) {
result = spawnSync('python', ['./inspect.py'], {
stdio: 'pipe',
});
if (result.stdout){
res.status(200).send(result.stdout);
}else if (result.stderr){
res.status(200).send(result.stderr);
}
};
inspect.py
print('hello functions!')
Compress these two files with Zip and upload them on the Console screen of Cloud Functions.
This completes deploy, HTTP Trigger, so if you open the URL in your browser, Python will output'hello functions!'.
Now that I know I can use Python, let's look into a little more detail.
inspect.py
try:
import tensorflow as tf
print('tensorflow %s' % tf.__version__)
except:
print('tensorflow n/a')
try:
import sklearn
print('sklearn %s' % sklearn.__version__)
except:
print('sklearn n/a')
try:
import numpy as np
print('numpy %s' % np.__version__)
except:
print('numpy n/a')
try:
import scipy as sp
print('scipy %s' % sp.__version__)
except:
print('scipy n/a')
List the existence of the library that I was interested in for the time being. ・ ・ ・ ** It was annihilated ** 3rd-party lib doesn't seem to be prepared.
What I did a quick look at
Python version | 2.7.9 |
OS | Debian series 8.7 |
pip | N/A |
easy_install | N/A |
File System | read only |
Since the File System is read only, it seems impossible to install and use something at runtime. However, there seems to be no limit to the file format included in Zip at the time of deploy, so It seems that it can be executed if you put the binary etc. in advance.
Googler is doing the same with Go. That may be more helpful. https://github.com/kelseyhightower/google-cloud-functions-go
Currently, using Python is quite a hassle, but I think that it is an environment where you can execute functions very easily as you use Node.js as usual. It is very attractive to be able to write quickly on the Console and deploy immediately.
Recommended Posts