Skip to content

pythonic-emacs/service-factory

Repository files navigation

service-factory

Build Status Coverage Status Requirements Status Code Health

JSON RPC service factory for Python.

Usage

Service factory in a nutshell:

from service_factory import service_factory

def add(one, two):
    """Add two numbers."""
    return one + two

def mul(one, two):
    """Multiply two numbers."""
    return one * two

app = [add, mul]

if __name__ == '__main__':
    service_factory(app, host='localhost', port=0)

Run this as usual python file:

$ python calc.py
service factory starts at port 9001

See it works:

$ curl -X POST -d '{"jsonrpc": "2.0", "method": "add", "params": [1, 2], "id": 1}' -H 'Content-Type:application/json;' http://localhost:9001/

You can use any callable list from arbitrary module to run your application:

$ python -m service_factory calc:app --host=localhost --port=auto
# or
$ service_factory calc:app --host=localhost --port=auto

TODO

  • process all errors codes
  • batch processing
  • notifications
  • WSGI provider
  • tornado provider
  • aiohttp provider
  • --port-file option
  • console entry point
  • make providers act as context managers
  • user_error(code, message, data=None)
  • WSGI authorization
  • sphinx docs
  • Django user permissions for rpc method
  • Celery service implementation
  • RQ service implementation