Skip to main content

Pendulum type support for click.

Project description

Click Pendulum

Click support for Pendulum date, time, interval and duration types to allow developers to easily parse strings as parameters to Python click CLIs.

Example: pendulum.DateTime

You can accept a Pendulum DateTime as a parameter to your click CLI

import click, pendulum
from click_pendulum import DateTime

@click.option(
    "--date",
    type=DateTime(),
    default=pendulum.now(),
    help="An example parsing and printing a datetime.",
)
@click.command()
def cli(date: pendulum.DateTime):
    click.echo("The date : {0}".format(date))

if __name__ == "__main__":
    cli()  # type: ignore
$ python examples/datetime_with_custom_format.py --date=2016-01-01
The date : 2016-01-01 00:00:00+00:00

Example: pendulum.Duration

You can accept a Pendulum Duration as a parameter to your click CLI

import click, pendulum
from click_pendulum import Duration

@click.option(
    "--duration",
    type=Duration(),
    help="Parse a duration string.",
)
@click.command()
def cli(duration: pendulum.Duration):
    click.echo(f"Duration: {duration}")

if __name__ == "__main__":
    cli()  # type: ignore
$ python examples/duration_parser.py --duration="2d5h"
Duration: 2 days 5 hours
pip install click-pendulum

Development

Building and packaging

poetry build

Testing the compiled wheel

# Create a virtual environment for testing
python -m .venv/test
source .venv/test/bin/activate

# Confirm importing and exporting is correct
python -c 'import click_pendulum as cd; print(dir(cd))'

Authors

  • Dawson Reid (@ddaws)

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

click_pendulum-0.2.1.tar.gz (2.5 kB view hashes)

Uploaded Source

Built Distribution

click_pendulum-0.2.1-py3-none-any.whl (3.3 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