Use app engine yaml parser in scripts - python

I have some configuration files I want to write in yaml and read in a Python script running on Google app engine. Given that app engine uses app.yaml, index.yaml among others it seems reasonable to assume there is a python yaml parser available.
How can I gain access to this parser (what is the import) and where can I find its documentation.
I'd also like to use this parser for scripts running outside of agg engine (build scripts and such) so how can I gain access to the same import from a script that will run from the command line?

The YAML library is included with the AppEngine SDK. It is located in google_appengine/lib/yaml. You should be able to use it in your AppEngine code just by having import yaml in your code.
For non-AppEngine work, a quick Google search reveals http://pyyaml.org/ home to many and various Python implementations.

Related

how to setup modules in the Glue job script

I'm following this tutorial: https://www.youtube.com/watch?v=EzQArFt_On4
In this tutorial it's only using one python script, what is I need to import some functions from another python script? For example: import script2
I wonder what's the correct way to setup in Glue job? I've tried to store this script in s3 bucket and add the location in editjob -> Security configuration, script libraries, and job parameters (optional)
->Python library path, but it gave me error ModuleNotFoundError: No module named 'script2, does anyone know how to fix this? Thanks.
In the video tutorial there is no such import like import script2. So if you do this in your script and don't provide script2.py library, the import is going to fail with your the message you are getting.
How to write modules, is best explained in Python docs.
The best way to start programming glue jobs is to auto-generate glue scripts by glue console. Then you can use the scripts generated as a starting point for customization. What's more you can setup Glue Endpoints or even run glue locally (or on ec2 instance) for learning and development purposes.

Automate CloudFoundry Deployment with python

I am new to Cloud Foundry. I want to automate the application deployment and service binding in Cloud Foundry with Python.
For deploying an application in Cloud Foundry we will use the commands (Cloud Foundry CLI) like:
cf push redis-sample-app
cf create-service redis shared-vm service-example-redis
cf bind-service redis-sample-app service-example-redis
cf restage redis-sample-app
Now I don't want to use the CLI for that, I just want to write a Python/Ruby/(any language) script which will do all the things.
I have tried google and ended up with Python cloudfoundry module, but it's not clear to go on. Is there any API for my task, like boto for accessing EC2. I have tried following code in Python:
from cloudfoundrty import CloudFoundryInterface
cf=CloudFoundryInterface(target="api.end.point",username="myusername",password="mypwd")
cf.login()
It's showing the error:
`File "C:\Python27\lib\site-packages\requests\models.py", line 398, in full_url
raise MissingSchema("Invalid URL %r: No schema supplied" % url)
MissingSchema: Invalid URL u'users/kishorekumarnetala%40gmail.com/tokens': No schema supplied`
First, a quick thing, what is the actual API endpoint of your Cloud Foundry deployment? If you're using the cf CLI, what did you put when you did cf api API_ENDPOINT? You can run cf target to see what the current API endpoint is set to. It should have a scheme like http or https. If you're actually putting api.end.point in your Python code, that's why you're getting the error message you're seeing.
As for your general question about automating Cloud Foundry interactions, you have a few options:
Write a shell script that directly drives the cf CLI
Write a module in a higher-level language like Ruby or Python that simply wraps calls to the CLI
Write a module in a higher-level language that wraps calls to the restful API.
Here's a breakdown of those options:
If your list of languages (Ruby/Python/any language) included things like bash or pure sh, then you can easily use that to have "code" that automates interacting with Cloud Foundry. The CLI is designed to be scriptable, and not require human interaction. This is the most common approach, since the CLI is designed for this use case.
If you want to drive interactions via a different language (e.g. maybe because this is part of a larger project that's already in a different language), you can certainly do that. The full suite of highest level system tests for Cloud Foundry does this in Golang. If you're familiar with navigating Golang projects, you can look at:
the package that drives the CLI
the test suites that use that package
You can also build a wrapper around the RESTful HTTP API. There are also several out there already in the ecosystem:
Here is a recent thread about an official supported Java client
Someone in the community has been developing a node.js client for their own purposes (not sure if it's public though)
There used to be a Ruby gem but it I believe it is deprecated, but you may be able to find it and look at it for ideas

Is it possible to access java class libraries from a python program in Google App Engine?

I am using Python in Google App Engine and I have a Java class library that I want to use in my program...
Is there a way to import that library and use it in a python program?
I have searched the net and found something like this:
from jpype import *
import re
import string
startJVM("/opt/sun-jre/lib/i386/client/libjvm.so", "-Djava.class.path=/home/talat/zemberek-0.6.4.jar", "-ea")
zerisim = JPackage('net').zemberek.erisim.Zemberek
But I am not sure whether "jpype" can be used in Google App Engine...
Thank you,
If the java functionality is critical to your application and not easy to rewrite in python, then you could write a simple web app in java that uses the library, and run that on appengine as a separate version than your main python app. You could then call the java app from the python app using HTTP. This is not an elegant solution, but if you really need the functionality, it should get the job done. The key here is that app engine will let you run more than one "version" of your app at a time, including different runtimes.
There is no way at present on App Engine to import or otherwise access Java libraries from Python. Jython might be an approach worth trying (using the Java GAE SDK), though I'm not aware of anyone having gone that route before.

Does poster.encode module supported in python appengine?

Does poster.encode module supported in python appengine ??
if No , whats is the possible alternatives ?
You'd need to deploy the module with your code by including it in your application's directory when deploying, but it does appear to be a pure python module and looking through the source I see no reason why it wouldn't work just fine in App Engine.
The only modules that won't work are those that use C extensions or make use of features like threads, sockets, etc. that are disabled in the App Engine runtime. poster.streaminghttp, for example, almost certainly won't work, as it uses sockets.
from what I see in https://bitbucket.org/chrisatlee/poster/src/bd5ab4c5005c/poster/encode.py I doesn't see any class that would be forbidden by google app engine. Just upload it as any of your own code.

How to check available Python libraries on Google App Engine & add more

How to check available Python libraries on Google App Engine & add more?
Is SQLite available or we must use GQL with their database system only?
Thank you in advance.
SQLite is there (but since you cannot write to files, you must use it in a read-only way, or on a :memory: database).
App engine docs do a good job at documenting what's there. You can add any other pure-python library, typically as a zipfile of .py (NOT .pyc) files to upload in the main directory of your app (you can directly import from inside the zipfile, of course).
A few more pure-Python third-party libraries included with app engine are listed and documented here -- the paragraph on zipimport at this URL has a bit more details on the ways and limitations of using zipfiles to add more third-party pure-Python libs to your app.
Afaik, you can only use the GAE specific database.

Categories