I am working as a summer intern at a fairly large company, me and another intern has been tasked with writing a background service from scratch in python(with given specifications). I can't say that I am a Python expert but I try to write as good code as possible and follow good practice. To the describe the service in a easy way it receives messages from a buss (amqp atm) and matches them against a patterns and preform actions depending on the pattern, all this is configurable from a json file.
To get down to the point, the service is suppose to be general and therefore a developer should be able to add different inputs and outputs classes. This is the structure I have right now.
- service.py
- input
- __init__.py (Includes all .py files in the __all__ variable)
- base.py
- amqp.py
service.py
from input import *
import input
#use input.base.sources
input\base.py
sources = {}
def register_input(cls):
sources[cls.input_name] = cls
return cls
class InputBase(object):
action(self, params):
...
input\amqp.py
@register_input
class AmqpInterface(InputBase):
input_name = "amqp"
action(self, params):
...
This works, but it doesn't look very nice and it also creates problems with include orders. Neither I nor the senior developer could think of a more pythonic way of solving this. Do you have any ideas how to solve this problem in a more elegant way?