Python API for generating Maltego mtgx files.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Python API for generating Maltego mtgx files.


$ python install


import pymtgx
mtgx = pymtgx.Pymtgx()
id1 = mtgx.add_node("maltego.EmailAddress", "")
id2 = mtgx.add_node("maltego.EmailAddress", "")
id3 = mtgx.add_node("maltego.EmailAddress", "")
mtgx.add_edge(id1, id2)
mtgx.add_edge(id1, id3, "I am edge label")

The importer

The API comes with a built-in importer, capable of generating mtgx archives from CSV files based on some format specification file. The format specification file can either be based on column name or column index.

Basic usage:

$ python pymtgx/ -h
usage: [-h] -i INPUT_FILE -f FORMAT_FILE -o OUTPUT_FILE -e
                   ENTITY_FILES [-d DELIMITER] [-q QUOTECHAR] [-s SKIP_LINES]
                   [-m MAP_HEADER]

optional arguments: -h, --help show this help message and exit -i INPUT_FILE, --input-file INPUT_FILE Path to file to parse -f FORMAT_FILE, --format-file FORMAT_FILE Path to format specification file. -o OUTPUT_FILE, --output-file OUTPUT_FILE Path to output file. Extension is added if missing. -e ENTITY_FILES, --entity-files ENTITY_FILES Comma separated list of .mtz files to use. -d DELIMITER, --delimiter DELIMITER How values are delimited. Default: , -q QUOTECHAR, --quotechar QUOTECHAR How values are quoted, remember escape character. Default: None -s SKIP_LINES, --skip-lines SKIP_LINES Number of lines to skip. Default: 0 -m MAP_HEADER, --map-header MAP_HEADER Use column names in format specification. If not, the columns in the specifications are 0-indexed.

The general syntax for entity and edge specifications is:


The entity types field must match one of the entity types registered using the '-e' option, without the 'maltego.' prefix.

Example for specification file using column index:

0:Person > 2:EmailAddress | Edge label 1
0:Person > 1:Person | Edge label 2
2:EmailAddress > 1:Person | Edge label 3

Example for specification file using column names:

Col1:Person > Col3:EmailAddress | Edge label 1
Col1:Person > Col2:Person | Edge label 2
Col3:EmailAddress > Col2:Person | Edge label 3

Both of these are capable of parsing the input CSV file:


Example runs:

Based on column index:

$ python -m pymtgx.importer -i test/importer/data.csv -f test/importer/indexed.format -o index_test.mtgx -e test/test_entities.mtz -q \"
Parsed 3 lines. Created index_test.mtgx

Based on column name:

$ python -m pymtgx.importer -i test/importer/data.csv -f test/importer/mapped.format -o mapped_test.mtgx -e test/test_entities.mtz -m True -q \"
Parsed 3 lines. Created mapped_test.mtgx