Skip to main content

make python functions usable from command line

Project description

Version License Python Contributors

When developing a new package, there are python functions that you want to make also available from the command line. To do so, an additional function is needed; a specially designed command-line-function which is then referenced in the setup.py file, inside the entry_points key. This command-line-function is special indeed, since it cannot have arguments (it uses instead sys.stdin or sys.argv as inputs) and cannot have return values (it uses instead print() as output).

With cmdfunctools you can automatically create a command-line-function from any python function.

Installation

The source code can be downloaded from GitHub, where the code is always available.

It can also be installed from PyPI running:

$ pip install cmdfunctools

Usage

To create a command-line-function use the comand_func decorator:

from cmdfunctools import command_func

@command_func(itype='int', otype='int')
def add(a, b)
    res = a + b
    return res

Now the function can be referenced as is in entry_points inside setup.py and, after the package installation, it can be used from the command line interface:

$ add 3 2
5

The original function can still be used within python code using the __wrapped__() method:

>>> add.__wrapped__(3, 2)
5

Features

  • Automatic number of arguments check

  • Automatic argument type check

  • Optional argument length check (equal or less-or-equal)

  • Pipelines supported

  • I/O argument types supported:

    • integer
    • hexadecimal

The project is in 3-Alpha development status, new features will be added before 5-Production/Stable.

Project details


Release history Release notifications

Download files

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

Files for cmdfunctools, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size cmdfunctools-0.0.3-py3-none-any.whl (6.3 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size cmdfunctools-0.0.3.tar.gz (5.9 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 SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page