Skip to main content

A package to manage and execute Python operations.

Project description

PythonScriptOperations

PyPI

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, a similar library for C# console applications.

Quick Start

  1. Import the pip package:

    import pythonscriptoperations
    
  2. Create a function or async function and register it:

    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:

    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:

pip install pythonscriptoperations

Then, simply import pythonscriptoperations wherever you need it.

2. Define 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:

def example_function():
    print("This is an example.")

register_operations(example_function, "An example operation")

3. Register your operations

You can register multiple operations at once:

def operation1():
    pass

def operation2():
    pass

register_operations(operation1, "Description for operation1")
register_operations(operation2, "Description for operation2")

4. Start listening

Start the listener to display available operations and accept user input:

start_listening_async()

For synchronous setups, you can use:

start_listening()

5. 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.

Project details


Download files

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

Source Distribution

pythonscriptoperations-0.1.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

pythonscriptoperations-0.1.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file pythonscriptoperations-0.1.1.tar.gz.

File metadata

File hashes

Hashes for pythonscriptoperations-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8f57becf93e2a4015ada8c0e68e174ba79eea002c9fa0716ba9e4600dfdeed62
MD5 39a2421668cf176cad7c3abaf0fdd4cb
BLAKE2b-256 2456945fad72528c2f61c048309dec77cfd47a26d36e7a66ebab2b42515b89c6

See more details on using hashes here.

File details

Details for the file pythonscriptoperations-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pythonscriptoperations-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0e792c84238ef56c61f2069c2ab74447843305f26235e3b2e858062b4e1eedd3
MD5 e675f153cd9be33829ab3d77f1732e88
BLAKE2b-256 9b7461cfa77c50cee8d9c3d67dadf338df1ff87710609368414ff78d385c26a8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page