Skip to main content

utility to execute a pythonscript from both commandline and webserver

Project description

cgli

A utility to use a python program from both command line (cli) as website (cgi)

Installation

Use pip to install cgli

	pip install cgli

Usage

Example script:

# import the application_make 
# and application_execute functions
# from the cgli module
from cgli import application_maker, application_execute


# define the arguments
arguments = {
    'string'  : { 'short': 's', 'help': 'a string' },
    'number'  : { 'short': 'n', 'help': 'a number', 'type': int },
    'another' : { 'short': 'a', 'help': 'another number', 'default': 42, 'type': int },
}

# define a function with the arguments defined above
def some_function(string, number, another):
    # do something
    sum = number + another

    # return something
    return {
        'string': 'The string is %s' % string,
        'number': 'The number is %d' % number,
        'sum': sum,
    }


# make the application and execute it
application_execute(application_maker(some_function, arguments))

Command line

Show arguments:

$ ./example.py -h

Use arguments (long and short attribute names can be combined):

$ ./example.py -s"Hello World" --number 3

Webserver

Show arguments:

http://example.com/example.py?h

Use arguments (only long attribute names can be used)

http://example.com/example.py?string=Hello+World&number=3

Project details


Download files

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

Source Distribution

cgli-0.0.4.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

cgli-0.0.4-py3-none-any.whl (15.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page