Skip to main content

console script boilerplate

Project description

console script boilerplate

some boilerplate stuff for console scripts. inspired by now unmaintained pyCLI.

decorate your main function and register it in your setup.py as console_scripts entry_point [1]. the function will receive an app object as argument.

you get:

  • pythons ArgumentParser
  • KeyboardInterrupt is catched
  • SIGTERM is handled, so that context managers will exit properly
  • logging helper

exit_handler and sigterm_handler may be customized.

[1] https://setuptools.readthedocs.io/en/latest/setuptools.html#automatic-script-creation

example

from csboilerplate import cli_app


@cli_app(name=__name__)
def main(app):
    app.logging_config(log_level=app.args.debug)
    # do your stuff


main.argparser.add_argument('-d', '--debug', action='count', default=0,
                            help='lower logging threshold, may be used twice')

dev env

checkout git and:

virtualenv .env -p python3
. .env/bin/activate
pip install -e .[dev]

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

csboilerplate-0.1.0.tar.gz (7.8 kB view details)

Uploaded Source

File details

Details for the file csboilerplate-0.1.0.tar.gz.

File metadata

File hashes

Hashes for csboilerplate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d3921a2a682d7471d27c72b796909ac33db99a42dcc9fa02e80d782ae41d79a4
MD5 b7452918d917594d85f4e2a81c2b1a8c
BLAKE2b-256 5a58c638e4c756a9ab27f8b3a7e18a507882d7037fdfed1261a77c3ce5a07906

See more details on using hashes here.

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