Properties

class bhopengraph.Properties.Properties(**kwargs)[source]

Bases: object

Properties class for storing arbitrary key-value pairs for nodes and edges. Follows BloodHound OpenGraph schema requirements where properties must be primitive types.

__init__(**kwargs)[source]

Initialize Properties with optional key-value pairs.

Parameters:

**kwargs (-) –

Key-value pairs to initialize properties

set_property(key, value)[source]

Set a property value. Only primitive types are allowed.

Parameters:
  • key (-) – Property name

  • value (-) – Property value (must be primitive type: str, int, float, bool, None, list)

get_property(key, default=None)[source]

Get a property value.

Parameters:
  • key (-) – Property name

  • default (-) – Default value if key doesn’t exist

Returns:

  • Property value or default

remove_property(key)[source]

Remove a property.

Parameters:

key (-) – Property name to remove

has_property(key)[source]

Check if a property exists.

Parameters:

key (-) – Property name to check

Returns:

True if property exists, False otherwise

Return type:

  • bool

get_all_properties()[source]

Get all properties as a dictionary.

Returns:

Copy of all properties

Return type:

  • dict

clear()[source]

Clear all properties.

validate()[source]

Validate all properties according to OpenGraph schema rules.

Returns:

(is_valid, list_of_errors)

Return type:

  • tuple[bool, list[str]]

is_valid_property_value(value)[source]

Validate a single property value according to OpenGraph schema rules.

Properties must be primitive types or arrays of primitive types. Nested objects and arrays of objects are not allowed. Arrays must be homogeneous (e.g. all strings or all numbers).

Parameters:

value (-) – The property value to validate

Returns:

True if valid, False otherwise

Return type:

  • bool

to_dict()[source]

Convert properties to dictionary for JSON serialization.

Returns:

Properties as dictionary

Return type:

  • dict

items()[source]

Return a view of the properties as (key, value) pairs.

Returns:

View of properties as key-value pairs

Return type:

  • dict_items

keys()[source]

Return a view of the property keys.

Returns:

View of property keys

Return type:

  • dict_keys