Senzing v3 G2ConfigMgr

G2ConfigMgr modifies Senzing configurations in the Senzing database.

from senzing import G2ConfigMgr, G2Exception

init

init() initializes the G2ConfigMgr object. It must be called prior to any other calls.

g2_config_mgr.init(g2_object_name, senzing_engine_configuration_json, verbose_logging)
Parameters
  • g2_object_name: (str) A short name given to this instance of the G2ConfigMgr object, to help identify it within system logs.
  • senzing_engine_configuration_json: (str) A JSON string containing configuration parameters.
  • verbose_logging: (bool [optional]) (default False) Enables diagnostic logging. False for no logging; True for logging.
Click to expand init() example Click to collapse
Example
#! /usr/bin/env python3

from senzing import G2ConfigMgr, G2Exception

# REPLACE /home/user/your_project with the path to your Senzing project
senzing_engine_configuration_json = '{ "PIPELINE": { "CONFIGPATH": "/home/user/your_project/etc", "SUPPORTPATH": "/home/user/your_project/data", "RESOURCEPATH": "/home/user/your_project/resources" }, "SQL": { "CONNECTION": "sqlite3://na:na@/home/user/your_project/var/sqlite/G2C.db" } }'

g2_config_mgr = G2ConfigMgr()

try:
    g2_config_mgr.init(
        'G2ConfigMgr',
        senzing_engine_configuration_json,
        False)

    g2_config_mgr.destroy()

except G2Exception as err:
    print(err)

addConfig

addConfig() adds a configuration JSON document to the Senzing database.

g2_config_mgr.addConfig(senzing_engine_configuration_json, config_comment, config_id_bytearray)
Parameters
  • senzing_er_configuration_json: (JSON str) The configuration JSON document.
  • config_comment: (str) A free-form string of comments describing the configuration document.
  • config_id_bytearray: (bytearray) The returned configID for the new config document registered in the data store.
Click to expand addConfig() example Click to collapse
Example
#! /usr/bin/env python3

from senzing import G2ConfigMgr, G2Exception

# REPLACE /home/user/your_project with the path to your Senzing project
senzing_engine_configuration_json = '{ "PIPELINE": { "CONFIGPATH": "/home/user/your_project/etc", "SUPPORTPATH": "/home/user/your_project/data", "RESOURCEPATH": "/home/user/your_project/resources" }, "SQL": { "CONNECTION": "sqlite3://na:na@/home/user/your_project/var/sqlite/G2C.db" } }'

g2_config_mgr = G2ConfigMgr()

with open('Senzing_config_to_add.json', 'r') as file:
    senzing_er_configuration_json = file.read().strip()

config_id_bytearray = bytearray()

try:
    g2_config_mgr.init( 'G2ConfigMgr', senzing_engine_configuration_json)

    g2_config_mgr.addConfig(
        senzing_er_configuration_json,
        'Added a configuration',
        config_id_bytearray)

    g2_config_mgr.destroy()

    print(F"Config ID: {config_id_bytearray.decode()}")

except G2Exception as err:
    print(err)
Output
Configuration id: 2180518637

getConfigList

getConfigList() retrieves a list of the configuration JSON documents contained in the data repository.

g2_config_mgr.getConfigList(response_bytearray)
Parameters
  • response_bytearray: (bytearray) Object to store the output of the method.
Click to expand getConfigList() example Click to collapse
Example
#! /usr/bin/env python3

from senzing import G2ConfigMgr, G2Exception

# REPLACE /home/user/your_project with the path to your Senzing project
senzing_engine_configuration_json = '{ "PIPELINE": { "CONFIGPATH": "/home/user/your_project/etc", "SUPPORTPATH": "/home/user/your_project/data", "RESOURCEPATH": "/home/user/your_project/resources" }, "SQL": { "CONNECTION": "sqlite3://na:na@/home/user/your_project/var/sqlite/G2C.db" } }'

g2_config_mgr = G2ConfigMgr()

response_bytearray = bytearray()

try:
    g2_config_mgr.init( 'G2ConfigMgr', senzing_engine_configuration_json)

    g2_config_mgr.getConfigList(response_bytearray)

    g2_config_mgr.destroy()

    print(response_bytearray.decode())

except G2Exception as err:
    print(err)
Output
{
  "CONFIGS": [
    {
      "CONFIG_ID": 403343571,
      "CONFIG_COMMENTS": "Configuration added from G2SetupConfig.",
      "SYS_CREATE_DT": "2022-11-21 22:21:02.343"
    }
  ]
}

getConfig

getConfig() retrieves a specific configuration JSON document from the data repository.

g2_config_mgr.getConfig(config_id_bytearray, response_bytearray)
Parameters
  • config_id_bytearray: (bytearray) The configID for the config document that you wish to retrieve.
  • response_bytearray: (bytearray) Object to store the output of the method.
Click to expand getConfig() example Click to collapse
Example
#! /usr/bin/env python3

from senzing import G2ConfigMgr, G2Exception

# REPLACE /home/user/your_project with the path to your Senzing project
senzing_engine_configuration_json = '{ "PIPELINE": { "CONFIGPATH": "/home/user/your_project/etc", "SUPPORTPATH": "/home/user/your_project/data", "RESOURCEPATH": "/home/user/your_project/resources" }, "SQL": { "CONNECTION": "sqlite3://na:na@/home/user/your_project/var/sqlite/G2C.db" } }'

g2_config_mgr = G2ConfigMgr()

current_config_id = bytearray()

response_bytearray = bytearray()

try:
    g2_config_mgr.init( 'G2ConfigMgr', senzing_engine_configuration_json)

    g2_config_mgr.getDefaultConfigID(current_config_id)

    g2_config_mgr.getConfig(
        current_config_id,
        response_bytearray)

    g2_config_mgr.destroy()

    print(response_bytearray.decode())

except G2Exception as err:
    print(err)
Output
Configuration ID: 2425495991

getDefaultConfigID

getDefaultConfigID() retrieves a specific configuration ID from the data repository.

g2_config_mgr.getDefaultConfigID(config_id_bytearray)
Parameters
  • config_id_bytearray: (bytearray) Returns the configID for the current default configuration, or 0 if none is set.
Click to expand getDefaultConfigID() example Click to collapse
Example
#! /usr/bin/env python3

from senzing import G2ConfigMgr, G2Exception

# REPLACE /home/user/your_project with the path to your Senzing project
senzing_engine_configuration_json = '{ "PIPELINE": { "CONFIGPATH": "/home/user/your_project/etc", "SUPPORTPATH": "/home/user/your_project/data", "RESOURCEPATH": "/home/user/your_project/resources" }, "SQL": { "CONNECTION": "sqlite3://na:na@/home/user/your_project/var/sqlite/G2C.db" } }'

g2_config_mgr = G2ConfigMgr()

config_id_bytearray = bytearray()

try:
    g2_config_mgr.init( 'G2ConfigMgr', senzing_engine_configuration_json)

    g2_config_mgr.getDefaultConfigID(config_id_bytearray)

    g2_config_mgr.destroy()

except G2Exception as err:
    print(err)

print(F"Configuration ID: {config_id_bytearray.decode()}")
Output
Configuration ID: 2425495991

setDefaultConfigID

setDefaultConfigID() sets the default configuration JSON document in the data repository.

g2_config_mgr.setDefaultConfigID(config_id_bytearray)
Parameters
  • config_id_bytearray: (bytearray or int) The configuration ID for a configuration JSON document previously added to the database.
Click to expand setDefaultConfigID() example Click to collapse
Example
#! /usr/bin/env python3

from senzing import G2ConfigMgr, G2Exception

# REPLACE /home/user/your_project with the path to your Senzing project
senzing_engine_configuration_json = '{ "PIPELINE": { "CONFIGPATH": "/home/user/your_project/etc", "SUPPORTPATH": "/home/user/your_project/data", "RESOURCEPATH": "/home/user/your_project/resources" }, "SQL": { "CONNECTION": "sqlite3://na:na@/home/user/your_project/var/sqlite/G2C.db" } }'

g2_config_mgr = G2ConfigMgr()

default_config_id_bytearray = bytearray()

config_id_bytearray = default_config_id_bytearray

try:
    g2_config_mgr.init( 'G2ConfigMgr', senzing_engine_configuration_json)

    g2_config_mgr.getDefaultConfigID(default_config_id_bytearray)

    g2_config_mgr.setDefaultConfigID(config_id_bytearray)

    g2_config_mgr.destroy()

except G2Exception as err:
    print(err)

replaceDefaultConfigID

getDefaultConfigID() checks the current default configuration ID, and if it matches, replaces it with another configured ID in the database.

g2_config_mgr.replaceDefaultConfigID(config_id_bytearray, new_config_id_bytearray)
Parameters
  • default_config_id_bytearray: (bytearray) The current default configuration value to verify.
  • new_config_id_bytearray: (bytearray) The new configID value.
Click to expand replaceDefaultConfigID() example Click to collapse
Example
#! /usr/bin/env python3

from senzing import G2ConfigMgr, G2Exception

# REPLACE /home/user/your_project with the path to your Senzing project
senzing_engine_configuration_json = '{ "PIPELINE": { "CONFIGPATH": "/home/user/your_project/etc", "SUPPORTPATH": "/home/user/your_project/data", "RESOURCEPATH": "/home/user/your_project/resources" }, "SQL": { "CONNECTION": "sqlite3://na:na@/home/user/your_project/var/sqlite/G2C.db" } }'

g2_config_mgr = G2ConfigMgr()

default_config_id_bytearray = bytearray()

new_config_id_bytearray = default_config_id_bytearray

try:
    g2_config_mgr.init( 'G2ConfigMgr', senzing_engine_configuration_json)

    g2_config_mgr.getDefaultConfigID(default_config_id_bytearray)

    g2_config_mgr.replaceDefaultConfigID(
            default_config_id_bytearray,
            new_config_id_bytearray)

    g2_config_mgr.destroy()

except G2Exception as err:
    print(err)

Cleanup

destroy

destroy() destroys and performs cleanup for G2Config.

g2_config_mgr.destroy()
Click to expand destroy() example Click to collapse
Example
#! /usr/bin/env python3

from senzing import G2ConfigMgr, G2Exception

# REPLACE /home/user/your_project with the path to your Senzing project
senzing_engine_configuration_json = '{ "PIPELINE": { "CONFIGPATH": "/home/user/your_project/etc", "SUPPORTPATH": "/home/user/your_project/data", "RESOURCEPATH": "/home/user/your_project/resources" }, "SQL": { "CONNECTION": "sqlite3://na:na@/home/user/your_project/var/sqlite/G2C.db" } }'

g2_config_mgr = G2ConfigMgr()

try:
    g2_config_mgr.destroy()

except G2Exception as err:
    print(err)

If you have any questions, contact Senzing Support. Support is 100% FREE!