Skip to content

sift_py.rule.service

CLASS DESCRIPTION
RuleService

A service for managing rules. Allows for loading rules from YAML and creating or updating them in the Sift API.

RuleChannelReference

Convenient wrapper to map rule names to relevant channel references

RuleIdentifier

Wrapper around RuleIdentifier for working with external rules.

RuleService

RuleService(channel: SiftChannel, enable_caching=False)

A service for managing rules. Allows for loading rules from YAML and creating or updating them in the Sift API.

PARAMETER DESCRIPTION
channel

The configured Sift channel.

TYPE: SiftChannel

enable_caching

Enable caching on various API calls to speed up rule creation. Use this for short lived instantiations of the RuleService where assets, channels, users are unlikely to change.

DEFAULT: False

METHOD DESCRIPTION
load_rules_from_yaml

Loads rules from a YAML spec, and creates or updates the rules in the Sift API.

create_external_rules_from_yaml

Creates external rules from a YAML spec in the Sift API.

create_or_update_rules

Create or update a list of rules via a list of RuleConfigs.

attach_asset

Associates a rule with an asset by name. The asset must already exist in the Sift API.

detach_asset

Disassociates a rule from an asset by name. The asset must already exist in the Sift API.

create_or_update_rule

Create or update a rule via a RuleConfig. The config must contain a rule_client_key or an exception will be raised.

create_external_rules

Create external rules via RuleConfigs. The configs must have is_external set to

get_rule

Get a rule by rule id or client key. Returns a RuleConfig if the rule exists, otherwise None.

load_rules_from_yaml

load_rules_from_yaml(
    paths: List[Path],
    named_expressions: Optional[Dict[str, str]] = None,
) -> List[RuleConfig]

Loads rules from a YAML spec, and creates or updates the rules in the Sift API. For more on rule YAML definitions, see sift_py.ingestion.config.yaml.spec.RuleYamlSpec.

PARAMETER DESCRIPTION
paths

The list of YAML paths to load.

TYPE: List[Path]

named_expressions

The named expressions to substitute into the rules.

TYPE: Optional[Dict[str, str]] DEFAULT: None

RETURNS DESCRIPTION
List[RuleConfig]

The loaded RuleConfigs.

create_external_rules_from_yaml

create_external_rules_from_yaml(
    paths: List[Path],
    named_expressions: Optional[Dict[str, str]] = None,
) -> List[RuleIdentifier]

Creates external rules from a YAML spec in the Sift API. For more on rule YAML definitions, see sift_py.ingestion.config.yaml.spec.RuleYamlSpec. If is_external is set in the YAML, this overrides that.

PARAMETER DESCRIPTION
paths

The list of YAML paths to load.

TYPE: List[Path]

named_expressions

The named expressions to substitute into the rules.

TYPE: Optional[Dict[str, str]] DEFAULT: None

RETURNS DESCRIPTION
List[RuleIdentifier]

The loaded RuleConfigs as external rules.

create_or_update_rules

create_or_update_rules(rule_configs: List[RuleConfig])

Create or update a list of rules via a list of RuleConfigs. See sift_py.rule.config.RuleConfig for more information on configuation parameters for rules.

attach_asset

attach_asset(
    rule: Union[str, RuleConfig], asset_names: List[str]
) -> RuleConfig

Associates a rule with an asset by name. The asset must already exist in the Sift API. The provided rule may either be a rule client key, rule id, or a RuleConfig.

detach_asset

detach_asset(
    rule: Union[str, RuleConfig], asset_names: List[str]
) -> RuleConfig

Disassociates a rule from an asset by name. The asset must already exist in the Sift API. The provided rule may either be a rule client key, rule id, or a RuleConfig.

create_or_update_rule

create_or_update_rule(config: RuleConfig)

Create or update a rule via a RuleConfig. The config must contain a rule_client_key or an exception will be raised. If a rule with the given client key already exists it will be updated, otherwise it will be created. See sift_py.rule.config.RuleConfig for more information on configuation parameters for rules.

create_external_rules

create_external_rules(
    configs: List[RuleConfig],
) -> List[RuleIdentifier]

Create external rules via RuleConfigs. The configs must have is_external set to True or an exception will be raised. rule_client_key must be empty.

PARAMETER DESCRIPTION
configs

The list of RuleConfigs to create as external rules.

TYPE: List[RuleConfig]

RETURNS DESCRIPTION
List[RuleIdentifier]

The list of RuleIdentifiers created.

get_rule

get_rule(rule: str) -> Optional[RuleConfig]

Get a rule by rule id or client key. Returns a RuleConfig if the rule exists, otherwise None.

RuleChannelReference dataclass

RuleChannelReference(
    rule_name: str, channel_references: Dict[str, Any]
)

Convenient wrapper to map rule names to relevant channel references when creating rules from yaml.

ATTRIBUTE DESCRIPTION
rule_name

TYPE: str

channel_references

TYPE: Dict[str, Any]

rule_name instance-attribute

rule_name: str

channel_references instance-attribute

channel_references: Dict[str, Any]

RuleIdentifier dataclass

RuleIdentifier(rule_id: str, name: str)

Wrapper around RuleIdentifier for working with external rules.

ATTRIBUTE DESCRIPTION
rule_id

TYPE: str

name

TYPE: str

rule_id instance-attribute

rule_id: str

name instance-attribute

name: str