1

I've found many discussions on bundling python scripts but I'm interested in bundling into a ZIP file my Python script that depends only on 2 libraries "JSON" and "PYMYSQL". Thus, I'd like to get a ZIP file that is containing my Python script with the packages "JSON" and "PYMYSQL" only. Is it possible?

I've used the library called "Pigar" in order to list in the "requirements.txt" the necessary 2 dependencies (i.e. json and pymysql).

The aim is to create a ZIP file to deploy it as a lambda function on AWS; I'm thus looking for a small ZIP file that does not exceed 50MB.

I am not an expert in all virtualenv etc... I guess my package would not work with only JSON and pymysql right?

Many thanks

sammtt
  • 401
  • 1
  • 6
  • 14
  • On a high-level, you will need to go through all the "built-in" libraries your code is using along-with external dependencies. You can copy to original to a different folder and remove unwanted libraries and try it out. Make sure Python path is changed to new folder. If it works locally, it would work on AWS. – Anil_M Dec 11 '17 at 21:16

1 Answers1

0

Have a look at the serverless framework (https://serverless.com/). There is a plugin that might do what you want: https://www.npmjs.com/package/serverless-python-requirements

It handles your requirements and you can even tell it to do this in a dockerized environment, such that you can also use packages with binary dependencies.

Otherwise you have to apply some manual labour. Especially if you need packages that have binary dependencies and that need to be compiled against the lambda environment.

DrEigelb
  • 588
  • 4
  • 8