TensorShareServer
The TensorShareServer
schema defines the server configuration that will receive the tensors from any client.
It will be used by the TensorShareClient
for sending tensors over the network.
Schema
The schema inherits from the pydantic.BaseModel
class and has the following properties:
-
url
: The URL of the server. This is the URL that the client will use to connect to the server. It should be a valid URL, including the protocol (e.g.http://localhost:5000
orhttps://example.com
). -
ping
: The path to the health-check endpoint. This is the path that the client will use to check if the server is available. It should be a valid string, without the leading slash (e.g.ping
orhealthcheck
). It will beping
by default. -
receive_tensor
: The path to the endpoint receiving the tensor. This is the path that the client will use to send the tensor to the server. It should be a valid string without the leading slash (e.g.receive_tensor
ortensors
). It will bereceive_tensor
by default. -
response_model
: The response model that the server will return to the client. It should be a subclass ofBaseModel
from Pydantic. It will beDefaultResponse
by default, a simple model returning amessage
string.
Create a config - from_dict
The from_dict
method creates a TensorShareServer
config from a dictionary.
from tensorshare import DefaultResponse, TensorShareServer
config = TensorShareServer.from_dict(
server_config={
"url": "http://localhost:5000", # required
"ping": "ping", # optional
"receive_tensor": "receive_tensor", # optional
"response_model": DefaultResponse, # optional
}
)
print(config)
# url=Url('http://localhost:5000/')
# ping=Url('http://localhost:5000/ping')
# receive_tensor=Url('http://localhost:5000/receive_tensor')
# response_model=<class 'tensorshare.schema.DefaultResponse'>
The url
, ping
and receive_tensor
properties leverage the HttpUrl
type from Pydantic. This means that they will be validated and normalized at runtime.
Use the config
Like any pydantic
model, you can use the config as a standard Python class object.
config.url
>>> Url('http://localhost:5000/')
config.ping
>>> Url('http://localhost:5000/ping')
config.receive_tensor
>>> Url('http://localhost:5000/receive_tensor')
config.response_model
>>> <class 'tensorshare.schema.DefaultResponse'>
You can also get the URL as a string or some parts of it.
str(config.url)
>>> 'http://localhost:5000/'
config.url.scheme
>>> 'http'
config.url.host
>>> 'localhost'
config.url.port
>>> 5000
config.url.path
>>> '/'
Created: 2023-08-20