Search code examples
pythongoogle-app-engineweb-applicationswebapp2

Use external libraries in Google App Engine(Python) with webapp


How can I use an external library like requests in GAE with webapp? There are various related questions on SOF but none that answer my question specifically.


Solution

  • You may to create dir in your project dir, let it will be distlibs. Than in main.py you should add this dir into sys.path:

    import sys
    sys.path[0:0] = ['distlibs']
    

    than you can import libs from distlibs dir (for example wtforms):

    from wtforms import validators
    ...
    

    Update:

    In the case of the requests lib, once you extract ithub(github.com/kennethreitz/requests) will find it has a directory called requests in it. That is what you need to put somewhere in your code.