Skip to main content

ec - a cli interface for python modules.

Project description

The intenetion

ec - intends to reduce the learning curve needed to expose functionality via the command line. With available options like argparse and docopt, it might take several hours to get them right. And there is also the issue of the needed amount of extra coding to setup and process the arguments. See the following example to see how ec solves the issue.

A simple example

from import task

def say_hello():
        print 'Hello, world!'

could be accessed from the command line, like:

$ python say_hello
        Hello, world!


  • Typed arguments.
  • Sub commands (like git).
  • Custom types.
  • Shell mode (like python’s interactive mode).
  • Named / Positional arguments.

A more complete example


from import task, arg, group

@task # define a task
@arg(type=int, desc= 'Value for arg1') # add an argument with a type and a description
def task1(arg1, arg2=1):
        print arg1, arg2

@group(desc = 'A group with some tasks') # define a group
class group1:
        def task1(arg1): # define a task inside the group
                print arg1 + arg1

Execute a task: <dispatch mode>

From the command-line enter

$ python task1 arg1=1 arg2=2
        1 2

$ python group1/task1 arg1=1

$ python group1/task1 1 # positional arguments too are supported

Interactively execute tasks: <shell mode>

From the command-line enter

$ python # this will enter into ec-shell

Value for arg1: 1
arg2 (1): 2
1 2

>group1/task1 # execute task1 under group1
arg1: 1

>task1 arg1=1 # arguments can be given while calling the task, the missing arguments will be collected from the user
arg2 (1): 2
1 2

>^Z # exit the shell

Utilizing STDIN:

From the command-line enter

$ echo 1 2 | xargs python task1 # Dispatch a command with args passed through STDIN and converted to args using xargs.
$ echo -e "1\n2" | python -p task1 # Dispatch a command and with partial args and pass the rest through STDIN.
$ echo task1 1 2 | python # Feeding the shell with complete commands through stdin.

Detailed docs could be found at PyDocs.

For more examples check the github page.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ec, version 0.2.5
Filename, size File type Python version Upload date Hashes
Filename, size ec-0.2.5-py2.py3-none-any.whl (26.4 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size ec-0.2.5.tar.gz (39.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page