Documentation

class pystixview.PySTIXView(notebook=False)

Class to create a graph representing STIX objects and relationships

Parameters:

notebook (bool) – If True render the graph in a Jupyter Notebook

add_bundle(bundle)

Add a Bundle to the graph

Parameters:

bundle (Bundle | dict | str) – Bundle object to add to the graph.

Return type:

bool

Returns:

True if the object was added successfully

Raises:

TypeError – If an invalid Bundle object is provided

add_custom_stix_type(custom_type, node_icon=None, label_name='name', node_color=None)
Define a custom STIX object type by assigning an icon

or a color to the node. One of icon or a color must be provided.

Parameters:
  • custom_type (str) – Name of the custom type to define

  • node_icon (str) – URL or local path to the image to use as node icon

  • label_name (str) – name of the field to use as node label

  • color – Color to assign to the node in hex rgb format

Raises:

ValueError – If an attempt is made to add a custom type that is already defined.

add_node(stix_obj)

Add a node to the graph

Parameters:

stix_obj (AttackPattern | Campaign | CourseOfAction | Grouping | Identity | Indicator | Infrastructure | IntrusionSet | Location | Malware | MalwareAnalysis | Note | ObservedData | Opinion | Report | ThreatActor | Tool | Vulnerability | MarkingDefinition | AutonomousSystem | DomainName | EmailAddress | EmailMessage | File | IPv4Address | IPv6Address | MACAddress | NetworkTraffic | URL | UserAccount | str | dict) – STIX Object (SDO, Observable or MarkingDefinition to add to the graph

Return type:

bool

Returns:

True if the node was added correctly

Raises:
  • KeyError – If a custom type does not have any image or color for the node

  • TypeError – If an invalid STIX Domain Object is provided

add_relationship(relationship)

Add a Relationship object to the graph

Parameters:

relationship (Relationship | str | dict) – STIX Relationship Object to add

Return type:

bool

Returns:

True if the relationship is added successfully

Raises:

TypeError – If an invalid Relationship object is provided

save_graph(name, width, height, select_menu=False, filter_menu=False, style='square-flat', show_physics_buttons=False, show_node_buttons=False, show_edge_buttons=False)

Generate and save HTML file containing the graph.

Parameters:
  • name – Name of the file to save the graph as

  • width (str) – Width of the graph section in px

  • height (str) – Height of the graph section in px

  • select_menu (bool) – Enable menu to highlight nodes and the neighborhood

  • filter_menu (bool) – Enable menu to filter nodes and edges based on attributes

  • style (str) –

    Style of node icons. It can be one of the following:

    • square-flat (default)

    • square-dark

    • square-lite

    • noback-flat

    • noback-dark

    • round-flat

  • show_physics_buttons (bool) – Set to True to show graph physics options menu

  • show_node_buttons (bool) – Set to True to show graph node options menu

  • show_edge_buttons (bool) – Set to True to show graph edge options menu

Return type:

str

show_graph(name, width, height, select_menu=False, filter_menu=False, style='square-flat', show_physics_buttons=False, show_node_buttons=False, show_edge_buttons=False)

Generate and return HTML code to render the graph. In case of Jupyter Notebook, the graph is rendered via IPython.display.HTML.

Parameters:
  • name (str) – Name of the output file that will contain the graph

  • height (str) – Height of the graph section in px

  • width (str) – Width of the graph section in px

  • style (str) –

    Style of node icons. It can be one of the following:

    • square-flat (default)

    • square-dark

    • square-lite

    • noback-flat

    • noback-dark

    • round-flat

  • show_physics_buttons (bool) – Set to True to show graph physics options menu

  • show_node_buttons (bool) – Set to True to show graph node options menu

  • show_edge_buttons (bool) – Set to True to show graph edge options menu

Return type:

str

Returns:

HTML code representin the graph. If execute in a Jupyter Notebook, an IPython.display.HTML object is returned

to_json()

Get graph data in JSON format

Return type:

str

Returns:

JSON representation of the graph