How to add third party python libraries in Google App Engine, which are not provided by Google? I am trying to use BeautifulSoup in Google App Engine and unable to do so. But my question is for any library I want to use in Google App Engine.
The Python 3 runtime supports Python 3.7, Python 3.8, Python 3.9, and Python 3.10 and uses the latest stable release of the version that is specified in your app. yaml file. App Engine automatically updates to new patch release versions, but it will not automatically update the minor version.
Google has provided a documented way for included third-party libraries in your GAE project.
See the "Adding Third-party Packages to the Application" section of the Libraries in Python 2.7 docs.
If you want to include additional pure-python third-party packages, you can do so by setting up vendoring. Vendoring allows you to install packages to a subdirectory of your project and include them in your code. To use vendoring, create (or modify) appengine_config.py in the root of your project.
from google.appengine.ext import vendor # Add any libraries installed in the "lib" folder. vendor.add('lib')
And then just put all your libs' source code in your lib
dir
> pip install beautifulsoup4 -t lib
So your project directory structure looks like this:
project - lib - bs4 - your_code.py
This will allow your project's source files to import libs' packages/modules as if they were added to your PYTHON_PATH
. For example:
# file: your_code.py import bs4 # no need for 'from lib import bs4' # do stuff with bs4...
You can also easily install everything from a requirements.txt file by doing the following command
> pip install -t lib -r requirements.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With