finos / symphony-bdk-python

Symphony Python Bot Development Kit (BDK)
https://symphony-bdk-python.finos.org/
Apache License 2.0
31 stars 34 forks source link

Extension mechanism #268

Closed symphony-mariacristina closed 2 years ago

symphony-mariacristina commented 2 years ago

Description

The Extension API is available through the module symphony.bdk.core.extension. Extensions are registered programmatically via the ExtensionService. A Service Provider extension is a specific type of extension loaded on demand when calling the ExtensionService#service(MyExtensionType) method.

To make your extension Service Provider, your extension definition must implement the method get_service(self).

# Usage example.
async def run():
    config = BdkConfigLoader.load_from_symphony_dir("config.yaml")
    async with SymphonyBdk(config) as bdk:
        extension_service = bdk.extensions()
        extension_service.register(MyBdkExtensionService)
        service = extension_service.service(MyBdkExtensionService)
        service.say_hello("Symphony")

asyncio.run(run())

BDK Aware Extensions

The BDK Extension Model allows extensions to access to some core objects such as the configuration or the api clients. Developers that wish to use these objects are free to implement a set of abstract base classes all suffixed with the Aware keyword. List of Aware classes:

symphony-elias commented 2 years ago

@symphony-mariacristina should we document how to leverage the retry mechanism in extensions? I would say so because it differs much from the Java BDK

symphony-elias commented 2 years ago

Implements #251