Sovereign provides a ConfigDeserializer
class that can be subclassed.
As an example let's make a msgpack
deserializer
1 2import msgpack from typing import Any from sovereign.dynamic_config.deser import ConfigDeserializer class Msgpack(ConfigDeserializer): def deserialize(self, input: Any) -> Any: return msgpack.unpackb(input)
The following script adds your Python module to the list of available deserializers, which Sovereign checks at runtime:
1 2from setuptools import setup, find_packages setup( name='my_deser_plugin', packages=find_packages(), entry_points={ "sovereign.deserializers": [ "msgpack = my_deser_plugin.deser:Msgpack", ] } )
This will install the above Python module into an entry point named sovereign.deser
,
with a name of msgpack
You'll need to install the package on the same machine or container where you've installed sovereign, otherwise it won't be able to access the entry point when it starts.
Run python setup.py install
and you should see output similar to the following:
1 2$ python setup.py install TODO: show expected output
Using the name specified in the entry points, you can refer to your new plugin in template context:
1 2template_context: context: my_api_backend: protocol: 'https' serialization: 'msgpack' path: 'mydata.server.internal'
Rate this page: