Skip to main content

Library allows you to build and connect external processors & connectors to Seventech Integra product

Project description

Integra bridge

pip install integra-bridge

Allows you to move the business logic of complex services outside of Integra. Under the hood, interaction with Integra is carried out using the HTTP protocol based on REST FastAPI.

Bridge - base class responsible for assembling services.

Params:
- title string - input title of service;
- address string | None - address of service location;
- description string | None - address of service location;
- manual_path string | Pathlike - Path to manual file;

To map external URLs to local ones when writing handlers,
use the variable URL_PATH_MAPPER, which must be set via a variable in the environment of your service in the form of a serializable JSON string.

Minimal example of data handler implementation:

from integra_bridge import Bridge
from integra_bridge.adapters import ProcessorAdapter
from integra_bridge.dto import SkeletonProcessor, ProcessorView


class SimpleProcessor(ProcessorAdapter):
    async def execute(self, body: dict, params: dict) -> dict:
        body['hello'] = 'world'
        return body

    async def get_view(self) -> ProcessorView:
        skeleton = SkeletonProcessor()
        return ProcessorView(
            title="Simple processor",
            description="",
            skeleton=skeleton
        )
        
bridge = Bridge(
    title='My service',
    address='Moscow',
    description='For demo',
    manual_path=Path(__file__).parent / 'manual.pdf'
)

bridge.register_handlers([SimpleProcessor])

application = bridge.build()

if __name__ == '__main__':
    uvicorn.run(app="__main__:application", host='localhost', port=8000)

You can construct forms for your handler inside Integra using parameter classes and skeletons:

server_name = Parameter(
    name='server_name',
    label='Server name',
    description='',
    default_value='google.com',
    is_required=True,
    is_add_value=True,
    bottom_text='bottom_text'
)

skeleton = SkeletonProcessor(parameters=[server_name,])

Validation of form fields at Integra level:

class SimpleProcessor(ProcessorAdapter):
    async def execute(self, body: dict, params: dict) -> dict:
        body['hello'] = 'world'
        return body

    async def validate(self, processor: Processor) -> ValidationResponse:
        result = True
        params_description = {}
        if len(processor.params.get('field_to_check')) > 10:
            result = False
            params_description['field_to_check'] = ['Превышена максимальная длинна в 10 символов']
        return ValidationResponse(
            result=result,
            params_description=params_description,
        )

Example of implementation of an incoming connector using the RabbitMQ broker:

# Class for handling input broker message
class ConsumerManager:
    def __init__(self):
        self.consumers = {}

    async def create_consumer(self, queue_name: str, connection_params: dict):
        connection = await aio_pika.connect_robust("amqp://guest:guest@localhost/")
        channel = await connection.channel()
        exchange = await channel.declare_exchange(name='integra', type="fanout")
        queue = await channel.declare_queue(queue_name, auto_delete=False, durable=True)
        await queue.bind(exchange=exchange, routing_key=queue_name)
        callback = partial(self.on_message, queue_name=queue_name, connection_params=connection_params)
        consumer_tag = await queue.consume(callback, no_ack=False)
        self.consumers[queue_name] = {"connection": connection, "channel": channel, "consumer_tag": consumer_tag}
        return consumer_tag

    async def delete_consumer(self, queue_name: str, connection_params: dict):
        if queue_name in self.consumers:
            consumer = self.consumers[queue_name]
            await consumer["channel"].close()
            await consumer["connection"].close()
            del self.consumers[queue_name]

    async def on_message(self, message: AbstractIncomingMessage, queue_name, connection_params: dict) -> None:
        data = json.loads(message.body.decode('utf-8'))
        send_status = await ConnectorAdapter.push_to_integra(
            input_body=data,
            connect_to_block_id=queue_name
        )
        if send_status in (200, 201):
            await message.ack()

#Connector form parametrs
server_name = Parameter(
    name='server_name',
    label='Server name',
    is_required=True,
    is_add_value=True,
)
url = Parameter(
    name='url',
    label='url',
    is_required=True,
    is_add_value=True,
)

class SimpleInputConnector(ConnectorAdapter):
    async def get_view(self) -> ConnectorView:
        skeleton_connector = SkeletonConnector(type_connect='input', parameters=[server_name, url, ])
        return ConnectorView(
            title="Simple input connector",
            input_description="description",
            skeleton_input_connect=skeleton_connector
        )

    async def on_after_deploy(self, connection_id: str, connector_params: dict):
        await consumer_manager.create_consumer(connection_id, connector_params)

    async def on_after_destroy(self, connection_id: str, connector_params: dict):
        await consumer_manager.delete_consumer(connection_id, connector_params)

Project details


Download files

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

Source Distribution

integra_bridge-0.2.5.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

integra_bridge-0.2.5-py3-none-any.whl (32.2 kB view details)

Uploaded Python 3

File details

Details for the file integra_bridge-0.2.5.tar.gz.

File metadata

  • Download URL: integra_bridge-0.2.5.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.4 Windows/11

File hashes

Hashes for integra_bridge-0.2.5.tar.gz
Algorithm Hash digest
SHA256 80fd7a9d13caa5680c6755b55c913e7c3dcc3fd53ba9c0e210d4b33740b5e437
MD5 72734d47a527afee2315ffbb11664cf9
BLAKE2b-256 71646ed3b8038d9d4a21fb43fb3f0de32bd7028b4425f86f613cb31d5a4cbd29

See more details on using hashes here.

File details

Details for the file integra_bridge-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: integra_bridge-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 32.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.4 Windows/11

File hashes

Hashes for integra_bridge-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b6ff179dd0e15733f69333057894385344b135083b503fc94252c988496d048c
MD5 54d65d6bf5d9b80a0569edb87eeb8c6d
BLAKE2b-256 1fb9ca4e8c67d043caea57c567b11098ebfe0c12b71e1aca1ef0b870c671632c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page