Skip to main content

More click.

Project description

more_click

PyPI PyPI - Python Version PyPI - License DOI

Extra stuff for click I use in basically every repo

More Options

The module more_click.options has several options (pre-defined instances of click.option()) that I use often. First, verbose_option makes it easy to adjust the logger of your package using -v.

There are also several that are useful for web stuff, including

Name Type Flag
more_click.host_option str --host
more_click.port_option str --port

Web Tools

In many packages, I've included a Flask web application in wsgi.py. I usually use the following form inside cli.py file to import the web application and keep it insulated from other package-related usages:

# cli.py
import click
from more_click import host_option, port_option


@click.command()
@host_option
@port_option
def web(host: str, port: str):
    from .wsgi import app  # modify to point to your module-level flask.Flask instance
    app.run(host=host, port=port)


if __name__ == '__main__':
    web()

However, sometimes I want to make it possible to run via gunicorn from the CLI, so I would use the following extensions to automatically determine if it should be run with Flask's development server or gunicorn.

# cli.py
import click
from more_click import host_option, port_option, with_gunicorn_option, workers_option, run_app


@click.command()
@host_option
@port_option
@with_gunicorn_option
@workers_option
def web(host: str, port: str, with_gunicorn: bool, workers: int):
    from .wsgi import app  # modify to point to your module-level flask.Flask instance
    run_app(app=app, with_gunicorn=with_gunicorn, host=host, port=port, workers=workers)


if __name__ == '__main__':
    web()

For ultimate lazy mode, I've written a wrapper around the second:

# cli.py
from more_click import make_web_command

web = make_web_command('my_package_name.wsgi:app')

if __name__ == '__main__':
    web()

This uses a standard wsgi-style string to locate the app, since you don't want to be eagerly importing the app in your CLI since it might rely on optional dependencies like Flask. If your CLI has other stuff, you can include the web command in a group like:

# cli.py
import click
from more_click import make_web_command


@click.group()
def main():
    """My awesome CLI."""


make_web_command('my_package_name.wsgi:app', group=main)

if __name__ == '__main__':
    main()

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

more_click-0.1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

more_click-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: more_click-0.1.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for more_click-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3f55a247d382a6b099267848cf7300afcc08c2691b3f6db91d76a99c92acec40
MD5 e47dd9764e28f2fbe8aa37885679fe35
BLAKE2b-256 d8ad45fef4052f9d1d73831c1edf15140070e739588c6c1591ca19ff87a7944f

See more details on using hashes here.

Provenance

File details

Details for the file more_click-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: more_click-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for more_click-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 41fd8911931d02132f83923337e6ad62fad95f8b6827e105e413fddcc1ff4d3d
MD5 3cb977b67262b9534988fec6c0a4dfc5
BLAKE2b-256 4981b24f7c8efe75cf988bf9dc073321128872c8c24b013cd2acda3ed16de67a

See more details on using hashes here.

Provenance

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