smax package
Submodules
smax.cli module
smax.smax_client module
- smax.smax_client.join(*args)[source]
Join SMA-X tables and keys. We use this method to avoid the TypeErrors from string.join()
- params:
*args : SMA-X key elements to join
smax.smax_data_types module
- class smax.smax_data_types.SmaxArray(*args, **kwargs)[source]
Bases:
UserArray
,SmaxVarBase
Class for holding SMA-X array objects, with their metadata
- property data
Python buffer object pointing to the start of the array’s data.
- type: str | None = None
- class smax.smax_data_types.SmaxBool(*args, **kwargs)[source]
Bases:
UserBool
,SmaxVarBase
Class for holding SMA-X boolean objects, with their metadata.
- This class is not an exact subclass for bool - e.g.:
In [1]: SmaxBool(True) is True Out[1]: False
- property data
- type: str = 'boolean'
- class smax.smax_data_types.SmaxData(data, type, dim, date, origin, seq, smaxname)
Bases:
tuple
- data
Alias for field number 0
- date
Alias for field number 3
- dim
Alias for field number 2
- origin
Alias for field number 4
- seq
Alias for field number 5
- smaxname
Alias for field number 6
- type
Alias for field number 1
- class smax.smax_data_types.SmaxFloat(data: dataclasses.InitVar[float] = <property object>, *, timestamp: ~datetime.datetime | None = None, origin: str | None = None, seq: int = 1, smaxname: str | None = None, dim: int | tuple = 1, description: str | None = None, unit: str | None = None, coords: ~typing.Any | None = None, type: str = 'float')[source]
Bases:
float
,SmaxVarBase
Class for holding SMA-X float objects, with their metadata
- type: str = 'float'
- class smax.smax_data_types.SmaxFloat32(*args, **kwargs)[source]
Bases:
UserFloat32
,SmaxVarBase
Class for holding SMA-X float objects, with their metadata
- property data
Pointer to start of data.
- type: str = 'float32'
- class smax.smax_data_types.SmaxFloat64(*args, **kwargs)[source]
Bases:
UserFloat64
,SmaxVarBase
Class for holding SMA-X float objects, with their metadata
- property data
Pointer to start of data.
- type: str = 'float64'
- class smax.smax_data_types.SmaxInt(*args, **kwargs)[source]
Bases:
UserInt
,SmaxVarBase
Class for holding SMA-X integer objects, with their metadata
- type: str = 'integer'
- class smax.smax_data_types.SmaxInt16(*args, **kwargs)[source]
Bases:
UserInt16
,SmaxVarBase
Class for holding SMA-X integer objects, with their metadata
- type: str = 'int16'
- class smax.smax_data_types.SmaxInt32(*args, **kwargs)[source]
Bases:
UserInt32
,SmaxVarBase
Class for holding SMA-X integer objects, with their metadata
- type: str = 'int32'
- class smax.smax_data_types.SmaxInt64(*args, **kwargs)[source]
Bases:
UserInt64
,SmaxVarBase
Class for holding SMA-X integer objects, with their metadata
- type: str = 'int64'
- class smax.smax_data_types.SmaxInt8(*args, **kwargs)[source]
Bases:
UserInt8
,SmaxVarBase
Class for holding SMA-X integer objects, with their metadata
- type: str = 'int8'
- class smax.smax_data_types.SmaxStr(*args, **kwargs)[source]
Bases:
UserStr
,SmaxVarBase
Class for holding SMA-X string objects, with their metadata
- type: str = 'string'
- class smax.smax_data_types.SmaxStrArray(*args, **kwargs)[source]
Bases:
UserList
,SmaxVarBase
Class for holding SMA-X string arrays, with their metadata
- type: str = 'string'
- class smax.smax_data_types.SmaxStruct(*args, **kwargs)[source]
Bases:
UserDict
,SmaxVarBase
Class for holding SMA-X string objects, with their metadata
- type: str = 'struct'
- class smax.smax_data_types.SmaxVarBase(*, timestamp: datetime | None = None, origin: str | None = None, seq: int = 1, smaxname: str | None = None, dim: int | tuple = 1, description: str | None = None, unit: str | None = None, coords: Any | None = None)[source]
Bases:
object
Class defining the metadata for SMA-X data types.
We define all the metadata except data and type here.
- coords: Any | None = None
- property data
- description: str | None = None
- dim: int | tuple = 1
- property metadata
- origin: str | None = None
- seq: int = 1
- smaxname: str | None = None
- timestamp: datetime | None = None
- unit: str | None = None
smax.smax_redis_client module
- class smax.smax_redis_client.SmaxRedisClient(redis_ip='localhost', redis_port=6379, redis_db=0, program_name=None, hostname=None, debug=False, logger=None)[source]
Bases:
SmaxClient
- smax_connect_to(redis_ip, redis_port, redis_db)[source]
Uses the redis-py library to establish a connection to redis, then obtains and stores the LUA scripts in the object (ex self._getSHA). This function is called automatically by the SmaxClient parent class, so there shouldn’t be a need to call this explicitly.
- Parameters:
redis_ip (str) – IP address of redis-server.
redis_port (int) – Port of redis-server.
redis_db (int) – Database index to connect to.
- Returns:
A Redis client object configured from the given args.
- Return type:
Redis
- smax_disconnect()[source]
Python manages a connection pool automatically, if somehow that fails release the connection, this disconnect function will do it.
- smax_dsm_get_table(target, key, host=None)[source]
Get the SMA-X name that maps to a DSM target, key, and (optionally) host.
- Parameters:
target (str) – DSM target or caller
key (str) – DSM key
host (str, optional) – DSM host (caller). If not set, defaults to target.
- Returns:
SMA-X table where the key can be found.
- Return type:
str
- smax_list_higher_than(table, value)[source]
List all SMA-X fields in table with values higher than the value.
- Parameters:
table (str) – table, struct or meta name
value (int or float) – cutoff value.
- Returns:
list of pairs of SMA-X fields and values higher than value
- Return type:
list[(str, smax.SmaxData)]
- smax_list_newer_than(dt)[source]
List all SMA-X keys newer than the datetime object.
- Parameters:
dt (datetime.datetime) – cutoff time.
- Returns:
list of pairs of SMA-X keys and values newer than dt
- Return type:
list[(str, smax.SmaxData)]
- smax_list_older_than(dt)[source]
List all SMA-X keys older than the datetime object.
- Parameters:
dt (datetime.datetime) – cutoff time.
- Returns:
list of pairs of SMA-X keys and values older than dt
- Return type:
list[(str, smax.SmaxData)]
- smax_list_zeroes(key)[source]
List all fields in key equal to zero.
- Parameters:
key (str) – Redis key to test.
- Returns:
list of all fields equal to zero.
- Return type:
list(str)
- smax_pull(table, key, pull_meta=False)[source]
Get data which was stored with the smax macro HSetWithMeta along with the associated metadata. The return value will an SmaxData object containing the data, typeName, dataDimension(s), dataDate, source of the data, and a sequence number. If you pulled a struct, you will get a nested dictionary back, with each leaf being an SmaxData object. :param table: SMAX table name :type table: str :param key: SMAX key name :type key: str :param pull_meta: Flag whether to pull optional metadata :type pull_meta: bool
- Returns:
Populated Smax<type> dataclass object.
- Return type:
Smax<type>
- smax_pull_meta(meta, table)[source]
Pulls specified metadata field from a given table. :param table: Name of the table to pull metadata from. :type table: str :param meta: Metadata field name to pull. :type meta: str
- Returns:
Result of redis-py hget function.
- smax_purge(table, key=None)[source]
Purges a table or key from Redis. Use with ultimate caution.
- Parameters:
table (str) – SMA-X table to purge. Can include wild cards to purge by pattern matching.
key (str, optional) – Specific SMA-X key in table to purge. Defaults to None.
- Returns:
number of SMA-X keys purged from Redis
- Return type:
int
- smax_purge_volatile()[source]
Purges all volatile tables and keys from Redis. Use with ultimate caution.
- smax_push_meta(meta, table, value)[source]
Sets additional metadata for a given table. :param meta: Key for the metadata field. :type meta: str :param table: Name of the table to set metadata for. :type table: str :param value: Metadata value to store in redis, note this
needs to be a string int.
- Returns:
Result of redis-py hset function.
- smax_set_description(table, description)[source]
Creates a <description> metadata field for specified table. :param table: Full SMAX table name (with key included). :type table: str :param description: String for the description of this smax field. :type description: str
Send data to redis using the smax macro HSetWithMeta to include metadata. The metadata is typeName, dataDimension(s), dataDate, source of the data, and a sequence number. The first two are determined from the data and the source from this computer’s name plus the program name if given when this class is instantiated. Date and sequence number are added by the redis macro. :param table: SMAX table name :type table: str :param key: SMAX key name :type key: str :param value: data to store, takes supported types, including (nested) dicts. :param push_meta: Push optional metadata if present in object
(does not work for SmaxStructs and is not atomic).
- Parameters:
type_name (str) – Force casting to type_name before sharing.
- Returns:
return value from redis-py’s evalsha() function.
- smax_subscribe(pattern, callback=None, pubsub_sleep=0.01)[source]
Subscribe to a redis field or group of fields. You can type the full name of the field you’d like to subscribe too, or use a wildcard “*” character as a suffix to specify a pattern. Use a callback for asynchronous processing of notifications, or use one of the smax_wait_on functions.
Internal to the HSET* and HMSET*, notifications for pub/sub are generated with the prefix smax:. This needs to be added/removed within smax_subscribe, etc.
- Parameters:
pattern (str) – Either full name of smax field, or use a wildcard ‘*’ at the end of the pattern to be notified for anything underneath.
callback (func) – Function that takes a single argument (Default=None). The message in your callback will be an SmaData object, or a nested dictionary for a struct.
pubsub_sleep (float) – Sleep time within each loop of the pubsub event handling thread
- smax_unsubscribe(pattern=None)[source]
Unsubscribe from all subscribed channels, or pass a pattern argument to unsubscribe from specific channels. :param pattern: Either full name of smax field, or use a wildcard ‘*’
at the end of the pattern to be notified for anything underneath.
- smax_wait_on_any_subscribed(timeout=None, notification_only=False)[source]
If you use smax_subscribe without a callback, you can use this function to block until a message is received from any channel you are subscribed to. :param timeout: Value in seconds to wait before raising timeout exception. :type timeout: float :param notification_only: If True, only returns the notification from redis. :type notification_only: bool
- Returns:
Either a (list) notification, or the actual pulled data.
- smax_wait_on_subscribed(pattern, timeout=None, notification_only=False)[source]
If you use smax_subscribe without a callback, you can use this function to specify with channel to listen to, and block until a message is received. :param pattern: SMAX table/key pattern to listen on. :type pattern: str :param timeout: Value in seconds to wait before raising timeout exception. :type timeout: int :param notification_only: If True, only returns the notification from redis. :type notification_only: bool
- Returns:
Either a (list) notification, or the actual pulled data.
smax.smax_redis_client_old module
- class smax.smax_redis_client_old.SmaxRedisClient(redis_ip='localhost', redis_port=6379, redis_db=0, program_name=None, hostname=None)[source]
Bases:
SmaxClient
- smax_connect_to(redis_ip, redis_port, redis_db)[source]
Uses the redis-py library to establish a connection to redis, then obtains and stores the LUA scripts in the object (ex self._getSHA). This function is called automatically by the SmaxClient parent class, so there shouldn’t be a need to call this explicitly.
- Parameters:
redis_ip (str) – IP address of redis-server.
redis_port (int) – Port of redis-server.
redis_db (int) – Database index to connect to.
- Returns:
A Redis client object configured from the given args.
- Return type:
Redis
- smax_disconnect()[source]
Python manages a connection pool automatically, if somehow that fails release the connection, this disconnect function will do it.
- smax_dsm_get_table(target, key, host=None)[source]
Get the SMA-X name that maps to a DSM target, key, and (optionally) host.
- Parameters:
target (str) – DSM target or caller
key (str) – DSM key
host (str, optional) – DSM host (caller). If not set, defaults to target.
- Returns:
SMA-X table where the key can be found.
- Return type:
str
- smax_list_higher_than(table, value)[source]
List all SMA-X fields in table with values higher than the value.
- Parameters:
table (str) – table, struct or meta name
value (int or float) – cutoff value.
- Returns:
list of pairs of SMA-X fields and values higher than value
- Return type:
list[(str, smax.SmaxData)]
- smax_list_newer_than(dt)[source]
List all SMA-X keys newer than the datetime object.
- Parameters:
dt (datetime.datetime) – cutoff time.
- Returns:
list of pairs of SMA-X keys and values newer than dt
- Return type:
list[(str, smax.SmaxData)]
- smax_list_older_than(dt)[source]
List all SMA-X keys older than the datetime object.
- Parameters:
dt (datetime.datetime) – cutoff time.
- Returns:
list of pairs of SMA-X keys and values older than dt
- Return type:
list[(str, smax.SmaxData)]
- smax_list_zeroes(key)[source]
List all fields in key equal to zero.
- Parameters:
key (str) – Redis key to test.
- Returns:
list of all fields equal to zero.
- Return type:
list(str)
- smax_pull(table, key)[source]
Get data which was stored with the smax macro HSetWithMeta along with the associated metadata. The return value will an SmaxData object containing the data, typeName, dataDimension(s), dataDate, source of the data, and a sequence number. If you pulled a struct, you will get a nested dictionary back, with each leaf being an SmaxData object. :param table: SMAX table name :type table: str :param key: SMAX key name :type key: str
- Returns:
Populated SmaxData NamedTuple object. dict: If a struct is pulled, this returns a nested dictionary.
- Return type:
- smax_pull_meta(table, meta)[source]
Pulls specified metadata field from a given table. :param table: Name of the table to pull metadata from. :type table: str :param meta: Metadata field name to pull. :type meta: str
- Returns:
Result of redis-py hget function.
- smax_purge(table, key=None)[source]
Purges a table or key from Redis. Use with ultimate caution.
- Parameters:
table (str) – SMA-X table to purge. Can include wild cards to purge by pattern matching.
key (str, optional) – Specific SMA-X key in table to purge. Defaults to None.
- Returns:
number of SMA-X keys purged from Redis
- Return type:
int
- smax_purge_volatile()[source]
Purges all volatile tables and keys from Redis. Use with ultimate caution.
- smax_push_meta(meta, table, value)[source]
Sets additional metadata for a given table. :param meta: Key for the metadata field. :type meta: str :param table: Name of the table to set metadata for. :type table: str :param value: Metadata value to store in redis, note this
needs to be a string int.
- Returns:
Result of redis-py hset function.
- smax_set_description(table, description)[source]
Creates a <description> metadata field for specified table. :param table: Full SMAX table name (with key included). :type table: str :param description: String for the description of this smax field. :type description: str
Send data to redis using the smax macro HSetWithMeta to include metadata. The metadata is typeName, dataDimension(s), dataDate, source of the data, and a sequence number. The first two are determined from the data and the source from this computer’s name plus the program name if given when this class is instantiated. Date and sequence number are added by the redis macro. :param table: SMAX table name :type table: str :param key: SMAX key name :type key: str :param value: data to store, takes supported types, including (nested) dicts.
- Returns:
return value from redis-py’s evalsha() function.
- smax_subscribe(pattern, callback=None)[source]
Subscribe to a redis field or group of fields. You can type the full name of the field you’d like to subscribe too, or use a wildcard “*” character as a suffix to specify a pattern. Use a callback for asynchronous processing of notifications, or use one of the smax_wait_on functions. :param pattern: Either full name of smax field, or use a wildcard ‘*’
at the end of the pattern to be notified for anything underneath.
- Parameters:
callback (func) – Function that takes a single argument (Default=None). The message in your callback will be an SmaData object, or a nested dictionary for a struct.
- smax_unsubscribe(pattern=None)[source]
Unsubscribe from all subscribed channels, or pass a pattern argument to unsubscribe from specific channels. :param pattern: Either full name of smax field, or use a wildcard ‘*’
at the end of the pattern to be notified for anything underneath.
- smax_wait_on_any_subscribed(timeout=None, notification_only=False)[source]
If you use smax_subscribe without a callback, you can use this function to block until a message is received from any channel you are subscribed to. :param timeout: Value in seconds to wait before raising timeout exception. :type timeout: float :param notification_only: If True, only returns the notification from redis. :type notification_only: bool
- Returns:
Either a (list) notification, or the actual pulled data.
- smax_wait_on_subscribed(pattern, timeout=None, notification_only=False)[source]
If you use smax_subscribe without a callback, you can use this function to specify with channel to listen to, and block until a message is received. :param pattern: SMAX table/key pattern to listen on. :type pattern: str :param timeout: Value in seconds to wait before raising timeout exception. :type timeout: int :param notification_only: If True, only returns the notification from redis. :type notification_only: bool
- Returns:
Either a (list) notification, or the actual pulled data.