ochra.common.connections
api_models
- pydantic model ochra.common.connections.api_models.ObjectCallRequest
Bases:
BaseModelClass that represents a request to call a method of an object.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- field args: Dict | None = None
The arguments to be passed to the method. Defaults to None.
- field caller_id: str [Required]
The unique identifier of the caller.
- field method: str [Required]
The name of the method to be called.
- pydantic model ochra.common.connections.api_models.ObjectCallResponse
Bases:
BaseModelClass that represents a response to an object method call.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Fields:
- field return_data: Any [Required]
The data returned by the method call.
- field warnings: str = None
Any warnings generated during the method call. Defaults to None.
- pydantic model ochra.common.connections.api_models.ObjectConstructionRequest
Bases:
BaseModelClass that represents a request to construct a new object.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Fields:
- field object_json: str [Required]
The JSON representation of the object to be constructed.
- pydantic model ochra.common.connections.api_models.ObjectPropertyGetRequest
Bases:
BaseModelClass that represents a request to get a property of an object.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Fields:
- field property: str [Required]
The name of the property to be retrieved.
- pydantic model ochra.common.connections.api_models.ObjectPropertyPatchRequest
Bases:
BaseModelClass that represents a request to patch a property of an object.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Fields:
- field patch_args: Dict[str, Any] | None = None
Additional arguments for the patch operation. Defaults to None.
- field patch_type: PatchType = PatchType.SET
The type of patch to be applied. Defaults to PatchType.SET.
- field property: str [Required]
The name of the property to be patched.
- field property_value: Any [Required]
The new value to be assigned to the property.
lab_connection
- class ochra.common.connections.lab_connection.LabConnection(*args, **kwds)
Bases:
objectClass that provides a high-level interface for interacting with the lab engine API, utilizing RestAdapter for communication. This class is tightly integrated with the lab engine’s API structure.
Constructor for LabConnection class.
- Parameters:
hostname (str) – Address of lab API. Defaults to “127.0.0.1:8000”.
experiment_id (str, optional) – ID of the experiment associated with this connection. If None, a new UUID will be generated. Defaults to None.
api_key (str, optional) – API key if exists. Defaults to ‘’.
ssl_verify (bool, optional) – If we need to verify SSL. Defaults to False.
args (Any)
kwds (Any)
- Return type:
Any
- call_on_object(type, id, method, args)
Initiates a method call on a specified object within the lab engine.
- Parameters:
type (str) – The type of the object to invoke the method on.
id (UUID) – The unique identifier of the target object.
method (str) – The name of the method to execute.
args (dict) – Arguments to pass to the method.
- Raises:
LabEngineException – If the method invocation fails or the response cannot be parsed.
- Returns:
An Operation instance representing the status and result of the method call.
- Return type:
- construct_object(type, object)
Constructs an object on the lab engine.
- Parameters:
type (str) – The type of the object to construct.
object (DataModel) – The data model instance representing the object to be constructed.
- Raises:
LabEngineException – If there is an error during object construction or response parsing.
- Returns:
The unique identifier of the constructed object.
- Return type:
UUID
- delete_object(type, id)
Deletes an object from the lab engine.
- Parameters:
type (str) – The type of the object to delete.
id (UUID) – The unique identifier of the object.
- Raises:
LabEngineException – If deletion fails.
- Returns:
Response from the lab engine.
- Return type:
Any
- get_all_objects(type)
Retrieve all objects of a specified type from the lab engine.
- Parameters:
type (str) – The type of objects to retrieve.
- Raises:
LabEngineException – If retrieval or parsing fails.
- Returns:
List of instantiated objects corresponding to the specified type.
- Return type:
List[Any]
- get_data(type, id)
Retrieves raw data from a results data object in the lab engine.
- Parameters:
type (str) – The type of the object to retrieve data from.
id (str) – The unique identifier of the object.
- Returns:
The raw bytes of the object’s data.
- Return type:
bytes
- Raises:
LabEngineException – If data retrieval fails.
- get_object(type, identifier)
Retrieve an object from the lab engine by its identifier.
- Parameters:
type (str) – The type of the object to retrieve.
identifier (str | UUID) – The unique ID or name of the object.
- Raises:
LabEngineException – If the object cannot be retrieved or parsed.
- Returns:
An instance of the requested object, loaded from its data model.
- Return type:
Any
- get_object_id(type, name)
Retrieves the unique identifier (UUID) of an object from the lab engine using its name.
- Parameters:
type (str) – The type of the object to retrieve.
name (str) – The name of the object.
- Raises:
LabEngineException – If the object cannot be found or the response is invalid.
- Returns:
The unique identifier of the object.
- Return type:
UUID
- get_property(type, id, property)
Retrieves the value of a specified property from an object on the lab engine.
- Parameters:
type (str) – The type of the object.
id (UUID) – The unique identifier of the object.
property (str) – The name of the property to retrieve.
- Raises:
LabEngineException – If the property cannot be retrieved or parsed.
- Returns:
The value of the requested property, which may be a primitive, DataModel instance, list, or dict.
- Return type:
Any
- load_from_data_model(model)
Instantiates an object from a given DataModel.
- Parameters:
model (DataModel) – The data model containing class and module information.
- Raises:
LabEngineException – If the class cannot be imported or instantiated.
- Returns:
An instance of the specified class, loaded using its ID.
- Return type:
Any
- patch_property(type, id, property, value, patch_type, patch_args=None)
Applies a patch operation to a specified property of an object in the lab engine.
- Parameters:
type (str) – The type of the object whose property will be patched.
id (UUID) – The unique identifier of the object.
property (str) – The name of the property to patch.
value (Any) – The value to apply in the patch operation.
patch_type (PatchType) – The type of patch operation (e.g., ADD, REMOVE, REPLACE).
patch_args (dict, optional) – Additional arguments for the patch operation. Defaults to None.
- Returns:
The response from the lab engine after applying the patch.
- Return type:
Any
- Raises:
LabEngineException – If the patch operation fails.
- put_data(type, id, result_data)
Uploads data to a OperationResult object in the lab engine.
- Parameters:
type (str) – The type of the object to upload data to.
id (str) – The unique identifier of the object.
result_data (Any) – The data to upload (e.g., file-like object, bytes, or dict).
- Returns:
The unique identifier of the object after data upload.
- Return type:
UUID
- Raises:
LabEngineException – If the upload fails or the response is invalid.
- set_property(type, id, property, value)
Sets the value of a specified property on an object in the lab engine.
- Parameters:
type (str) – The type of the object to update.
id (UUID) – The unique identifier of the object.
property (str) – The name of the property to set.
value (Any) – The value to assign to the property.
- Returns:
The response from the lab engine after setting the property.
- Return type:
Any
- Raises:
LabEngineException – If the property update fails.
rest_adapter
- exception ochra.common.connections.rest_adapter.LabEngineException
Bases:
Exception
- class ochra.common.connections.rest_adapter.RestAdapter(hostname, api_key='', ssl_verify=True, logger=None)
Bases:
objectAdapter class for interacting with RESTful APIs.
Initializes the RestAdapter for interacting with a RESTful API.
- Parameters:
hostname (str) – The hostname or IP address of the API server.
api_key (str, optional) – API key for authentication. Defaults to ‘’.
ssl_verify (bool, optional) – Whether to verify SSL certificates. Defaults to True.
logger (logging.Logger, optional) – Custom logger instance. If None, a default logger is used.
- delete(endpoint, ep_params=None, data=None)
Performs a DELETE request to the specified endpoint.
- Parameters:
endpoint (str) – The API endpoint to send the DELETE request to.
ep_params (Dict, optional) – Query parameters for the endpoint. Defaults to None.
data (Dict, optional) – JSON body to include in the request. Defaults to None.
- Returns:
An object containing the status code, message, and data from the response if successful.
- Return type:
- get(endpoint, ep_params=None, data=None, jsonify=True)
Performs a GET request to the specified endpoint.
- Parameters:
endpoint (str) – The API endpoint to send the GET request to.
ep_params (Dict, optional) – Query parameters for the endpoint. Defaults to None.
data (Dict, optional) – JSON body to include in the request. Defaults to None.
jsonify (bool, optional) – If True, parses the response as JSON. If False, returns the raw response.
- Returns:
An object containing the status code, message, and data from the response if successful. requests.Response: The raw response object if jsonify is False.
- Return type:
- patch(endpoint, ep_params=None, data=None, files=None)
Performs a PATCH request to the specified endpoint.
- Parameters:
endpoint (str) – The API endpoint to send the PATCH request to.
ep_params (Dict, optional) – Query parameters for the endpoint. Defaults to None.
data (Dict, optional) – JSON body to include in the request. Defaults to None.
files (Any, optional) – Files to upload with the request. Defaults to None.
- Returns:
An object containing the status code, message, and data from the response if successful.
- Return type:
- post(endpoint, ep_params=None, data=None)
Performs a POST request to the specified endpoint.
- Parameters:
endpoint (str) – The API endpoint to send the POST request to.
ep_params (Dict, optional) – Query parameters for the endpoint. Defaults to None.
data (Dict, optional) – JSON body to include in the request. Defaults to None.
- Returns:
An object containing the status code, message, and data from the response if successful.
- Return type:
- put(endpoint, ep_params=None, data=None)
Performs a PUT request to the specified endpoint.
- Parameters:
endpoint (str) – The API endpoint to send the PUT request to.
ep_params (Dict, optional) – Query parameters for the endpoint. Defaults to None.
data (Dict, optional) – JSON body to include in the request. Defaults to None.
- Returns:
An object containing the status code, message, and data from the response if successful.
- Return type:
- class ochra.common.connections.rest_adapter.Result(status_code, message='', data=None)
Bases:
objectA class representing the result of an HTTP request, including status code, message, and data.
Initializes a Result instance.
- Parameters:
status_code (int) – HTTP status code.
message (str, optional) – Message returned from the request. Defaults to “”.
data (List[Dict], optional) – Data returned from the request. Defaults to None.