Skip to content

Servers and clients

serve

serve(
    algorithm: Union[Algorithm, MultiAlgorithm, Callable],
    *args,
    **kwargs,
) -> None

Serve an algorithm, algorithm collection, or plain Python function over HTTP.

Starts a FastAPI server (with uvicorn) and blocks until it is stopped. Run it from a Python script, not from a Jupyter notebook.

Parameters:

Name Type Description Default
algorithm Algorithm, MultiAlgorithm, or callable

The algorithm or collection to serve. A plain Python function is converted to an algorithm.

required
*args

Passed to the server: host (default "0.0.0.0", all network interfaces) and port (default 8000).

()
**kwargs

Passed to the server: host (default "0.0.0.0", all network interfaces) and port (default 8000).

()

Examples:

>>> if __name__ == "__main__":
...     sk.serve(threshold_algo, port=8000)

Client

Client(
    server_url: Optional[str] = None, name: str = "client"
)

Bases: AlgorithmRunner

Client to connect to algorithm servers.

A client implements the shared AlgorithmRunner interface, so the same code can run an algorithm locally or on a server. Computations requested with run() are executed on the server.

Parameters:

Name Type Description Default
server_url str

Address of the algorithm server, e.g. "http://localhost:8000". If provided, the client connects to the server immediately.

None
name str

A name identifying the client.

"client"

Attributes:

Name Type Description
server_url str

Address of the algorithm server.

algorithms list of str

The names of the algorithms available on the server.

Examples:

>>> client = sk.Client("http://localhost:8000")
>>> results = client.run(image, threshold=100)

connect

connect(server_url: str) -> None

Connect to an algorithm server and list its algorithms.

Parameters:

Name Type Description Default
server_url str

Address of the algorithm server, e.g. "http://localhost:8000".

required

The other methods of clients are described in the shared interface.