Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/claymcleod/psme
- Owner: claymcleod
- License: mit
- Created: 2021-11-30T00:26:10.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-11-30T00:45:24.000Z (about 3 years ago)
- Last Synced: 2024-12-21T16:23:17.800Z (about 2 months ago)
- Language: Python
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
psme
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 Adde = 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 BaseSubcommandclass 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