pype-cli is a command-line tool to manage sets of other command-line tools. It simplifies the creation, orchestration and access of Python scripts that you require for your development work, process automation, etc.
- Install pype-cli via
pip install --user pype-cli. This will install the commandpypefor the current user - Run
pype pype.config shell-installand open a new shell to activate shell completion - Create a new plugin in your home folder:
pype pype.config plugin-register --create --name my-plugin --path ~/ - Create a sample pype for your plugin:
pype my-plugin --create-pype my-pype - Run your pype:
pype my-plugin my-pype - Show and edit the template pype you've just created:
pype my-plugin --open-pype my-pype
You'll find more information on the commands in the sections below.
To use an alternative name you need to install from source via
PYPE_CUSTOM_SHELL_COMMAND=my_cmd_name python setup.py install --user
pype-cli builds upon plugins and pypes. A pype is a single Python script whereas a plugin is essentially a Python module that extens pype-cli with a collection of pypes.
pype-cli ships with one built-in plugin called pype.config that is used to configure pype-cli. All of the required information will be stored to a local JSON-configuration file that defaults to ~/.pype-cli/config.json. To configure a custom configuration folder use the environment variable PYPE_CONFIG_FOLDER. For example to use /path/to/pype-cli/config.json as configuration folder/file put into your ~/.bashrc file: export PYPE_CONFIG_FOLDER=/path/to/pype-cli.
- List all available pypes:
pype --list-pypes - Open pype-cli's configuration file:
pype --open-config - Refer to
pype ... --helpfor further information on the command-line
For all options you will find a short variant such as -h for --help or pype -l instead of pype --list-pypes. They are omitted here for better readability.
pype-cli's main benefit is that is is extendable with custom plugins and that it will allow you to immediatelly browse and use newly created and existing plugins/pypes by using the <TAB> key and by configuring short aliases. To enable the functionality it is required to install a source-script to your shell's rc-file that will be executed everytime you open a shell.
- Run
pype pype.config shell-install - Run
pype pype.config shell-uninstallto remove if necessary
If you want to use one-tab completion (instead of two tab presses) you can add the following section to your .bashrc file:
bind 'set show-all-if-ambiguous on'
bind 'set completion-ignore-case on'For .zshrc apply instead:
unsetopt listambiguous- Register an existing plugin:
pype pype.config plugin-register --name myplugin --path ~/pype_plugins(mypluginis a Python module with at least an__init__.pyfile and~/pype_pluginsa folder where the plugin is stored) - On-the-fly create and register a new plugin:
pype pype.config plugin-register --create --name myplugin --path ~/pype_plugins - Unregister (but not delete) a plugin:
pype pype.config plugin-unregister --name myplugin
To create a new pype you need to decide to which plugin you want to add the pype, e.g., myplugin.
- Create a new pype from a template:
pype myplugin --create mypype - Create a new pype from a template with less boilerplate:
pype myplugin --minimal --create mypype - Create a new pype from minimal template and open immediately:
pype myplugin --minimal --edit --create mypype - Open a pype in your default editor:
pype myplugin --open-pype mypype - Delete a pype:
pype myplugin --delete-pype mypype
If you have selected a pype from a plugin you can set aliases for it. Afterwards you need to start a new shell session or source your rc-file to activate the aliases. New aliases are stored in the configuration file.
- Register an alias:
pype --alias-register mm myplugin mypype→alias mm="pype myplugin mypype" - Register an alias with options:
pype --alias-register mm myplugin mypype --option opt1 --toggle→alias mm="pype myplugin mypype --option opt1 --toggle" - Unregister an alias:
pype --alias-unregister mm - List all avaliable aliases:
pype --aliases
pype-cli contains a built-in file logger setup. To configure it use the pype pype pype.config logger. In your pypes you can use it right away like this:
import logging
import click
@click.command(name='my-pype', help=__doc__)
def main() -> None:
# Name your logger. Note that this can be omitted but you will end up
# with the default 'root' logger.
logger = logging.getLogger(__name__)
# Log something to the global log file. Note that the output to the file
# depends on the logging configuration mentioned above.
logger.debug('Debug message')
logger.info('Info message')- Enable/disable global logging:
pype pype.config logger enable/disable - Print current configuration:
pype pype.config logger print-config - Set logging folder:
pype pype.config logger set-directory /your/login/folder - Set logging level:
pype pype.config logger set-level DEBUG - Set logging pattern:
pype pype.config logger set-pattern "%(asctime)s %(levelname)s %(name)s %(message)s"
If your plugin contains shared code over all pypes you can simply put it into a subpackage of your plugin or into a file prefixed with __, e.g., __commons__.py. pype-cli will only scan / consider top-level Python scripts without underscores as pypes.
pype-cli has been built around the Click-project ("Command Line Interface Creation Kit") which is a Python package for creating beautiful command line interfaces. To fully utilize the capabilities of pype-cli it is highly recommended to get familiar with the project and use it in your pypes as well.
- Run
make venvto create a new virtual environment - Run
pipenv shellto activate a local shell with the required configurations - Run
pypeto operate locale development version (it will react to code changes) - Run
PYPE_BENCHMARK_INIT=1 pypeto print loading times for individual plugins or pypes
- Switch to latest
mainbranch after making sure it is stable - Get latest changelog via
make changelogand updateCHANGELOG.md - Run
NEXT_VERSION=0.0.3 make release - Trigger Github action to release to PyPi
This software is licensed under Apache License 2.0.
Icon made by Freepik from Flaticon is licensed by CC 3.0 BY.
