A services registry
A simple service registry for use within HIS, but useful elsewhere.
Services registered must extend an abstract base class, which acts as a contract or interface.
Services should be defined as follows
import abc class ExampleContract(metaclass=abc.ABCMeta): @abc.abstractmethod def method(self): pass class ExampleService(ExampleContract): def method(self): print("I'm an example")
Then register an instance of the service:
from almanac import services s = ExampleService() services.register(s)
Finally, to retrieve a registered service you need to use the contract:
from almanac import services s = services.get(ExampleContract)
Errors and Exceptions
If you try to register an object as a service which does not have an abstract parent then it will raise an InvalidServiceType exception.
Attempting to get a service which has not been registered will raise a ServiceNotFoundError exception.
Attempting to get a service with anything other than an abstract base class (e.g. the contract) will result in the system raising an InvalidContract exception
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size his.almanac-0.0.1.tar.gz (3.0 kB)||File type Source||Python version None||Upload date||Hashes View hashes|