pyprediktormapclient package
Subpackages
Submodules
pyprediktormapclient.analytics_helper module
- class pyprediktormapclient.analytics_helper.AnalyticsHelper(input: List)[source]
Bases:
object
Your data as a Pandas DataFrame, but with a specific formatting and some nifty functions. Put the data from ModelIndex in here and move further on by adding data and from other ModelIndex calls or live or historical data from OPC UA.
Columns in the normalizes dataframe are:
Id
Name
Type
- Props
DisplayName
Value
- Vars
DisplayName
Id
- Parameters:
input (List) – The return from a ModelIndex call function
- dataframe
The normalized dataframe
- Type:
- Returns:
An instance of the class with some resources and attributes
- ID_PATTERN = '^\\d+:\\d+:\\S+$'
- list_of_ids() list [source]
Extracts the values in the column “Id” to a list of unique IDs.
- Returns:
Unique IDs
- Return type:
- list_of_names() list [source]
Extracts the values in the column “Name” to a list of unique names.
- Returns:
Unique names
- Return type:
- list_of_types() list [source]
Extracts the values in the column “Type” to a list of unique types.
- Returns:
Unique types
- Return type:
- list_of_variable_names() list [source]
Explodes the content of the column “Vars” and extracts the values from DisplayName into a list of unique values.
- Returns:
Unique variable names
- Return type:
- namespaces_as_list(list_of_dicts: List) List [source]
Takes the output of a get_namespace_array() request from ModelIndex and generates a list of strings that can be used for the OPC UA Values API.
- Parameters:
list_of_dicts (List) – A list in of dicts like [{‘Idx’: 0, ‘Uri’: ‘http://opcfoundation.org/UA/’}, etc]
- Returns:
A list of strings containing the URIs
- Return type:
List
- normalize()[source]
Normalize column names in the dataframe class attribute. Different ModelIndex calls has different column names but this will be normalized with this function according to the class docs.
- Returns:
Nothing, but normalizes the instance “dataframe”
- properties_as_dataframe() DataFrame [source]
Explodes the column “Props” into a new dataframe. Column names will be.
Id (same as from the original dataframe)
Name (same as from the original dataframe)
Type (same as from the original dataframe)
Property (from the exploded value DisplayName)
Value (from the exploded value Value)
- Returns:
A new dataframe with all properties as individual rows
- Return type:
- variables_as_dataframe() DataFrame [source]
Explodes the column “Vars” into a new dataframe. Column names will be.
Id (same as from the original dataframe)
Name (same as from the original dataframe)
Type (same as from the original dataframe)
VariableId (from the exploded value Id)
VariableName (from the exploded value DisplayName)
- Returns:
A new dataframe with all variables as individual rows
- Return type:
pyprediktormapclient.auth_client module
- class pyprediktormapclient.auth_client.AUTH_CLIENT(rest_url: Url, username: str, password: str)[source]
Bases:
object
Helper functions to authenticate with Ory.
- Parameters:
rest_url (str) – The complete url of the OPC UA Values REST API. E.g. “http://127.0.0.1:13371/”
opcua_url (str) – The complete url of the OPC UA Server that is passed on to the REST server. E.g. “opc.tcp://127.0.0.1:4872”
namespaces (list) – An optional but recommended ordered list of namespaces so that IDs match
- Returns:
Object
- class pyprediktormapclient.auth_client.Ory_Login_Structure(*, method: str, identifier: str, password: str)[source]
Bases:
BaseModel
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'identifier': FieldInfo(annotation=str, required=True), 'method': FieldInfo(annotation=str, required=True), 'password': FieldInfo(annotation=str, required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__ from Pydantic V1.
- class pyprediktormapclient.auth_client.Token(*, session_token: str, expires_at: datetime | None = None)[source]
Bases:
BaseModel
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'expires_at': FieldInfo(annotation=Union[datetime, NoneType], required=False, default=None), 'session_token': FieldInfo(annotation=str, required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__ from Pydantic V1.
pyprediktormapclient.model_index module
- class pyprediktormapclient.model_index.ModelIndex(url: Url, auth_client: object = None, session: Session = None)[source]
Bases:
object
Helper functions to access the ModelIndex API server.
- Parameters:
url (str) – The URL of the ModelIndex server with the trailing slash
- get_namespace_array() str [source]
Get the namespace array.
- Returns:
the JSON returned from the server
- Return type:
- get_object_ancestors(type_name: str, ids: List, domain: str) str [source]
Function to get object ancestors.
- get_object_descendants(type_name: str, ids: List, domain: str) str [source]
A function to get object descendants.
pyprediktormapclient.opc_ua module
- class pyprediktormapclient.opc_ua.HistoryValue(*, Value: SubValue)[source]
Bases:
BaseModel
Helper class to parse all values api’s.
- Variables:
Value: SubValue - Containing Type and Body (value) of the variable. Described in SubValue class.
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pyprediktormapclient.opc_ua.OPC_UA(rest_url: Url, opcua_url: Url, namespaces: List = None, auth_client: object = None, session: Session = None)[source]
Bases:
object
Helper functions to access the OPC UA REST Values API server.
- Parameters:
rest_url (str) – The complete url of the OPC UA Values REST API. E.g. “http://127.0.0.1:13371/”
opcua_url (str) – The complete url of the OPC UA Server that is passed on to the REST server. E.g. “opc.tcp://127.0.0.1:4872”
namespaces (list) – An optional but recommended ordered list of namespaces so that IDs match
- Returns:
Object
- async get_historical_aggregated_values_asyn(start_time: datetime, end_time: datetime, pro_interval: int, agg_name: str, variable_list: List[str], **kwargs) DataFrame [source]
Request historical aggregated values from the OPC UA server.
- async get_historical_raw_values_asyn(start_time: datetime, end_time: datetime, variable_list: List[str], limit_start_index: int | None = None, limit_num_records: int | None = None, **kwargs) DataFrame [source]
Request raw historical values from the OPC UA server.
- async get_historical_values(start_time: datetime, end_time: datetime, variable_list: List[str], endpoint: str, prepare_variables: Callable[[List[str]], List[dict]], additional_params: dict = None, max_data_points: int = 10000, max_retries: int = 3, retry_delay: int = 5, max_concurrent_requests: int = 30) DataFrame [source]
Generic method to request historical values from the OPC UA server with batching.
- get_values(variable_list: List[Variables]) List [source]
Request realtime values from the OPC UA server.
- write_historical_values(variable_list: List[WriteHistoricalVariables]) List [source]
Request to write realtime values to the OPC UA server.
- Parameters:
variable_list (list) – A list of variables you want, containing keys “Id”, “Namespace”, “Values” and “IdType”. Values must be in descending order of the timestamps.
- Returns:
The input variable_list extended with “Timestamp”, “Value”, “ValueType”, “StatusCode” and “StatusSymbol” (all defaults to None)
- Return type:
- write_values(variable_list: List[WriteVariables]) List [source]
Request to write realtime values to the OPC UA server.
- Parameters:
variable_list (list) – A list of variables you want to write to with the value, timestamp and quality, containing keys “Id”, “Namespace”, “Values” and “IdType”.
- Returns:
The input variable_list extended with “Timestamp”, “Value”, “ValueType”, “StatusCode” and “StatusSymbol” (all defaults to None)
- Return type:
- class pyprediktormapclient.opc_ua.StatsCode(*, Code: int | None = None, Symbol: str | None = None)[source]
Bases:
BaseModel
Helper class to parse all values api’s.
- Variables:
Code: Optional[int] - Status code, described in https://reference.opcfoundation.org/v104/Core/docs/Part8/A.4.3/ Symbol: Optional[str] - String value for status code, described in https://reference.opcfoundation.org/v104/Core/docs/Part8/A.4.3/
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'Code': FieldInfo(annotation=Union[int, NoneType], required=False, default=None), 'Symbol': FieldInfo(annotation=Union[str, NoneType], required=False, default=None)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__ from Pydantic V1.
- class pyprediktormapclient.opc_ua.SubValue(*, Type: int, Body: str | float | int | bool)[source]
Bases:
BaseModel
Helper class to parse all values api’s.
- Variables:
Type: int - Type of variable, e.g. 12. string, 11. float, etc. list of types described in https://reference.opcfoundation.org/Core/Part6/v104/5.1.2/ Body: Union[str, float, int, bool] - The value of the varible, should match type.
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'Body': FieldInfo(annotation=Union[str, float, int, bool], required=True), 'Type': FieldInfo(annotation=int, required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__ from Pydantic V1.
- class pyprediktormapclient.opc_ua.Value(*, Value: SubValue, SourceTimestamp: datetime, SourcePicoseconds: int | None = None, ServerTimestamp: datetime | None = None, ServerPicoseconds: int | None = None, StatusCode: StatsCode | None = None)[source]
Bases:
BaseModel
Helper class to parse all values api’s.
- Variables:
Value: SubValue - Containing Type and Body (value) of the variable. Described in SubValue class. SourceTimestamp: str - Timestamp of the source, e.g. when coming from an API the timestamp returned from the API for the varaible is the sourcetimestamp. SourcePicoseconds: Optional[int] - Picoseconds for the timestamp of the source if there is a need for a finer granularity, e.g. if samples are sampled in picosecond level or more precision is needed. ServerTimestamp: Optional[str] - Timestamp for the server, normally this is assigned by the server. ServerPicoseconds: Optional[int] - Picoseconds for the timestamp on the server, normally this is assigned by the server. StatusCode: StatusCode - Status code, described in https://reference.opcfoundation.org/v104/Core/docs/Part8/A.4.3/
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'ServerPicoseconds': FieldInfo(annotation=Union[int, NoneType], required=False, default=None), 'ServerTimestamp': FieldInfo(annotation=Union[datetime, NoneType], required=False, default=None), 'SourcePicoseconds': FieldInfo(annotation=Union[int, NoneType], required=False, default=None), 'SourceTimestamp': FieldInfo(annotation=datetime, required=True), 'StatusCode': FieldInfo(annotation=Union[StatsCode, NoneType], required=False, default=None), 'Value': FieldInfo(annotation=SubValue, required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__ from Pydantic V1.
- class pyprediktormapclient.opc_ua.Variables(*, Id: str, Namespace: int, IdType: int)[source]
Bases:
BaseModel
Helper class to parse all values api’s. Variables are described in https://reference.opcfoundation.org/v104/Core/docs/Part3/8.2.1/
- Variables:
Id: str - Id of the signal, e.g. SSO.EG-AS.WeatherSymbol Namespace: int - Namespace on the signal, e.g. 2. IdType: int - IdTypes described in https://reference.opcfoundation.org/v104/Core/docs/Part3/8.2.3/.
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'Id': FieldInfo(annotation=str, required=True), 'IdType': FieldInfo(annotation=int, required=True), 'Namespace': FieldInfo(annotation=int, required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__ from Pydantic V1.
- class pyprediktormapclient.opc_ua.WriteHistoricalVariables(*, NodeId: Variables, PerformInsertReplace: int, UpdateValues: List[Value])[source]
Bases:
BaseModel
Helper class for write historical values api.
- Variables:
NodeId (str): The complete node’id for the variable PerformInsertReplace (int): Historical insertion method 1. Insert, 2. Replace 3. Update, 4. Remove UpdateValues (list): List of values to update for the node’id. Time must be in descending order.
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'NodeId': FieldInfo(annotation=Variables, required=True), 'PerformInsertReplace': FieldInfo(annotation=int, required=True), 'UpdateValues': FieldInfo(annotation=List[Value], required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__ from Pydantic V1.
- class pyprediktormapclient.opc_ua.WriteReturn(*, Id: str, Value: str, TimeStamp: str, Success: bool)[source]
Bases:
BaseModel
Helper class to collect API output with API input to see successfull writes for nodes.
- Variables:
Id: str - The Id of the signal Value: str - The written value of the signal TimeStamp: str - THe SourceTimestamp of the written signal Success: bool - Success flag for the write operation
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'Id': FieldInfo(annotation=str, required=True), 'Success': FieldInfo(annotation=bool, required=True), 'TimeStamp': FieldInfo(annotation=str, required=True), 'Value': FieldInfo(annotation=str, required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__ from Pydantic V1.
- class pyprediktormapclient.opc_ua.WriteVariables(*, NodeId: Variables, Value: Value)[source]
Bases:
BaseModel
Helper class for write values api.
- Variables:
NodeId: Variables - The complete node’id for the variable Value: Value - The value to update for the node’id.
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'NodeId': FieldInfo(annotation=Variables, required=True), 'Value': FieldInfo(annotation=Value, required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__ from Pydantic V1.
- class pyprediktormapclient.opc_ua.WriteVariablesResponse(*, SymbolCodes: List[StatsCode])[source]
Bases:
BaseModel
Helper class for write historical values api.
- Variables:
SymbolCodes: List[StatusCode] - A list of class StatusCode, described in StatusCode class.
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].