Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/claymcleod/psme

Python subcommands made easy.
https://github.com/claymcleod/psme

Last synced: about 4 hours ago
JSON representation

Python subcommands made easy.

Awesome Lists containing this project

README

        



psme



Actions: CI Status


PyPI


PyPI: Downloads


Code Coverage


License: MIT


Python subcommands made easy.



See the example »




Request Feature
·
Report Bug
·
⭐ Consider starring the repo! ⭐


## 🎨 Features

* Project Structure. Salient project structure to build small to large command line applications with many subcommands.
* Easy to understand and implement. Best practices for implementing subcommands for free (almost!).

## 📚 Getting Started

### Installation

#### Python Package Index

If you're using [poetry] (recommended), you can easily add `psme` as a dependency to your command line application.

```bash
poetry add psme
```

You can also install `psme` using the Python Package Index ([PyPI](https://pypi.org/)).

```bash
pip install psme
```

## 🚌 A Quick Tour

At its foundation, `psme` is meant to make it easy to design and implement command line tools with multiple subcommands. Commonly, you will want to use it to create multiple subcommands and run the command line engine to distinguish between them and run the correct one.

In your main package, you can do something like the following:

```python
from psme.engine import Engine
from .subcommands.add import Add

e = Engine('psme-example', [Add()],
description="Python subcommands made easy tutorial.")
e.run()
```

Assuming you have a directory in your Python package for subcommands, and `Add` subcommand may look like this:

```python
from psme.subcommand import BaseSubcommand

class Add(BaseSubcommand):
def name(self):
return "add"

def register_args(self, subparser):
subparser.add_argument("operand_one", type=int, help="First operand to add together.")
subparser.add_argument("operand_two", type=int, help="Second operand to add together.")

def run(self, args):
print(f"{args.get('operand_one')} + {args.get('operand_two')} = {args.get('operand_one') + args.get('operand_two')}")
```

For more information, please see [the example application](https://github.com/claymcleod/psme-example).

## 🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/claymcleod/psme/issues). Please ensure you fill out the entire template for each of these. You can also take a look at the [contributing guide][contributing-md].

## 📝 License

Copyright © 2021 Clay McLeod. This project is [MIT][license-md] licensed.

[poetry]: https://python-poetry.org/
[contributing-md]: https://github.com/claymcleod/psme/blob/main/CONTRIBUTING.md
[license-md]: https://github.com/claymcleod/psme/blob/main/LICENSE.md