Are there tools for Python that minimize the size of the imports used in a Python package, something similar to esbuild for JavaScript? Having a tool that extracts only the used methods of imported packages, uglifying them, and putting them into a single file for efficiency purposes would be very useful. I need something like that to package my Python code into a Lambda. I am having trouble finding a tool that does so beyond linting.
I tried tools like Black, flake8, and pyright, however none fulfill the purpose of minimizing the file/package size.
A few tools are available to assist you in packaging your code for usage in a Lambda function and reducing the size of Python imports.
Pipenv, a package manager that lets you manage dependencies and virtual environments for your Python applications, is one well-liked solution. You can deploy your project without relying on external dependencies by using pipenv to "vendor" your dependencies, which means that it will copy all the required packages into a vendor directory in your project.
Another tool that can help with this is pyinstaller. pyinstaller is a tool that can be used to package Python code into a standalone executable. It can also be used to package a Python script as a single executable file, which can be useful for deployment in environments like Lambda where you have limited control over the environment.
Are there Python tools that optimize for package size and performance?