Skip to main content

Basic Console Listener for General Use

Project description

Github


PYPI

Downloads Downloads Downloads


Discord

Discord


EasyCommandInterface

Sometimes running a project like flask or a discord bot will remove the flexibility of using console to send commands, This library will revive that with just a simple setup.

How to install

To install just use following command

pip install EasyCommandInterface

If you are looking for latest beta/alpha, you can use following command

pip install --upgrade git+https://github.com/Ashenguard/EasyCommandInterface.git

Example

from EasyCommandInterface import CommandInterface

# Only one Interface is allowed, If you try to create another one CommandInterfaceError will be raised.
interface = CommandInterface()


# A simple command, All the arguments are passed as string.
# Example input: test 1 Hi "Hello World!"
# Result: TEST COMMAND: ('1', 'Hi', 'Hello world!')
@interface.command('test')
def _test(*args):
    print('TEST COMMAND:', args)


# Another command with fixed arguments! If 2 arguments is not passed, It will raise CommandExecutionError
# Example input: sum 5 5.5
# Result: 10.5
@interface.command('sum')
def _sum(a, b):
    print(float(a) + float(b))


# As default, All commands will be executed inside a separate thread, But if you set `thread` to `False`, Command will be executed inside the interface thread
# Example input: sleep
# Result: Nothing - Except for that the interface will not accept another command before this one ends.
@interface.command('sleep', thread=False)
def _sleep(*args):
    from time import sleep

    sleep(10)

# There is a known issue (Fetal Python Error) when the program ends if the interface is waiting for another command.
# So we recommend using the `stop` method inside a not threaded command to stop the input thread as soon as it receives the command.
# Calling this method outside will stop the thread AFTER it received another command.
@interface.command('exit', thread=False)
def _exit():
    interface.stop()

# To start the interface, just say START! 
interface.start()

# Since the interface will read all inputs as soon as it starts, If you need an input just use following method. Using `input` might not work as intended
value = interface.get_input('Input something: ')
print("Input received:", value)

# You should keep the program alive since as soon as main program ends, Interface will be closed.
# You can use other projects like a flask or discord bot or ... instead
while interface.is_alive():
    pass

❗ There will be more tutorials and examples at Wiki

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

EasyCommandInterface-1.0.0.tar.gz (4.9 kB view hashes)

Uploaded Source

Built Distribution

EasyCommandInterface-1.0.0-py3-none-any.whl (5.4 kB view hashes)

Uploaded Python 3

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