Python Tip #281 (of 365): Bundle your package into one runnable file with zipapp...

@treyhunner@mastodon.social

Python Tip #281 (of 365):

Bundle your package into one runnable file with zipapp.

$ python3 -m zipapp src -m "greet.cli:main" -p "/usr/bin/env python3" -o greet.pyz
$ python3 greet.pyz
Hello from greet!
$ ./greet.pyz
Hello from greet!

That ".pyz" file is a zip file holding everything in src (here, yesterday's greet package) plus a __main__โ€.py file that zipapp writes at its root:

# -*- coding: utf-8 -*-
import greet.cli
greet.cli.main()

๐Ÿงต (1/3)

#Python #DailyPythonTip