Goal

Setup a basic command line package in python.

Package

Let’s get to it

Create a virtual environnement.

python -m venv my_env
. my_env/bin/activate

Then the setup.py file: (require setuptools)

from setuptools import setup

setup(
    name='myapp',
    version='1.0',
    py_modules=['myapp'],
    install_requires=[
        'Click',
    ],
    entry_points="""
        [console_scripts]
        myapp=myapp:cli
    """,
)

and the myapp.py

def cli():
    print("Launching the app")

Then you can run :

pip install --editable .

and while you are in the venv you can run myapp and it will work.

Now, we need to get the cli basic function up.

Go back to myapp.py

import click

@click.command()
@click.option("--stuff", default="random stuff")
def cli(stuff):
    print("posting %s" %stuff)

and now you have a basic working command line.

More options in the docs of Click