paketoi 0.1

A few months ago I wrote about how to build AWS Lambda deployment packages with Pex. It works, but it left me wondering: why isn’t there a one-command solution for building the packages for simple Python projects? I decided to build one.

It’s called paketoi. It takes a requirements.txt file and your source files and bundles them into a zip file that you can deploy on AWS Lambda. I’ve released the initial version on PyPI.

It’s a bit rough right now - it is version 0.1 after all - but I hope to polish it later on.

Why use paketoi?

AWS Lambda’s developer guide has instructions for building deployment packages with pip. Why use paketoi instead of them? There are two benefits:

  1. It’s a single command instead of a bunch of calls to pip and zip
  2. It works around that pip bug that sometimes results in wrong versions of dependencies being installed, depending on the Python version you’re using.

How it works under the hood is that it downloads deps with pex like in my previous post. It comes with the “complete platform information” files, so you don’t have to care about them. As a bonus, the result is zipped with repro-zipfile, so the checksum of the deployment package stays the same if the inputs stay the same.

Usage

For full installation and usage instructions, see the README.The easiest way to install it is with pipx: pipx install paketoi.

Here’s a small example. Let’s say you have a simple lambda with just source code file, lambda_function.py, and some dependencies listed in requirements.txt.

.
├── lambda_function.py
└── requirements.txt

Let’s say you want to build a deployment package that works with Python 3.12 runtime on arm64 architecture. You can do that by running the following command in the project directory:

paketoi -r requirements.txt --runtime 3.12 --platform arm64 lambda.zip

Now upload lambda.zip to AWS Lambda and enjoy your function.

Could you use uv instead?

uv is a brand new Python package installer developed by Astral, the same company that also develops ruff. uv is billed as a drop-in replacement for pip so you might ask if it has the same shortcoming as pip.

Unfortunately uv does not yet support the --target flag, so it cannot be easily used for building the deployment packages.

But what about Poetry?

Are you using Poetry instead of requirements.txt like I have recommended on this blog? That’s great! I’ve noticed that since my post about Pex, a new Poetry plugin has appeared: poetry-plugin-lambda-build. I have not tried it out, but it looks potentially useful.


Comments or questions? Send me an e-mail.