Google App engine documentation states that it is possible to upload and use third party libraries provided they written in pure Python.
What are the steps I need to take to do this?
Google App engine documentation states that it is possible to upload and use third party libraries provided they written in pure Python.
What are the steps I need to take to do this?
What I did is created a file called fix_path.py in my root directory that looks like this:
import os
import sys
import jinja2
# path to lib direcotory
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'lib'))
Then I created a lib directory, and drop the module in there.
For example, I use WTForms. My file structure looks like this.
when I am ready to call it from my somefile script
import fix_path # has to be first.
import wtforms
here is this example in my github source. checkout fix_path.py for setup and views.py for usage.
Well I tried the same with following steps.
lib/__init__.py
in my project root.created my module (mymodule.py
), and defined a function i.e.
def myfunc():
return "mycustomfunction"
imported mymodule in my main.py
from lib import mymodule
I could use the returned value from myfunc()
and could pass that as a template value to my jinja2 template
Similarly, if we follow what @rjz also pointed out in the first answer, if the 3rd Party library is just a module then we can keep that in libs with an init file and it can be imported with an import statement ( point 3) . If the 3rd party library is a package then we can keep it in the project root and import it again with an import statement as this one in the main.py
:
from thirdpartypackage import *