SDK API Reference

Modified on Tue, 14 Jul at 11:37 AM

This article is the consolidated API reference for the Maltego Transforms SDK (maltego-transforms): the core classes you import from maltego.server (and a couple of supporting modules) when writing transforms, entities, and transform servers. For these classes used in context, see the SDK Examples and Writing Your First Transform (Quickstart) articles in this folder.

MaltegoGraph

MaltegoGraph (maltego.server.MaltegoGraph, defined in maltego.model.graph) represents a Maltego graph as provided to a transform function: a collection of entities and the links between them. Use it as a transform's input type to receive a whole selection of entities, or as a return type to produce multiple entities with custom links between them.

Use MaltegoGraph as an input annotation to receive the entire selected graph:

from maltego.server import register_transform, MaltegoGraph
from maltego.entities import Phrase


@register_transform(
    display_name="Count Entities and Links [My Transforms]",
)
async def count_graph(graph: MaltegoGraph) -> Phrase:
    num_entities = len(graph.entities)
    num_links = len(graph.links)
    return Phrase(f"Graph has {num_entities} entities and {num_links} links")

To restrict the graph to specific entity types, use a generic type parameter, e.g. MaltegoGraph[Person] (this also restricts which selections the transform appears for in the client). A transform can also return a MaltegoGraph to produce multiple entities with custom links between them, built via graph.add_entity() and graph.add_link():

from maltego.server import register_transform, MaltegoGraph
from maltego.entities import Phrase


@register_transform(
    display_name="Create Linked Chain [My Transforms]",
)
async def create_chain(graph: MaltegoGraph) -> MaltegoGraph:
    # Add entities to the output graph
    previous = graph.add_entity(Phrase("Start"))


    for i in range(5):
        entity = graph.add_entity(Phrase(f"Node {i}"))
        # Create a link between entities
        graph.add_link(previous, entity)
        previous = entity


    return graph

Links can be traversed with graph.get_source() / graph.get_target():

from maltego.server import register_transform, MaltegoGraph
from maltego.entities import Phrase


@register_transform(
    display_name="Analyze Connections [My Transforms]",
)
async def analyze_links(graph: MaltegoGraph) -> Phrase:
    for link in graph.links:
        source = graph.get_source(link)  # Source entity
        target = graph.get_target(link)  # Target entity
        label = link.label               # Link label (if any)
        # Analyze the relationship...


    return Phrase(f"Analyzed {len(graph.links)} connections")

These examples aren't exhaustive; see the SDK Examples article for more variations, including using Union types to accept multiple entity types in a typed graph input.

Constructor parameters:

ParameterTypeDescription
entitiesOptional[List[MaltegoEntity]]Entities to seed the graph with.
linksOptional[List[MaltegoLink]]Links to seed the graph with. Each link's source/target entity must already be in entities, or a ValueError is raised.

Key methods and properties:

Method / PropertyDescriptionReturns
graph.entitiesAll entities currently in the graph.List[MaltegoEntity]
graph.linksAll links currently in the graph.List[MaltegoLink]
graph.add_entity(entity)Adds a single entity. Raises TypeError if not a MaltegoEntity.MaltegoEntity
graph.add_entities(entities)Adds a list of entities. Raises ValueError if input is not a list.List[MaltegoEntity]
graph.delete_entity(entity)Deletes a single entity from the graph.Optional[MaltegoEntity]
graph.delete_entity_by_id(entity_id)Deletes a single entity, looked up by its graph entity ID.Optional[MaltegoEntity]
graph.add_child(entity, child, link_properties=None)Adds child to the graph and links it to entity, using the child entity's own link style/color/label/thickness settings.MaltegoEntity
graph.add_link(source, target, is_reversed=False, style=LinkStyle.NORMAL, color=LinkColor.NONE, thickness=LinkThickness.THICKNESS_DEFAULT, properties=None, label=None)Adds a link between two entities (adding either entity to the graph first if not already present).MaltegoLink
graph.delete_link(link)Deletes a link from the graph.Optional[MaltegoLink]
graph.get_entity_by_id(entity_id)Returns the entity with the given graph entity ID, if present.Optional[MaltegoEntity]
graph.get_entities_of_type(entity_type_id)Returns all entities matching a given type ID (e.g. "maltego.Phrase").List[MaltegoEntity]
graph.get_entities_by_property(property_name)Returns all entities that have a property matching the given name.List[MaltegoEntity]
graph.get_link_from(entity) / graph.get_links_from(entity)Returns the first / all links originating from the given entity.Optional[MaltegoLink] / List[MaltegoLink]
graph.get_link_to(entity) / graph.get_links_to(entity)Returns the first / all links pointing to the given entity.Optional[MaltegoLink] / List[MaltegoLink]
graph.get_link_between(source_entity, target_entity)Returns the link between two given entities, if one exists.Optional[MaltegoLink]
graph.get_links_from_and_to(source_entity, target_entity)Returns all links between two given entities in either direction.List[MaltegoLink]
graph.get_source(link) / graph.get_target(link)Resolves a link's source / target entity object.MaltegoEntity

MaltegoEntity

MaltegoEntity (maltego.server.MaltegoEntity, defined in maltego.model.entity) is the typed base class for all Maltego entities. Transform inputs and outputs are MaltegoEntity subclasses (either the standard entities from maltego.entities or custom entities you define), and custom entity classes are declared as Python classes decorated with @register_entity.

Constructor parameters (also available as instance attributes/properties):

ParameterTypeDescription
valueAnyThe entity's value, e.g. Phrase("Hello World").
weightint, default 100Entity weight, shown in the Maltego client.
maltego_entity_idOptional[str]Graph-unique entity ID; auto-generated if omitted.
icon_urlOptional[str]URL of a custom icon overlay for this entity.
propertiesOptional[Dict[str, _MaltegoEntityProperty]]Initial property values.
noteOptional[str]Free-text annotation shown on the entity in the client.
display_informationOptional[List[_DisplayInformationItem]]Display labels/fields shown in the entity detail view.
bookmarkOptional[Bookmark]Bookmark color for the entity node.
link_label, reverse_link, link_style, link_color, link_thicknessOptional[str], bool, LinkStyle, LinkColor, LinkThicknessStyling applied to the link leading into this entity when it is added as a child of another entity.
overlaysOptional[List[Overlay]]Icon/text overlays shown on the entity node.

Key methods:

MethodDescriptionReturns
entity.get_property(name, default_value=None)Returns a property's value by its property ID, or default_value if the property is absent/unset.property value or None
entity.set_property(name, value, display_name=None, matching_rule=None, try_parsing=True, property_type=None)Sets a property to a value, translating internal property names to the class attribute namespace as needed.None
entity.has_property(property_name)Whether the entity currently has the given property.bool
entity.get_properties()All properties currently set on the entity.Dict[str, ...]
entity.add_display_label(name, value, content_type="text/html")Adds a display label to the entity detail view (HTML or Markdown content).None
entity.add_display_field(name, value, content_type="text/html")Adds a display field to the entity detail view.None
entity.add_overlay(overlay_type, position, property_name)Adds an icon/text overlay to the entity node, sourced from a property's value.None
entity.icon_url (property)Gets/sets the entity's icon overlay URL.Optional[str]
entity.weight (property)Gets/sets the entity's weight.int
entity.note (property)Gets/sets the entity's note annotation.Optional[str]

MaltegoEntityConfig

MaltegoEntityConfig (maltego.server.MaltegoEntityConfig, defined in maltego.model.entity.config) configures how a custom entity class is displayed and categorized in the Maltego client. It is assigned to a custom entity's Config class attribute.

Constructor parameters (all optional):

ParameterTypeDescription
value_propertyOptional[str]Name of the property used as the entity's value.
value_keyOptional[str]Property key used as the entity's value (alternate lookup to value_property).
display_nameOptional[str]Singular display name shown in the Maltego client.
display_name_pluralOptional[str]Plural display name; defaults to f"{display_name}s".
descriptionOptional[str]Entity description text.
categoryOptional[str]Client-side category grouping; defaults to "Custom".
allowed_rootbool, default TrueWhether this entity type can be used as a graph root.
overlaysOptional[List[Overlay]]Default overlays for this entity type.
overlay_image_propertyOptional[str]Property used to source an image overlay.
icon_resourceOptional[Union[str, Tuple[str, str]]]Icon resource name, or a (name, path) tuple.
display_propertyOptional[str]Name of the property shown as the entity's display value; falls back to value_property if not set.
display_keyOptional[str]Property key shown as the entity's display value; falls back to value_key if not set.
conversion_orderOptional[int]Ordering hint used when the client resolves overlapping entity type conversions.
converterOptional[MaltegoEntityRegexConverter]Regex-based value converter for this entity type.
actionsOptional[List[MaltegoEntityAction]]Client-side actions (e.g. "open in browser") available on this entity type.

MaltegoEntityProperty

MaltegoEntityProperty (maltego.server.MaltegoEntityProperty, a function defined in maltego.model.entity.property) declares a single property on a custom entity class.

from maltego.entities import Person
from maltego.server import (
    MaltegoEntityConfig,
    MaltegoEntityProperty,
    register_entity,
)


@register_entity
class StaffMember(Person):
    Config = MaltegoEntityConfig(display_name="Staff Member")


    employee_id: str = MaltegoEntityProperty(
        display_name="Employee ID",
        sample_value="E-42",
    )

Parameters:

ParameterTypeDescription
display_nameOptional[str]Display name of this property in the Maltego client.
nameOptional[str]Property ID used to reference the property in the client.
matching_ruleMatchingRule, default MATCHING_RULE_STRICTWhether this property participates in the client's entity merge algorithm.
valueOptional[EntityPropertyType]Default value when used to define a full entity.
descriptionstr, default ""Property description.
hiddenbool, default FalseIf True, the property is not shown in the Maltego client.
readonlybool, default FalseWhether the property can be modified by the user.
nullablebool, default TrueWhether the property can have no value.
sample_valueOptional[EntityPropertyType]Sample value shown by the Maltego client.
evaluatorOptional[str]Optional evaluator reference for the property.

MaltegoLink (maltego.server.MaltegoLink, defined in maltego.model.link) represents a link between two entities in a MaltegoGraph. Links are usually created via graph.add_link() or graph.add_child() rather than instantiated directly.

Constructor parameters:

ParameterTypeDescription
source_idstrGraph entity ID of the link's source entity.
target_idstrGraph entity ID of the link's target entity.
is_reversedbool, default FalseWhether the link direction is reversed.
styleLinkStyle, default LinkStyle.NORMALVisual style of the link line.
colorLinkColor, default LinkColor.NONEColor of the link line.
thicknessLinkThickness, default LinkThickness.THICKNESS_DEFAULTThickness of the link line.
labelOptional[str]Text label shown on the link.
maltego_link_idOptional[str]Graph-unique link ID; auto-generated if omitted.
propertiesOptional[Dict[str, MaltegoLinkProperty]]Initial custom link properties.

Key methods and properties:

Method / PropertyDescriptionReturns
link.get_property(name, default_value=None)Returns a link property's value, or default_value if absent/unset.property value or None
link.set_property(name, value, display_name=None)Sets a link property to a given value.None
link.get_properties()All properties currently set on the link.Dict[str, MaltegoLinkProperty]
link.is_reversed (property)Whether the link is reversed.bool
link.style (property)The link's style.int
link.color (property)The link's color.Optional[str]
link.thickness (property)The link's thickness.Optional[int]
link.label (property)The link's text label.Optional[str]

TransformSetting

TransformSetting (maltego.server.TransformSetting, defined in maltego.model.transform.setting) defines a configurable transform setting: a value the Maltego client lets the user provide per-transform (such as an API key or a numeric limit).

Constructor parameters:

ParameterTypeDescription
namestrName of the setting as referenced later in the transform function. Must be 1-128 characters, starting with a letter, digit, or underscore.
display_namestrName shown to the user in the Maltego client.
typeUnion[TransformSetting.Types, str], default Types.strThe setting's type: str, float, int, boolean, date, datetime, or datetime_range. Only five of these have a _list variant for multi-value settings: str_list, float_list, int_list, boolean_list, and date_list (there is no datetime_list or datetime_range_list).
default_valueOptional[MaltegoSettingTypes]Default value for the setting.
optionalbool, default TrueSet to False to make the setting required on every transform execution.
popupbool, default FalseSet to True to force a settings popup on each execution.
is_globalbool, default FalseShares one stored setting value across transforms in the same namespace.
is_global_settingbool, default FalseDeprecated compatibility alias for is_global (identical behavior); emits a DeprecationWarning if used.
authbool, default FalseMarks the setting as an authentication-related value.
is_oauthbool, default FalseMarks the setting as an OAuth-related value.
use_raw_namebool, default FalseUses name verbatim instead of the SDK's namespaced setting name.

For usage guidance, naming behavior, and worked examples, see the Transform Settings article in this folder.

MaltegoContext

MaltegoContext (maltego.server.MaltegoContext, defined in maltego.model.context) is the server-side execution context passed into a transform function, carrying request data, logging, prompts, and authentication information for the current transform run.

Selected constructor parameters (a MaltegoContext is built by the SDK server, not typically constructed by transform authors):

ParameterTypeDescription
graphMaltegoGraphThe input graph for this transform run.
requestfastapi.RequestThe underlying FastAPI request object.
api_keyOptional[str]API key supplied with the request, if any.
remote_ipOptional[str]Remote IP address of the caller.
identityOptional[Identity]Verified caller identity from trusted auth validation.
unverified_auth_claimsOptional[Dict[str, Any]]Syntactically decoded bearer JWT/OIDC or SAML claims, populated only when AuthSettings(expose_unverified_claims=True) (or the equivalent environment variable) is set.

Key attributes and methods:

Attribute / MethodDescriptionReturns
context.graphThe input MaltegoGraph for this run.MaltegoGraph
context.logA LogCollector for sending UI messages back to the client, with inform(message), fatal(message), debug(message), and partial(message) methods.LogCollector
context.request (property)The underlying FastAPI Request object.fastapi.Request
context.user_agent (property)The request's User-Agent header, if present.Optional[str]
context.get_request_headers()Returns the request headers as a dictionary.Dict[str, Any]
context.identityVerified caller identity (from trusted auth validation only).Optional[Identity]
context.choice_prompt(...) / context.multi_choice_prompt(...)Display a popup dialog (single- or multi-select) to the user and await their response mid-transform.TransformPromptResponse

Authentication fields

context.identity is populated only from trusted auth validation results. When AuthSettings(expose_unverified_claims=True) or MALTEGO_SERVER_AUTH_EXPOSE_UNVERIFIED_CLAIMS=true is configured, context.unverified_auth_claims may contain syntactically decoded bearer JWT/OIDC or SAML claims. This can be enabled even when auth validation itself is disabled. Those claims are not signature-verified and must not be used for authorization, tenancy, billing, auditing, or rate limiting.

TransformMiddleware

TransformMiddleware (maltego.middlewares.middlewares.TransformMiddleware) is an abstract base class for hooking into the transform execution lifecycle. Subclass it and implement both abstract methods to run custom logic before and after every transform execution.

Class attributeDescription
call_on_failureClass attribute, default True. Whether after_transform should still be called if the transform raised an exception.

Abstract methods to implement:

MethodDescription
async before_transform(transform, transform_input, properties, context, soft_limit, hard_limit)Called before a transform executes. Receives the MaltegoTransform object, the input entity/entities/graph, the transform settings sent by the client, the MaltegoContext, and the client's requested (soft) and maximum (hard) entity limits.
async after_transform(transform, transform_input, output_entities, context, state, exceptions=None)Called after a transform executes. Receives the same transform/input/context, plus the transform's output entities, its final ExecutionState, and any exceptions raised during execution.

For middleware lifecycle guidance and registration examples, see the Transform Middlewares article in this folder.

MaltegoHubItem

MaltegoHubItem (maltego.server.MaltegoHubItem, defined in maltego.model.server) defines the metadata shown for an integration in the Maltego Hub: display name, description, icon, preview image, and provider contact details. Values can also be supplied via environment variables, since the class is a Pydantic BaseSettings model.

FieldTypeDescription
display_nameOptional[str]Hub item display name.
descriptionOptional[str]Hub item description.
icon_urlOptional[str]URL pointing to an icon (PNG) shown in the hub item panel.
preview_image_urlOptional[str]A preview image showcasing a graph, shown in the hub item's detail view.
provider_nameOptional[str]Name of the transform developer, shown in the details view.
provider_websiteOptional[str]Website of the transform developer, shown in the details view.
provider_emailOptional[str]Transform developer email, shown in the details view.
provider_phoneOptional[str]Developer phone number, shown in the details view.

For when to define a hub item and how to register it, see the Hub Items article in this folder.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article