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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file EasyCommandInterface-1.0.0.tar.gz.

File metadata

  • Download URL: EasyCommandInterface-1.0.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.27.1 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.6

File hashes

Hashes for EasyCommandInterface-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c53d8954ff6de648b862532f66e3fe96d7ff87b69ce6b78e435efce137b75eb9
MD5 30c18f029ea9e93c0f3c81b202fc0178
BLAKE2b-256 4230e7d55d4906d2fdc6a98db64835cc2bf870620f0dba8c078318d36d6efdbc

See more details on using hashes here.

File details

Details for the file EasyCommandInterface-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: EasyCommandInterface-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.27.1 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.6

File hashes

Hashes for EasyCommandInterface-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a63a913c51b06e64e68870b0fac211b40fb37fab1ad9ab5bc5b0ec164a98e3ee
MD5 ad68fd198b3d6bfadcf757426039b73a
BLAKE2b-256 06a42239da159f1115f42430aec2a094c908508fe70862e38bbba15b31081323

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