Skip to main content

A simple python framework for creating a looping application (Service).

Project description

loopie

This python framework is to provide a skeleton for managing a looping mainthread, with the ability of spawning childern threads that either loop of just do any other code and exit.

The project is designed to create a commandline application to loop through a custom python code while creating a skeleton for each project similar to the Arduino sketch code; meaning, for a loop to run there should be a loop_setup routine and a loop_logic routine that will be called on every loop.

One of the main uses of this project is to create a startup script (systemd) on a Raspberry Pi 2/3 that will run your custom python application, for example, to interact with the GPIO pins from the very start of the Pi.

To interact with the mainloop, the framework features a built-in WSGI application (which is based on Flask) and a wsgiserver which act as a simple UI for the mainloop at http://localhost:8000/. In addition, a JSON RPC (Flask-JSONRPC) service is added to the WSGI app to enable creating JSON APIs for your service. By default, the url for the api service is preappend with http://localhost:8000/api/ and include a browsable api page found here http://localhost:8000/api/browse/.

This web server is enabled by default but can be disabled. Additionally, you can use the included WSGI application to attach to any other server that supports WSGI.

This package is written in Python 3.

Installation

The best option to install is through pip by running the command:

pip install loopie

or

sudo pip install loopie

Example

import loopie

class MyMain(loopie.MainLoop):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.i = 0
    
    def loop_logic(self):
        self.i += 1
        print(self.i)
    
    def importRoutes(self):
        # You can override this method to import the route file or create your on url routes
        super().importRoutes()
        @self.web_app.route('/hello')
        def hello(**kwargs):
            return 'Hello from overridden importRoutes()'

if __name__ == '__main__':
    main = MyMain(name='main', enable_web_browsable_api=True)
    app = loopie.Application(main)
    main.importRoutes()
    
    @main.json_rpc.method('core.MyLoop(uuid=String) -> Object')
    def MyLoop(**kwargs):
        uuid = kwargs.pop('uuid', 'no uuid')
        return dict(app='loopie_test', status='running', i=main.i, uuid=uuid)
    
    app.start()
    print('application ended')

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

loopie-0.2.3.tar.gz (26.0 kB view details)

Uploaded Source

File details

Details for the file loopie-0.2.3.tar.gz.

File metadata

  • Download URL: loopie-0.2.3.tar.gz
  • Upload date:
  • Size: 26.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2

File hashes

Hashes for loopie-0.2.3.tar.gz
Algorithm Hash digest
SHA256 6c5f05e68ec0d7699bcbcfd88d4a1c3ad22935bfe9068eedb6e3eb6ccb19fda9
MD5 c862a1435f6ce897559ab6849869ceae
BLAKE2b-256 f13c1a92e514dd55c537d8b995c0e9c1b63a60c3ae78e8c8c9f1838633b99f35

See more details on using hashes here.

Supported by

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