Properties

bhopengraph.Properties.primitive_category(value)[source]

Classify a value into one of the OpenGraph primitive categories.

The BloodHound OpenGraph schema recognizes three primitive categories for property values: “string”, “number”, and “boolean”. This helper returns the matching category, or an empty string when the value is None or not a primitive (e.g. an object, list, or callable).

Note: bool is checked before int because in Python bool is a subclass of int; without this order True/False would be misclassified as numbers.

Source: https://bloodhound.specterops.io/opengraph/developer/nodes

Parameters:

value (-) – The value to classify

Returns:

“string”, “number”, “boolean”, or “” if not a primitive

Return type:

  • str

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 a primitive type: str, int, float, bool, or a homogeneous list of those). None is not a valid value.

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.

The BloodHound OpenGraph schema restricts a property value to a single primitive (string, number, or boolean) or a homogeneous array of primitives. None, nested objects, arrays of objects, and arrays mixing primitive categories are not valid.

Note: bool and the numeric types are treated as distinct categories, so a list such as [1, True] is rejected as non-homogeneous even though bool is a subclass of int in Python.

Source: https://bloodhound.specterops.io/opengraph/developer/nodes

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