Core API¶
This page documents the core functions and classes of the Skarv package.
Classes¶
skarv.Sample
dataclass
¶
A data sample consisting of a key expression and its associated value.
Attributes:
Name | Type | Description |
---|---|---|
key_expr |
KeyExpr
|
The key expression associated with the sample. |
value |
Any
|
The value of the sample. |
Source code in skarv/__init__.py
skarv.Subscriber
dataclass
¶
A subscriber that listens to updates for a specific key expression.
Attributes:
Name | Type | Description |
---|---|---|
key_expr |
KeyExpr
|
The key expression to subscribe to. |
callback |
Callable[[Any], None]
|
The callback function to invoke when a matching sample is published. |
Source code in skarv/__init__.py
skarv.Middleware
dataclass
¶
A middleware operator that processes values for a specific key expression.
Attributes:
Name | Type | Description |
---|---|---|
key_expr |
KeyExpr
|
The key expression the middleware applies to. |
operator |
Callable[[Any], Any]
|
The operator function to process the value. |
Source code in skarv/__init__.py
Functions¶
skarv.put(key: str, value: Any)
¶
Store a value for a given key, passing it through any registered middlewares and notifying subscribers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The key to associate with the value. |
required |
value
|
Any
|
The value to store. |
required |
Source code in skarv/__init__.py
skarv.subscribe(*keys: str)
¶
Decorator to subscribe a callback to one or more keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*keys
|
str
|
One or more keys to subscribe to. |
()
|
Returns:
Name | Type | Description |
---|---|---|
Callable |
A decorator that registers the callback as a subscriber. |
Source code in skarv/__init__.py
skarv.get(key: str) -> List[Sample]
¶
Retrieve all samples whose keys intersect with the given key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The key to search for. |
required |
Returns:
Type | Description |
---|---|
List[Sample]
|
List[Sample]: A list of matching samples. |
Source code in skarv/__init__.py
skarv.register_middleware(key: str, operator: Callable[[Any], Any])
¶
Register a middleware operator for a given key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The key to associate with the middleware. |
required |
operator
|
Callable[[Any], Any]
|
The operator function to process values. |
required |