G2Config
Version 3.x
Version 2.x
G2Config
modifies an in-memory configuration.
from senzing import G2Config, G2Exception
Configuration object management
init
init()
initializes the G2Config
object. It must be called prior to any other calls.
g2_config.init(g2_object_name, senzing_config_json, verbose_logging)
Parameters
- g2_object_name: (str) A short name given to this instance of the
G2Config
object, to help identify it within system logs.
- senzing_config_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
Example
#! /usr/bin/env python3
from senzing import G2Config, G2Exception
# REPLACE /home/user/your_project with the path to your Senzing project
senzing_config_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 = G2Config()
try:
g2_config.init(
'G2Config',
senzing_config_json,
False)
g2_config.destroy()
except G2Exception as err:
print(err)
create
create()
creates an editable in-memory configuration from the default template configuration JSON stored in the product installation. It also creates a handle pointer to the configuration. The handle is used by the addDataSource(), listDataSources(), deleteDataSource(), and save() methods. The handle is terminated by the close() method.
g2_config.create(config_handle)
Parameters
- config_handle: (int) the handle pointer to the in-memory configuration
Click to expand create() example
Example
#! /usr/bin/env python3
from senzing import G2Config, G2Exception
# REPLACE /home/user/your_project with the path to your Senzing project
senzing_config_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 = G2Config()
saved_config_json = bytearray()
try:
g2_config.init( 'G2Config', senzing_config_json)
config_handle = g2_config.create()
g2_config.save(
config_handle,
saved_config_json)
g2_config.destroy()
print(config_handle)
except G2Exception as err:
print(err)
save
save()
exports an in-memory configuration as a JSON string.
g2_config.save(config_handle, saved_config_json)
Parameters
- config_handle: (int) the handle pointer to the in-memory configuration.
- saved_config_json: (bytearray) Object to store the output of the method.
Click to expand save() example
Example
#! /usr/bin/env python3
from senzing import G2Config, G2Exception
# REPLACE /home/user/your_project with the path to your Senzing project
senzing_config_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 = G2Config()
saved_config_json = bytearray()
try:
g2_config.init( 'G2Config', senzing_config_json)
config_handle = g2_config.create()
g2_config.save(
config_handle,
saved_config_json)
g2_config.destroy()
print(config_handle)
except G2Exception as err:
print(err)
load
load()
creates an editable in-memory configuration from an configuration JSON input string. It also creates a handle pointer to the configuration. The handle is used by the addDataSource(), listDataSources(), deleteDataSource(), and save() methods. The handle is terminated by the close() method.
g2_config.load(config_json)
Parameters
- config_json: (bytearray) the config data to load into the config handle.
Click to expand load() example
Example
#! /usr/bin/env python3
from senzing import G2Config, G2ConfigMgr, G2Exception
# REPLACE /home/user/your_project with the path to your Senzing project
senzing_config_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 = G2Config()
g2_config_mgr = G2ConfigMgr()
current_config_id = bytearray()
config_json = bytearray()
try:
g2_config.init( 'G2Config', senzing_config_json)
g2_config_mgr.init( 'G2Config', senzing_config_json)
g2_config_mgr.getDefaultConfigID(current_config_id)
g2_config_mgr.getConfig(current_config_id.decode(), config_json)
g2_config.load(config_json)
g2_config.destroy()
except G2Exception as err:
print(err)
Datasource management
listDataSources
listDataSources()
returns a list of data sources contained in an in-memory configuration.
g2_config.listDataSources(config_handle, response_bytearray)
Parameters
- config_handle: (int) the handle pointer to the in-memory configuration.
- response_bytearray: (bytearray) Object to store the output of the method.
Click to expand listDataSources() example
Example
#! /usr/bin/env python3
from senzing import G2Config, G2ConfigMgr, G2Exception
# REPLACE /home/user/your_project with the path to your Senzing project
senzing_config_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 = G2Config()
g2_config_mgr = G2ConfigMgr()
current_config_id = bytearray()
config_json = bytearray()
response_bytearray = bytearray()
try:
g2_config.init( 'G2Config', senzing_config_json)
g2_config_mgr.init( 'G2Config', senzing_config_json)
g2_config_mgr.getDefaultConfigID(current_config_id)
g2_config_mgr.getConfig(current_config_id.decode(), config_json)
config_handle = g2_config.load(config_json)
g2_config.listDataSources(config_handle, response_bytearray)
g2_config.close(config_handle)
print(response_bytearray.decode())
g2_config.destroy()
except G2Exception as err:
print(err)
Output
{"id": 1, "dataSource": "TEST"}
{"id": 2, "dataSource": "SEARCH"}
{"id": 1001, "dataSource": "CUSTOMERS"}
{"id": 1002, "dataSource": "WATCHLIST"}
{"id": 1003, "dataSource": "REFERENCE"}
addDataSource
addDataSource()
adds a new data source to a G2Config
object.
g2_config.addDataSource(config_handle, datasource_json, response_bytearray)
Parameters
- config_handle: (int) the handle pointer to the in-memory configuration.
- datasource_json: (str) A JSON document in the format
{"DSRC_CODE": "NAME_OF_DATASOURCE"}
- response_bytearray: (bytearray) Object to store the output of the method.
Click to expand addDataSource() example
Example
#! /usr/bin/env python3
from senzing import G2Config, G2Exception
# REPLACE /home/user/your_project with the path to your Senzing project
senzing_config_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 = G2Config()
try:
datasource = {
"DSRC_CODE": "CUSTOMERS2"
}
datasource_json = json.dumps(datasource)
response_bytearray = bytearray()
g2_config.addDataSource(
config_handle,
datasource_json,
response_bytearray)
print(response_bytearray.decode())
except G2Exception as err:
print(err)
Output
deleteDataSource
deleteDataSource()
removes a data source from a G2Config
object.
g2_config.deleteDataSource(config_handle, datasource_json)
Parameters
- config_handle: (int) the handle pointer to the in-memory configuration.
- datasource_json: (str) A JSON document in the format
{"DSRC_CODE": "NAME_OF_DATASOURCE"}
Click to expand deleteDataSource() example
Example
#! /usr/bin/env python3
from senzing import G2Config, G2Exception
# REPLACE /home/user/your_project with the path to your Senzing project
senzing_config_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 = G2Config()
g2_config_mgr = G2ConfigMgr()
current_config_id = bytearray()
config_json = bytearray()
response_bytearray = bytearray()
datasource = {
"DSRC_CODE": "CUSTOMERS2"
}
datasource_json = json.dumps(datasource)
try:
g2_config.init( 'G2Config', senzing_config_json)
g2_config_mgr.init( 'G2Config', senzing_config_json)
g2_config_mgr.getDefaultConfigID(current_config_id)
g2_config_mgr.getConfig(current_config_id.decode(), config_json)
config_handle = g2_config.load(config_json)
g2_config.deleteDataSource(
config_handle,
datasource_json)
g2_config.close(config_handle)
g2_config.destroy()
except G2Exception as err:
print(err)
Configuration object cleanup
close
close()
cleans up an in-memory configuration.
g2_config.close(config_handle)
Parameters
- config_handle: (int) the handle pointer to the in-memory configuration.
Click to expand close() example
Example
#! /usr/bin/env python3
from senzing import G2Config, G2Exception
# REPLACE /home/user/your_project with the path to your Senzing project
senzing_config_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 = G2Config()
try:
g2_config.close()
except G2Exception as err:
print(err)
destroy
destroy()
destroys and performs cleanup for the G2Config
object and any in-memory configurations.
g2_config.destroy(config_handle)
Click to expand destroy() example
Example
#! /usr/bin/env python3
from senzing import G2Config, G2Exception
# REPLACE /home/user/your_project with the path to your Senzing project
senzing_config_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 = G2Config()
try:
g2_config.destroy()
except G2Exception as err:
print(err)