| 1 | # Packaging a cmd2 application for distribution |
| 2 | |
| 3 | As a general-purpose tool for building interactive command-line applications, `cmd2` is designed to |
| 4 | be used in many ways. How you distribute your `cmd2` application to customers or end users is up to |
| 5 | you. See the [Overview of Packaging for Python](https://packaging.python.org/overview/) from the |
| 6 | Python Packaging Authority for a thorough discussion of the extensive options within the Python |
| 7 | ecosystem. |
| 8 | |
| 9 | ## Publishing to the Python Package Index (PyPI) |
| 10 | |
| 11 | The easiest way is to follow the tutorial for |
| 12 | [Packaging Python Projects](https://packaging.python.org/en/latest/tutorials/packaging-projects/). |
| 13 | This will show you how to package your application as a Python package and upload it to the Python |
| 14 | Package Index ([PyPI](https://pypi.org/)). Once published there, users will be able to install it |
| 15 | using idiomatic Python packaging tools such as [pip](https://pip.pypa.io/) or |
| 16 | [uv](https://github.com/astral-sh/uv). |
| 17 | |
| 18 | Small tweaks on this process can allow you to publish to private PyPI mirrors such as one hosted on |
| 19 | [AWS CodeArtifact](https://aws.amazon.com/codeartifact/) or a private |
| 20 | [Artifactory](https://jfrog.com/artifactory/) server. |
| 21 | |
| 22 | ## Packaging your application in a container using Docker |
| 23 | |
| 24 | Packing your Python application in a [Docker](https://www.docker.com/) container is great when it |
| 25 | comes to cross-platform portability and convenience since this container will include all |
| 26 | dependencies for your application and run them in an isolated environment which won't conflict with |
| 27 | operating system dependencies. |
| 28 | |
| 29 | This convenient blog post will show you |
| 30 | [How to "Dockerize" Your Python Applications](https://www.docker.com/blog/how-to-dockerize-your-python-applications/). |
| 31 | |
| 32 | ## Packing your application along with Python in an installer |
| 33 | |
| 34 | For developers wishing to package a `cmd2` application into a single binary image or compressed |
| 35 | file, we can recommend all of the following based on personal and professional experience: |
| 36 | |
| 37 | - [Nuitka](https://github.com/Nuitka/Nuitka) |
| 38 | - Nuitka is a Python compiler written in Python |
| 39 | - You feed it your Python app, it does a lot of clever things, and spits out an executable or |
| 40 | extension module |
| 41 | - Particularly convenient if you have IP you wish to protect by obfuscating the Python source |
| 42 | code behind your application |
| 43 | - [PyInstaller](https://www.pyinstaller.org) |
| 44 | - Freeze (package) Python programs into stand-alone executables |
| 45 | - PyInstaller bundles a Python application and all its dependencies into a single package |
| 46 | - The user can run the packaged app without installing a Python interpreter or any modules |
| 47 | - [PyOxidizer](https://github.com/indygreg/PyOxidizer) |
| 48 | - A modern Python application packaging and distribution tool implemented in Rust |
| 49 | - A utility for producing binaries that embed Python and all of your dependencies |
| 50 | - You can copy a single executable file to another machine and run a Python application |
| 51 | contained within. It just works. |