Calmcode - typer: package

Package

1 2 3 4 5 6 7 8 9 10

When the typer cli app matures you'll want to package it. To turn a command line app into a package the most important thing to add is a setup.py file with appropriate configurations. A basic setup.py file might look like this.

Simple Setup

Below shows a simple setup file.

from setuptools import setup, find_packages

setup(
    name="demopkg",
    version="0.0.1",
    packages=find_packages(),
    install_requires=[],
)

You can use this to install your package via;

pip install -e .

The benefit of using this pip command is that you're also able to develop without having to reinstall your package.

With this step done, you should be able to run whatever cli is in the __main__ of your package.

python -m demopkg

This setup is already great. You could go a step further if you'd like to customise the commands but as is, you've already gotten everything working.

Direct Name

If you want to omit the python -m part and attach a custom name to your command line interface you'll need to make a slight change to your setup file.

from setuptools import setup, find_packages

setup(
    name="demopkg",
    version="0.0.1",
    packages=find_packages(),
    install_requires=[],
    entry_points={
        'console_scripts': [
            'megademo = demopkg.__main__:app',
            'megademodbdb = demopkg.db:app',
        ],
    },
)

If you're interested in the entire project, you should know that all the files are hosted on github.