Python script to package a Python function for deploying to AWS Lambda
Project description
package-python-function
Python command-line (CLI) tool to package a Python function for deploying to AWS Lambda, and possibly other cloud platforms.
This tool builds a ZIP file from a virtual environment with all depedencies installed that are to be included in the final deployment asset. If the content is larger than AWS Lambda's maximum unzipped package size of 250 MiB, then this tool will employ the ZIP-inside-ZIP (nested-ZIP) workaround. This allows deploying Lambdas with large dependency packages, especially those with native code compiled extensions like Pandas, PyArrow, etc.
This technique was originally pioneered by serverless-python-requirements, which is a NodeJS (JavaScript) plugin for the Serverless Framework. The technique has been improved here to not require any special imports in your entrypoint source file. That is, no changes are needed to your source code to leverage the nested ZIP deployment.
The motivation for this Python tool is to achieve the same results as serverless-python-requirements but with a purely Python tool. This can simplify and speed up developer and CI/CD workflows.
One important thing that this tool does not do is build the target virtual environment and install all of the dependencies. You must first generate that with a tool like Poetry and the poetry-plugin-bundle.
Example command sequence
poetry bundle venv .build/.venv --without dev
package-python-function .build/.venv --output-dir .build/lambda
The output will be a .zip file with the same name as your project from your pyproject.toml file (with dashes replaced with underscores).
Installation
Use pipx to install:
pipx install package-python-function
Usage / Arguments
package-python-function venv_dir [--project PROJECT] [--output-dir OUTPUT_DIR] [--output OUTPUT]
-
venv_dir[Required]: The path to the virtual environment to package. -
--project[Optional]: Path to the pyproject.toml file. Omit to use the pyproject.toml file in the current working directory.
One of the following must be specified:
-
--output: The full output path of the final zip file. -
--output-dir: The output directory for the final zip file. The name of the zip file will be based on the project's name in the pyproject.toml file (with dashes replaced with underscores).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file package_python_function-0.0.7.tar.gz.
File metadata
- Download URL: package_python_function-0.0.7.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d23891b089545acf068a63dbe311f3386783b82dceda66ce907bbaa7142d49ab
|
|
| MD5 |
59394e3a3a9d52c19965e6084ec712e2
|
|
| BLAKE2b-256 |
9692936e06df92736d70a85a92166b146e8bcaaeeb5d8c4611d0343396e96769
|
Provenance
The following attestation bundles were made for package_python_function-0.0.7.tar.gz:
Publisher:
release.yml on BrandonLWhite/package-python-function
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
package_python_function-0.0.7.tar.gz -
Subject digest:
d23891b089545acf068a63dbe311f3386783b82dceda66ce907bbaa7142d49ab - Sigstore transparency entry: 205649960
- Sigstore integration time:
-
Permalink:
BrandonLWhite/package-python-function@4715fafa859596c2d7ff1b2d9dd16b90868783d2 -
Branch / Tag:
refs/tags/v0.0.7 - Owner: https://github.com/BrandonLWhite
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4715fafa859596c2d7ff1b2d9dd16b90868783d2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file package_python_function-0.0.7-py3-none-any.whl.
File metadata
- Download URL: package_python_function-0.0.7-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1959a38ffc7e9a3f2ef8f0a17cbbda3c69421dae2d07820b7d803a9c736b74da
|
|
| MD5 |
1aa1563833bb0b8d182acf1ab7792903
|
|
| BLAKE2b-256 |
76452580b40878db1f977de18792b18b5b7ea005dab46fe8a5912cd50ac46cb9
|
Provenance
The following attestation bundles were made for package_python_function-0.0.7-py3-none-any.whl:
Publisher:
release.yml on BrandonLWhite/package-python-function
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
package_python_function-0.0.7-py3-none-any.whl -
Subject digest:
1959a38ffc7e9a3f2ef8f0a17cbbda3c69421dae2d07820b7d803a9c736b74da - Sigstore transparency entry: 205649964
- Sigstore integration time:
-
Permalink:
BrandonLWhite/package-python-function@4715fafa859596c2d7ff1b2d9dd16b90868783d2 -
Branch / Tag:
refs/tags/v0.0.7 - Owner: https://github.com/BrandonLWhite
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4715fafa859596c2d7ff1b2d9dd16b90868783d2 -
Trigger Event:
release
-
Statement type: