Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (testpypi.python.org).
Help us improve Python packaging - Donate today!

Python library for creating command line interfacesusing type annotations

Project Description

Playing around with the new type annotations in Python 3.5 and 3.6, I noticed they can be used to define command line interfaces from a regular python function. It’s kind of like what click does, but better.

Usage

SimpleCli Example:

# test.py
from typing import List, Optional
from pathlib import Path
from clype import SimpleCli

@SimpleCli
def mycli(v: Optional[bool], paths: List[Path]):
    print('v:', v)
    print('paths ({}):'.format(type(paths[0])), *paths)

if __name__ == '__main__':
    mycli.run()

Result:

$ python test.py -v dir/file.ext
v: True
paths (<class 'pathlib.PosixPath'>): dir/file.ext

SubcommandCli Example:

# test.py
from typing import List, Optional
from pathlib import Path
from clype import SubcommandCli

mycli = SubcommandCli('mycli')

@mycli.command
def bar(r: Optional[bool], path: Path):
    """
    The first command
    """
    pass

@mycli.command
def foo(v: Optional[bool], paths: List[Path]):
    """
    The second command
    """
    pass

if __name__ == '__main__':
    mycli.run()

Result:

$ python test.py -h
usage: mycli [-h] command ...
optional arguments:
  -h, --help  show this help message and exit
commands:
  bar       The first command
  foo       The second command
$ python test.py bar -h
usage: mycli bar [-h] [-r] path
positional arguments:
  path
optional arguments:
  -h, --help  show this help message and exit
  -r

Release History

This version
History Node

0.1.0.post1

History Node

0.1.0

Download Files

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

File Name & Hash SHA256 Hash Help Version File Type Upload Date
clype-0.1.0.post1.tar.gz
(3.2 kB) Copy SHA256 Hash SHA256
Source Jun 6, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting