Package Exports
- serverless-python-requirements
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (serverless-python-requirements) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Serverless Python Requirements
A Serverless v1.0 plugin to automatically bundle dependencies from
requirements.txt
and make them available in your PYTHONPATH
.
Install
npm install --save serverless-python-requirements
Add the plugin to your serverless.yml
:
plugins:
- serverless-python-requirements
Adding the dependencies to sys.path
Automatic
The default behavior of this plugin is to link libraries into the working tree
during deployment so that they are in your handler's PYTHONPATH
when running
on lambda.
Manual
This method is required when using ZipImport support and can be enabled manually by adding the following option to your config:
custom:
pythonRequirements:
link: false
serverless-python-requirements
adds a module called requirements
to your
puck. To easily make the bundled dependencies available, simply import it. Eg.
add this to the top of any file using dependencies specified in your
requirements.txt
:
import requirements
# Now you can use deps you specified in requirements.txt!
import requests
Cross compiling!
Compiling non-pure-Python modules is supported on MacOS via the use of Docker
and the docker-lambda image.
To enable docker usage, add the following to your serverless.yml
:
custom:
pythonRequirements:
dockerizePip: true
ZipImport!
To help deal with potentially large dependencies (for example: numpy
, scipy
and scikit-learn
) there is support for having python import using
zipimport. To enable this
add the following to your serverless.yml
:
custom:
pythonRequirements:
zipImport: true
Limitations
- if using the
package
directive inserverless.yml
ensure thatrequirements.py
is are included as well as.requirements
or.requirements.zip
if using ZipImport.
Manual invocations
The .requirements
and requirements.py
files are left behind to simplify
development. To clean them up, run sls requirements clean
. You can also
install them manually for local development with sls requirements install
.
Credit
This plugin is influenced by serverless-wsgi from @logandk. I however wanted a simpler pip install process. It now also supports bundling packages without the wsgi handler.