from abc import ABC, abstractmethod from fastapi import Request, Response class Blackbox(ABC): """Blackbox class that provides a standard way to create an blackbox class using inheritance. All blackbox classes should inherit from this class and implement the methods processing, valid and fast_api_handler. If implemented correctly, the blackbox class can be used in the main.py file """ def __init__(self, *args, **kwargs): pass """ processing method should return the processed data. The data is passed as an argument to the method. All processing shouldn't interaction with the disk but dist / list / string / bytes / io.BytesIO or other data type that in memory. Output same as above. """ @abstractmethod async def processing(self, *args, **kwargs): pass """ valid method should return True if the data is valid and False if the data is invalid """ @abstractmethod def valid(self, *args, **kwargs) -> bool: pass """ fast_api_handler method should return a fastapi Response object. This method is used to handle the request from the fastapi server. The request object is passed as an argument to the method. """ @abstractmethod async def fast_api_handler(self, request: Request) -> Response: pass @abstractmethod def __call__(self, *args, **kwargs): pass