hulse package
Submodules
hulse.cli module
hulse.client module
- class hulse.client.Hulse(api_key: str)
Bases:
object
- query(data: Union[str, list], task: Optional[str] = None, model: Optional[str] = None, **kwargs) dict
Run an inference query on a Hulse cluster.
Note that we don’t support HF pipeline batching as of now, since all inferences are performed on CPU. HF does not recommend batching on CPU.
- Parameters
task (str) – Task to be performed. Corresponds to the model you want to use.
data (Any) – Data to be inferred upon by the target model.
- set_api_key(api_key: str)
Set the Hulse API key.
- Parameters
api_key (str) – Hulse API key to define as default configuration.
hulse.errors module
- exception hulse.errors.HulseError(status: Optional[int] = None, expression: Optional[Any] = None)
Bases:
Exception
- exception hulse.errors.UnsufficientResources(expression: Optional[Any] = None)
Bases:
Exception
- exception hulse.errors.UnsupportedTaskError(task: str, expression: Optional[Any] = None)
Bases:
Exception
hulse.settings module
- hulse.settings.get_auth_headers(api_key: str) dict
Generate HTTP headers for authentication with bearer token.
- Parameters
api_key (str) – Hulse API key.
- Returns
Headers for authentication as a dict
- Return type
dict
- hulse.settings.load_config()
Load config from CONFIG user file.
- hulse.settings.reset_config()
Reset config to default.
- hulse.settings.set_config(config: dict) bool
Store config to CONFIG user file and set it in module.
- Parameters
config (dict) – Candidate config to be set.
- Returns
Whether the config is valid.
- Return type
bool
- hulse.settings.validate_config(config: dict) bool
Make sure that the provided config is valid.
- Parameters
config (dict) – Candidate config
- Returns
Config validity result.
- Return type
bool
hulse.utils module
- class hulse.utils.HostThread(group=None, target=None, name=None, args=(), kwargs=None, *, daemon=None)
Bases:
Thread
Run a Hulse host in a separate thread.
- raise_exception(exctype)
Raise an exception within the currently running thread.
- Parameters
exctype (Exception) – Type of exception to be raised.
- class hulse.utils.LoginThread(group=None, target=None, name=None, args=(), kwargs={}, *, daemon=None)
Bases:
HostThread
- get_api_key()
Returns the current value of the thread api key.
- Returns
Api key attribute of the thread.
- Return type
str
- get_email()
Return current email
- get_username()
Return current username
- run()
Run the login server thread
- Returns
Whether the login server was started.
- Return type
bool
- hulse.utils.create_cluster(api_key: str, name: str, description: Optional[str] = None) bool
Create a new Hulse cluster.
- Parameters
api_key (str) – Hulse API key.
name (str) – Name of the cluster to be created.
description (str, optional) – Short description of the newly created cluster, defaults to None
- Returns
Whether the cluster was created.
- Return type
bool
- hulse.utils.delete_cluster(cluster_id: str, api_key: str) bool
Delete a Hulse cluster
- Parameters
cluster_id (str) – Cluster ID to delete.
api_key (str) – Hulse API key
- Raises
errors.HulseError – Error raised if the cluster could not be deleted.
- Returns
Whether the cluster was deleted or not.
- Return type
bool
- hulse.utils.edit_cluster(cluster_id: str, name: str, description: str, api_key: str) bool
Edit a Hulse cluster
- Parameters
cluster_id (str) – Cluster ID to edit.
name (str) – New name for the cluster.
description (str) – New description for the cluster.
api_key (str) – Hulse API key
- Raises
errors.HulseError – Error raised if the cluster could not be edited.
- Returns
Whether the cluster was edited or not.
- Return type
bool
- hulse.utils.get_clusters(api_key: str) list
Get all available clusters for the given account.
- Parameters
api_key (str) – Hulse API key.
- Raises
Exception – Unknown error occured while sending request to Hulse server.
- Returns
List of clusters for the given account.
- Return type
list
- hulse.utils.handle_consumer_stream(response: Response, timeout: int = 10) dict
Handle the response stream from the Hulse server when making a query.
- Parameters
response (requests.Response) – Stream request response to be handled.
timeout (int, optional) – Timeout after which should raise an error if no results received, defaults to 10
- Returns
Result returned from the Hulse server.
- Return type
dict
- hulse.utils.handle_producer_stream(response: Response, api_key: str)
Produce a stream to be sent to the Hulse server.
- Parameters
response (requests.Response) – Stream request response to be handled.
api_key (str) – Hulse API key.
- hulse.utils.join_cluster(cluster_id: str, api_key: str) bool
Join a Hulse cluster
- Parameters
cluster_id (str) – Cluster ID to join.
api_key (str) – Hulse API key
- Raises
errors.HulseError – Error raised if the cluster could not be joined.
- Returns
Whether the cluster was joined or not.
- Return type
bool
- hulse.utils.leave_cluster(cluster_id: str, api_key: str) bool
Leave a Hulse cluster
- Parameters
cluster_id (str) – Cluster ID to leave.
api_key (str) – Hulse API key
- Raises
errors.HulseError – Error raised if the cluster could not be left.
- Returns
Whether the cluster was left or not.
- Return type
bool
- hulse.utils.post_query(task: str, data: str, model: str, api_key: str) dict
Send query to server to be processed by online producers.
- Parameters
task (str) – Transformer task to be performed.
data (str) – Data to be analysed by the target model.
api_key (str) – Api key for Hulse.
- Raises
errors.UnsufficientResources – If there are no online producers.
errors.HulseError – An error occurred while communicating with the Hulse server.
- Returns
The result of the query.
- Return type
dict
- hulse.utils.process_stream_data(raw_data: str) dict
Process a block of stream data from the Hulse server.
- Parameters
raw_data (str) – Raw stream data block.
- Returns
Processed stream data block (if any).
- Return type
dict
- hulse.utils.run_host(api_key: str)
Run the Hulse host until termination.
- Parameters
api_key (str) – Hulse API key for the account.