https://github.com/notcoffee418/pythonscriptoperations
Python version of CSharpScriptOperations
https://github.com/notcoffee418/pythonscriptoperations
Last synced: over 1 year ago
JSON representation
Python version of CSharpScriptOperations
- Host: GitHub
- URL: https://github.com/notcoffee418/pythonscriptoperations
- Owner: NotCoffee418
- License: mit
- Created: 2023-08-08T19:20:17.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-09T19:54:44.000Z (almost 3 years ago)
- Last Synced: 2025-02-24T10:49:37.120Z (over 1 year ago)
- Language: Python
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PythonScriptOperations
[](https://pypi.org/project/pythonscriptoperations/)
## What is it?
`PythonScriptOperations` is a library for Python console applications to quickly set up a console application interface. Developers can utilize it to swiftly access specific portions of their codebase by registering operations.
It is the brother to [CSharpScriptOperations](https://github.com/NotCoffee418/CSharpScriptOperations), a similar library for C# console applications.
## Quick Start
1. **Import the pip package**:
```python
from pythonscriptoperations import register_operation, start_listening, start_listening_async
```
2. **Create a function or async function and register it**:
```python
def add_numbers():
result = 2 + 2
print(f"2 + 2 = {result}")
register_operations(add_numbers, "Print the result of 2+2")
```
3. **Start listening for operations**:
```python
start_listening()
```
## What does it look like?
This is an example taken from the `demo.py`.
```
Available operations:
0. Exit
1. Addition: 5 + 7
2. Subtraction: 12 - 4
3. Multiplication (async): 6 * 3
4. Division: 36 / 6
Select an operation ('help' for list of operations)
1
Running operation: Addition: 5 + 7
12
Done
```
## Detailed Instructions
### 1. Install the pip package
Install the pip package using:
```bash
pip install pythonscriptoperations
```
Then, simply `import pythonscriptoperations` wherever you need it.
### 2. Register your operations
Operations are simple Python functions (or async functions) dedicated to specific tasks.
To provide a description, simply pass it when registering the function:
```python
def example_function():
print("This is an example.")
async def example_async_function():
print("This will be awaited")
await asyncio.sleep(1000)
register_operations(example_function, "An example operation")
register_operations(example_async_function, "An example async operation")
```
### 3. Start listening
Start the listener to display available operations and accept user input:
```python
start_listening()
```
If you need the console to be non-blocking, you can use the async version:
```python
start_listening_async()
```
### 4. Try it out
When you run your script, you should see a list of operations with numbers next to them. To execute an operation, simply input its number.
### Example
For a complete working example, refer to the `demo.py` in the repository.