Skip to main content

A services registry

Project description

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.

Usage

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

Project details


Release history Release notifications

This version

0.0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for his.almanac, version 0.0.1
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

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page