I would like to type in my Google Cloud function:
from my_google_cloud_project import another_google_cloud_func
another_google_cloud_func()
I don't want to invoke that function via HTTP request. How can I just import it?
Both functions are Google Cloud functions, but not just python code!
you can create a code.py file and write your code there
read the content of that file
with open('code.py') as f
content = f.read()
then execute those content using
exec(content)
Please read the official documentation regarding :
Packaging local dependencies
You can also package and deploy dependencies alongside your function.
This approach is useful if your dependency is not available via the
pip package manager or if your Cloud Functions environment's internet
access is restricted. For example, you might use a directory structure
such as the following:
You can then use code as usual from the included local dependency, localpackage. You can use this approach to bundle
any Python packages with your deployment.
Related
I'm trying to use OpenAPI for a Python project.
I've previously used OpenAPI with Java and it was really easy as you could configure it into pom.xml so that you would write a yaml file and then you would get an interface that you could implement into your controller.
I'm now working in Python and I'm trying to do a similar thing where you write an yaml file and get an interface or something similar that you can use.
I've tried openapi-generator-cli generate but it seems like it creates a lot of bloat files as it creates the whole server but I only need a single file that I can use further.
Is there something similar for Python as it is for Java?
Thanks in advance
You may want to try import flask_restx.
Then visit top-level URL of your flask app to see the swagger details.
https://flask-restx.readthedocs.io/en/latest/swagger.html#swaggerui
EDIT
Consider using apispec.
$ pip install -U 'apispec[yaml]'
can try flask-toolkits link very easy to setup as it will generate your openapi/swagger spec. Once you already done your code can try with app.run() then access http://localhost:5000/openapi.yaml
I've written a Python program that I want to package and upload to the Python package index. After doing this, is there any way for me to import that Python package and use it in Node.js or ReactJS? I basically want to use the functions and classes in the Python package to get some information and show it in some frontend application.
I am not sure if there is any mode to access the packages directly, however, you sure can execute a python script from your Node.js backend by using the child_process package.
Reference:
How to call a Python function from Node.js
I want to run a python script as part of a jenkins pipline triggered from a github repo. If I store the script directly in the repo itself, I can just do sh 'python path/to/my_package/script.py' which work perfectly. However since I want to use this from multiple pipelines from multiple repos, I want to put this in a jenkins shared library.
I found this question which suggested storing the python file in the resources directory and copying it to a temp file before use. That only works if the script is one standalone file. Unfortunately, mine is a package with multiple python files and imports between them, so thats a no go. I also tried to copy the entire folder containing the python package from the answer to this question, which suggests getting the location of the library with
import groovy.transform.SourceURI
import java.nio.file.Path
import java.nio.file.Paths
class ScriptSourceUri {
#SourceURI
static URI uri
}
but its gives me the following error:
Scripts not permitted to use staticMethod java.net.URI create java.lang.String. Administrators can decide whether to approve or reject this signature.
It seems that some additional permissions are required, which I don't think I'll be able to acquire (its a shared machine).
So? Does anyone know how I can run a python package from jenkins shared library? Right now the only solution I can think of is to manually recreate the directory structure of the python package, which is obviously very messy and non-generic.
PS: There is no particular reason for using the python script over writing the same script in groovy. Its just that the python script is well tested, well understood and well supported. Rewriting the whole thing in groovy just isn't feasible right now.
You can go to http://host:8080/jenkins/scriptApproval/ page of your Jenkins installation and approve the request for your scripts, please see below:-
And follow the link for more information.
I am thinking about doing some test on app engine. And I have read about the library google has originally provided. I wonder what should I do if I want to use some external libraries that were installed before as part of Python2.7 such as Pyaudio and wx..
I was aware of that I should claim the library in the yaml file but what else do I need to do? Will naming and assigning a new environment variable help? If it does help, what paths should I include here? Thanks.
You should read up on the python sandbox and runtime restrictions, https://developers.google.com/appengine/docs/python/#Python_The_sandbox
This tells you how to use other libraries.
The libraries you list can not be used in appengine.
Also read up on 3rd party libraries that are directly supported https://developers.google.com/appengine/docs/python/tools/libraries27
I would like to build an admin section into my App Engine app that will allow me to download and install python modules dynamically.
Any ideas on the most efficient way to accomplish this, without the ability to write to file system?
Are there any examples of this being done?
Does python27 support of setuptools make this easier?
Edit:
My initial thought is that this could be accomplished by downloading an egg or zip file dynamically. Saving it to the blobstore, and loading if from there.
Is this posible?
What kind of performance issues would this create?
On GAE you has no access to the file system, that's why you can't install any third-party packages on your instance, you can only distribute they with your own code.
In your app directory create a folder called 'lib'. For any module you want to add, just unzip it and add it to lib. Then redeploy your application using the console or Google App Launcher. Repeat every time you want to add a new module.
I'm not 100% sure about this. But it seems to me that if don't want a manual process involved then I would suggest dynamically adding the module content as a blob store entry and loading the module at runtime.
But the trick as the previous answer states is that to use a package, its code needs to be present in your app.