Git Product home page Git Product logo

spika's Introduction

Overview

Tiny Python context manager implementing a simple command protocol over pipes (e.g no deep binding/integration required) The data is serialized as json and arbitrary payload can be attached to the commands (and returned in the responses). Use it whenever you want to use python code to drive a project that is not python, typically to automate testing or maybe prepare some input, coordinate with remote systems, mock a quick REST front-end, etc. The manager will spawn the specified subprocess and read/write to its stdin/stdout. Any unexpected process exit will raise an exception and commands can be issued either in blocking mode or with a timeout.

The receiving process (e.g what's being "driven") must of course do its part and read its stdin. Any json snippet terminated by \n should be considered and a response potentially written back (still as json) to its stdout. The command layout is as follows:

{
    "tag": <unique integer sequence>
    "cmd": <arbitrary label>
    "ext": <optional free-form json object>
}

The "ext" sub-object represents some optional free-form payload, both from the request and response point of view. The response must include the same tag plus the "ext" sub-object (which may be then set to whatever payload you wish to return back). A few simple use-cases:

    try: 
      with driven('/usr/local/bin/my-stuff') as proxy:
        proxy.ask('do something')
        reply = proxy.ask('configure', ext={'foo': 'bar'})
        if proxy.ask('shutdown', timeout=5.0) is None:
          raise Exception('unable to terminate gracefully within 5 seconds')
    except BadExit:
      print 'abnormal process exit' 

You can simply install this package via pip/git:

$ pip install git+https://github.com/opaugam/spika 

Samples

A trivial Go snippet is provided to illustrate how the stuff works in conjunction with a tiny control script. Just build and try it out:

$ cd samples/go
$ go build snippet.go
$ python runme.py

Support

Contact [email protected] for more information about this project.

spika's People

Stargazers

Stuart Axon avatar

Watchers

Olivier Paugam avatar Lillio Mok avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.