server

create_controller_server

create_controller_server(
   controller: Controller,
   prepend_method_group: bool,
   api_keys: Optional[List[str]]
) -> FastAPI

Get the controller server instance.

Arguments: - controller (Controller): The controller to get the server for.

Returns: FastAPI: The controller server instance.


from ctrlstack import ctrl_cmd_method, ctrl_query_method, ctrl_method

class FooController(Controller):
    @ctrl_cmd_method
    def bar(self):
        pass
    
    @ctrl_query_method
    def baz(self, x: int) -> str:
        pass
    
    @ctrl_method(ControllerMethodType.QUERY, "q")
    def qux(self):
        pass
    
app = create_controller_server(FooController())
assert _is_port_free(_find_free_port())

start_local_controller_server_process

start_local_controller_server_process(
   controller: Controller|Callable[[], Controller],
   lockfile_path: str,
   port: Optional[int]
) -> Tuple[int, int, bool]

Start a local server for the given controller.

Arguments: - controller (Controller|Callable[[], Controller]): The controller or a callable that returns the controller to run. - lockfile_path (str): Path to the lockfile that stores the port and PID. - port (Optional[int]): The port to run the server on. If None, a free port will be found.


get_local_controller_server_status

get_local_controller_server_status(lockfile_path: str) -> Tuple[int, int, bool]

Get the status of the server from the lockfile.

Arguments: - lockfile_path (str): Path to the lockfile that stores the port and PID.

Returns: Tuple[int, int, bool]: A tuple containing the port number, process ID, and a boolean indicating if the server is running.


check_local_controller_server_process

check_local_controller_server_process(
   lockfile_path: str
) -> Tuple[Optional[int], Optional[int], bool]

Check if a local server process is running and return its port and PID.

Arguments: - lockfile_path (str): Path to the lockfile that stores the port and PID. - port (Optional[int]): The port to check. If None, the port from the lockfile will be used.

Returns: Tuple[Optional[int], Optional[int], bool]: A tuple containing the port number, process ID, and a boolean indicating if the server is running.


stop_local_controller_server_process

stop_local_controller_server_process(lockfile_path: str)