diff --git a/src/pydase/client/client.py b/src/pydase/client/client.py index 39543d1..079aca6 100644 --- a/src/pydase/client/client.py +++ b/src/pydase/client/client.py @@ -6,8 +6,8 @@ from typing import TypedDict, cast import socketio # type: ignore -import pydase.components -from pydase.client.proxy_loader import ProxyClassMixin, ProxyLoader +from pydase.client.proxy_class import ProxyClass +from pydase.client.proxy_loader import ProxyLoader from pydase.utils.serialization.deserializer import loads from pydase.utils.serialization.types import SerializedDataService, SerializedObject @@ -34,47 +34,6 @@ def asyncio_loop_thread(loop: asyncio.AbstractEventLoop) -> None: loop.run_forever() -class ProxyClass(ProxyClassMixin, pydase.components.DeviceConnection): - """ - A proxy class that serves as the interface for interacting with device connections - via a socket.io client in an asyncio environment. - - Args: - sio_client: - The socket.io client instance used for asynchronous communication with the - pydase service server. - loop: - The event loop in which the client operations are managed and executed. - - This class is used to create a proxy object that behaves like a local representation - of a remote pydase service, facilitating direct interaction as if it were local - while actually communicating over network protocols. - It can also be used as an attribute of a pydase service itself, e.g. - - ```python - import pydase - - - class MyService(pydase.DataService): - proxy = pydase.Client( - hostname="...", port=8001, block_until_connected=False - ).proxy - - - if __name__ == "__main__": - service = MyService() - server = pydase.Server(service, web_port=8002).run() - ``` - """ - - def __init__( - self, sio_client: socketio.AsyncClient, loop: asyncio.AbstractEventLoop - ) -> None: - super().__init__() - pydase.components.DeviceConnection.__init__(self) - self._initialise(sio_client=sio_client, loop=loop) - - class Client: """ A client for connecting to a remote pydase service using socket.io. This client diff --git a/src/pydase/client/proxy_class.py b/src/pydase/client/proxy_class.py new file mode 100644 index 0000000..287d33c --- /dev/null +++ b/src/pydase/client/proxy_class.py @@ -0,0 +1,50 @@ +import asyncio +import logging + +import socketio # type: ignore + +import pydase.components +from pydase.client.proxy_loader import ProxyClassMixin + +logger = logging.getLogger(__name__) + + +class ProxyClass(ProxyClassMixin, pydase.components.DeviceConnection): + """ + A proxy class that serves as the interface for interacting with device connections + via a socket.io client in an asyncio environment. + + Args: + sio_client: + The socket.io client instance used for asynchronous communication with the + pydase service server. + loop: + The event loop in which the client operations are managed and executed. + + This class is used to create a proxy object that behaves like a local representation + of a remote pydase service, facilitating direct interaction as if it were local + while actually communicating over network protocols. + It can also be used as an attribute of a pydase service itself, e.g. + + ```python + import pydase + + + class MyService(pydase.DataService): + proxy = pydase.Client( + hostname="...", port=8001, block_until_connected=False + ).proxy + + + if __name__ == "__main__": + service = MyService() + server = pydase.Server(service, web_port=8002).run() + ``` + """ + + def __init__( + self, sio_client: socketio.AsyncClient, loop: asyncio.AbstractEventLoop + ) -> None: + super().__init__() + pydase.components.DeviceConnection.__init__(self) + self._initialise(sio_client=sio_client, loop=loop)