Skip to content

sift_py.rule.service

CLASS DESCRIPTION
RuleChannelReference

Convenient wrapper to map rule names to relevant channel references

RuleIdentifier

Wrapper around RuleIdentifier for working with external rules.

RuleService

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

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
channel_references

TYPE: Dict[str, Any]

rule_name

TYPE: str

channel_references instance-attribute

channel_references: Dict[str, Any]

rule_name instance-attribute

rule_name: str

RuleIdentifier dataclass

RuleIdentifier(rule_id: str, name: str)

Wrapper around RuleIdentifier for working with external rules.

ATTRIBUTE DESCRIPTION
name

TYPE: str

rule_id

TYPE: str

name instance-attribute

name: str

rule_id instance-attribute

rule_id: str

RuleService

RuleService(channel: SiftChannel)

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

METHOD DESCRIPTION
attach_asset

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

create_external_rules

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

create_external_rules_from_yaml

Creates external rules from a YAML spec 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_or_update_rules

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

detach_asset

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

get_rule

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

load_rules_from_yaml

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

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.

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.

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.

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_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_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.

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.

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.

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.