Install a Library or Service

Easily install TinyChain services on your host or cluster without restarting

Arguably TinyChain's most powerful feature is the ability to install a Library or Service at runtime without restarting. For example, TinyChain's linear algebra and machine learning services are distributed as part of the Python client (math.linalg.LinearAlgebra, ml.NeuralNets, and ml.Optimizers). Installing them is as easy as:

import tinychain as tc

# the lead replica (can be a load balancer)
LEAD = tc.URI("http://your.tinychain.cluster")

host = tc.Host(LEAD)
host.install(tc.math.linalg.LinearAlgebra())

Install your Service

Of course the built-in Services aren't much use without being able to install your own!

# ...

class MyService(tc.service.Service):
    NS = "my_namespace"
    NAME = "my_service"
    VERSION = tc.Version("0.0.0")

    __uri__ = tc.service.service_uri(LEAD, NS, NAME, VERSION)

    @tc.get
    def hello(self, name: tc.String) -> tc.String:
        return tc.String("Hello, {{name}}!").render(name=name)


assert tc.URI(MyService).path() == "/service/my_namespace/my_service/0.0.0"

host.install(MyService())

assert host.get(tc.URI(MyService()).path() + "/hello", "World") == "Hello, World!"

Last updated