diff --git a/CHANGELOG.md b/CHANGELOG.md index f7b03de..0b518ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog], [markdownlint], and this project adheres to [Semantic Versioning]. +## [0.0.9] - 2025-07-23 + +### Changed in 0.0.9 + +- Modify method names changed in SDK +- Additional snippets + ## [0.0.8] - 2025-06-20 ### Changed in 0.0.8 diff --git a/python/configuration/README.md b/python/configuration/README.md index b586a60..9222c7e 100644 --- a/python/configuration/README.md +++ b/python/configuration/README.md @@ -2,6 +2,12 @@ Configuration related examples. ## Snippets -* **add_data_sources.py** - * Add new data source codes. +* **get_config_registry.py** + * Gets the configuration registry detailing existing configurations. +* **get_data_source_registry.py** + * Gets the data source registry detailing configured data sources in the current default configuration. +* **init_default_config.py** + * Initializes the repository with a default configuration using the default configuration template. +* **register_data_sources.py** + * Retrieves the current default configuration, registers new data source codes in it, registers the new configuration and makes it the current default configuration. diff --git a/python/configuration/get_config_registry.py b/python/configuration/get_config_registry.py new file mode 100755 index 0000000..f188db8 --- /dev/null +++ b/python/configuration/get_config_registry.py @@ -0,0 +1,20 @@ +#! /usr/bin/env python3 + +import os +import sys +from pathlib import Path + +from senzing import SzError +from senzing_core import SzAbstractFactoryCore + +INSTANCE_NAME = Path(__file__).stem +SETTINGS = os.getenv("SENZING_ENGINE_CONFIGURATION_JSON", "{}") + + +try: + sz_factory = SzAbstractFactoryCore(INSTANCE_NAME, SETTINGS, verbose_logging=False) + sz_configmanager = sz_factory.create_configmanager() + response = sz_configmanager.get_config_registry() + print(response) +except SzError as err: + print(f"{err.__class__.__name__} - {err}", file=sys.stderr) diff --git a/python/configuration/add_data_sources.py b/python/configuration/get_data_source_registry.py similarity index 54% rename from python/configuration/add_data_sources.py rename to python/configuration/get_data_source_registry.py index fe3d95c..6bcd29e 100755 --- a/python/configuration/add_data_sources.py +++ b/python/configuration/get_data_source_registry.py @@ -12,20 +12,12 @@ try: - sz_factory = SzAbstractFactoryCore("add_data_source", SETTINGS, verbose_logging=False) + sz_factory = SzAbstractFactoryCore(INSTANCE_NAME, SETTINGS, verbose_logging=False) sz_configmanager = sz_factory.create_configmanager() config_id = sz_configmanager.get_default_config_id() sz_config = sz_configmanager.create_config_from_config_id(config_id) - - for data_source in ("CUSTOMERS", "REFERENCE", "WATCHLIST"): - _ = sz_config.add_data_source(data_source) - - new_config = sz_config.export() - new_config_id = sz_configmanager.set_default_config(new_config, "Add data source CUSTOMERS") - - sz_config = sz_configmanager.create_config_from_config_id(new_config_id) - response = sz_config.get_data_sources() + response = sz_config.get_data_source_registry() print(response) except SzError as err: print(f"{err.__class__.__name__} - {err}", file=sys.stderr) diff --git a/python/configuration/init_default_config.py b/python/configuration/init_default_config.py new file mode 100755 index 0000000..b93f879 --- /dev/null +++ b/python/configuration/init_default_config.py @@ -0,0 +1,28 @@ +#! /usr/bin/env python3 + +import os +import sys +from pathlib import Path + +from senzing import SzError +from senzing_core import SzAbstractFactoryCore + +EXISTING_CONFIG_MSG = "\nA configuration exists in the repository, replace it with a template configuration? (y/n) " +INSTANCE_NAME = Path(__file__).stem +SETTINGS = os.getenv("SENZING_ENGINE_CONFIGURATION_JSON", "{}") + + +try: + sz_factory = SzAbstractFactoryCore(INSTANCE_NAME, SETTINGS, verbose_logging=False) + sz_configmanager = sz_factory.create_configmanager() + + if current_config_id := sz_configmanager.get_default_config_id(): + if not input(EXISTING_CONFIG_MSG).lower() in ("y", "yes"): + sys.exit(1) + + sz_config = sz_configmanager.create_config_from_template() + new_default_config = sz_config.export() + new_config_id = sz_configmanager.set_default_config(new_default_config, "Code snippet init_default_config example") + print(f"New default config ID: {new_config_id}") +except SzError as err: + print(f"{err.__class__.__name__} - {err}", file=sys.stderr) diff --git a/python/configuration/register_data_sources.py b/python/configuration/register_data_sources.py new file mode 100755 index 0000000..716610e --- /dev/null +++ b/python/configuration/register_data_sources.py @@ -0,0 +1,29 @@ +#! /usr/bin/env python3 + +import os +import sys +from pathlib import Path + +from senzing import SzError +from senzing_core import SzAbstractFactoryCore + +INSTANCE_NAME = Path(__file__).stem +SETTINGS = os.getenv("SENZING_ENGINE_CONFIGURATION_JSON", "{}") + + +try: + sz_factory = SzAbstractFactoryCore(INSTANCE_NAME, SETTINGS, verbose_logging=False) + sz_configmanager = sz_factory.create_configmanager() + + current_config_id = sz_configmanager.get_default_config_id() + sz_config = sz_configmanager.create_config_from_config_id(current_config_id) + + for data_source in ("CUSTOMERS", "REFERENCE", "WATCHLIST"): + sz_config.register_data_source(data_source) + + new_config = sz_config.export() + new_config_id = sz_configmanager.register_config(new_config, "Code snippet register_data_source example") + sz_configmanager.replace_default_config_id(current_config_id, new_config_id) + print(f"New default config ID: {new_config_id}") +except SzError as err: + print(f"{err.__class__.__name__} - {err}", file=sys.stderr) diff --git a/python/deleting/README.md b/python/deleting/README.md index c2bc3ed..e5fde7a 100644 --- a/python/deleting/README.md +++ b/python/deleting/README.md @@ -7,9 +7,9 @@ Deleting a record only requires the data source code and record ID for the recor ## Snippets - **delete_futures.py** - - Read and delete source records from a file using multiple threads + - Read and delete source records from a file using multiple threads. - **delete_loop.py** - - Basic read and delete source records from a file + - Basic read and delete source records from a file. - **delete_with_info_futures.py** - - Read and delete source records from a file using multiple threads - - Collect the response using the [SZ_WITH_INFO flag](../../README.md#with-info) on the `delete_record()` method and write it to a file + - Read and delete source records from a file using multiple threads. + - Collect the response using the [SZ_WITH_INFO flag](../../README.md#with-info) on the `delete_record()` method and write it to a file. diff --git a/python/information/README.md b/python/information/README.md index 9c63bd6..efc9e63 100644 --- a/python/information/README.md +++ b/python/information/README.md @@ -4,13 +4,13 @@ The information snippets outline the retrieval of different informational aspect ## Snippets -- **check_datastore_performance.py** - - Run an insert test against the Senzing repository to gauge performance -- **get_datastore_info.py** - - Return basic information about the Senzing repository(s) +- **check_repository_performance.py** + - Run an insert test against the Senzing repository to gauge performance. - **get_license.py** - - Return the currently in use license details + - Return the currently in use license details. +- **get_repository_info.py** + - Return basic information about the Senzing repository(s). - **get_stats.py** - - Return statistical information from the Senzing engine during entity resolution processing + - Return statistical information from the Senzing engine during entity resolution processing. - **get_version.py** - - Return the current Senzing product version details + - Return the current Senzing product version details. diff --git a/python/information/check_datastore_performance.py b/python/information/check_repository_performance.py similarity index 87% rename from python/information/check_datastore_performance.py rename to python/information/check_repository_performance.py index 04400b3..ced6047 100755 --- a/python/information/check_datastore_performance.py +++ b/python/information/check_repository_performance.py @@ -13,6 +13,6 @@ try: sz_factory = SzAbstractFactoryCore(INSTANCE_NAME, SETTINGS, verbose_logging=False) sz_diagnostic = sz_factory.create_diagnostic() - print(sz_diagnostic.check_datastore_performance(SECONDS_TO_RUN)) + print(sz_diagnostic.check_repository_performance(SECONDS_TO_RUN)) except SzError as err: print(f"\n{err.__class__.__name__} - {err}") diff --git a/python/information/get_datastore_info.py b/python/information/get_repository_info.py similarity index 90% rename from python/information/get_datastore_info.py rename to python/information/get_repository_info.py index f09e718..7be4138 100755 --- a/python/information/get_datastore_info.py +++ b/python/information/get_repository_info.py @@ -12,6 +12,6 @@ try: sz_factory = SzAbstractFactoryCore(INSTANCE_NAME, SETTINGS, verbose_logging=False) sz_diagnostic = sz_factory.create_diagnostic() - print(sz_diagnostic.get_datastore_info()) + print(sz_diagnostic.get_repository_info()) except SzError as err: print(f"\n{err.__class__.__name__} - {err}") diff --git a/python/initialization/README.md b/python/initialization/README.md index 0dde5ee..68e5fd4 100644 --- a/python/initialization/README.md +++ b/python/initialization/README.md @@ -3,15 +3,28 @@ ## Snippets - **abstract_factory_parameters.py** - - Used to create a dictionary that can be unpacked when creating an SzAbstractFactoryCore, also useful for type annotations + - Used to create a dictionary that can be unpacked when creating an abstract factory, also useful for type annotations. +- **abstract_factory.py** + - Basic example of how to create an abstract factory and each of the available engines. +- **abstract_factory_single_instance_only.py** + - Try and create >1 abstract factories where any argument between them is different. + - Only one abstract factory instance can exist at a time. + - Destroying an abstract factory will destroy it and any engine objects it has created. +- **abstract_factory_with_config_id.py** + - Create an abstract factory using a specific configuration ID. +- **abstract_factory_with_debug.py** + - Create an abstract factory with debug turned on. - **engine_priming.py** - - Priming the Senzing engine before use loads resource intensive assets upfront. Without priming the first SDK call to the engine will appear slower than usual as it causes these assets to be loaded -- **factory_and_engines.py** - - Basic example of how to create an abstract Senzing factory and each of the available engines -- **sz_engine_config_ini_to_json.py** - - The snippets herein utilize the `SENZING_ENGINE_CONFIGURATION_JSON` environment variable for Senzing abstract factory creation - - If you are familiar with working with a Senzing project you may be aware the same configuration data is held in the sz_engine_config.ini file - - Example to convert sz_engine_config.ini to a JSON string for use with `SENZING_ENGINE_CONFIGURATION_JSON` + - Priming the Senzing engine before use loads resource intensive assets upfront. + - Without priming the first SDK call to the engine will appear slower than usual as it causes these assets to be loaded. +- **factory_destroy.py** + - Calls `destroy` on the abstract factory destroying the abstract factory and any Senzing objects it has created. + - The abstract factory must exist for the life of Senzing objects it has created. + - If the abstract factory goes out of scope `destroy` is automatically called - **purge_repository.py** - - **WARNING** This script will remove all data from a Senzing repository, use with caution! **WARNING** - - It will prompt first, still use with caution! + - **WARNING** This script will remove all data from a Senzing repository, use with caution! **WARNING**. + - It will prompt first, still use with caution!. +- **sz_engine_config_ini_to_json.py** + - The snippets herein utilize the `SENZING_ENGINE_CONFIGURATION_JSON` environment variable for Senzing abstract factory creation. + - If you are familiar with working with a Senzing project you may be aware the same configuration data is held in the sz_engine_config.ini file. + - Example to convert sz_engine_config.ini to a JSON string for use with `SENZING_ENGINE_CONFIGURATION_JSON`. diff --git a/python/initialization/factory_and_engines.py b/python/initialization/abstract_factory.py similarity index 100% rename from python/initialization/factory_and_engines.py rename to python/initialization/abstract_factory.py diff --git a/python/initialization/abstract_factory_single_instance_only.py b/python/initialization/abstract_factory_single_instance_only.py new file mode 100755 index 0000000..b4daab7 --- /dev/null +++ b/python/initialization/abstract_factory_single_instance_only.py @@ -0,0 +1,46 @@ +#! /usr/bin/env python3 + +import os + +from senzing import SzError +from senzing_core import SzAbstractFactoryCore + +INSTANCE_NAME_1 = "ABSTRACT_FACTORY_1" +INSTANCE_NAME_2 = "ABSTRACT_FACTORY_2" +SETTINGS = os.getenv("SENZING_ENGINE_CONFIGURATION_JSON", "{}") + +# Try and create 2 abstract factories where any of the arguments differs +try: + print("\nCreating first abstract factory...") + sz_abstract_factory_1 = SzAbstractFactoryCore(INSTANCE_NAME_1, SETTINGS) + sz_engine_1 = sz_abstract_factory_1.create_engine() + print("\tFirst abstract factory and engine created") + print(f"\tUsing sz_engine_1: {sz_engine_1.get_active_config_id()}") + + print("\nCreating second abstract factory...") + sz_abstract_factory_2 = SzAbstractFactoryCore(INSTANCE_NAME_2, SETTINGS) + sz_engine_2 = sz_abstract_factory_2.create_engine() + print("\tSecond abstract factory and engine created") + print(f"\tUsing sz_engine_2: {sz_engine_2.get_active_config_id()}") +except SzError as err: + print(f"\t{err.__class__.__name__} - {err}") +finally: + sz_abstract_factory_1.destroy() + print("\nFirst abstract factory has been destroyed") + +# First abstract factory has been destroyed, try and use the engine object it created +try: + print("\nTrying sz_engine_1 from first abstract factory again...") + print(f"\tUsing sz_engine_1: {sz_engine_1.get_active_config_id()}") +except SzError as err: + print(f"\t{err.__class__.__name__} - {err}") + +# Now abstract factory 1 has been destroyed, try and re-create it and an engine object +try: + print("\nTrying second abstract factory again...") + sz_abstract_factory_2 = SzAbstractFactoryCore(INSTANCE_NAME_2, SETTINGS) + sz_engine_2 = sz_abstract_factory_2.create_engine() + print("\tCreated second abstract factory and engine after first was destroyed") + print(f"\tUsing sz_engine_2: {sz_engine_2.get_active_config_id()}") +except SzError as err: + print(f"\n{err.__class__.__name__} - {err}") diff --git a/python/initialization/initialize_with_config_id.py b/python/initialization/abstract_factory_with_config_id.py similarity index 100% rename from python/initialization/initialize_with_config_id.py rename to python/initialization/abstract_factory_with_config_id.py diff --git a/python/initialization/initialize_with_debug.py b/python/initialization/abstract_factory_with_debug.py similarity index 100% rename from python/initialization/initialize_with_debug.py rename to python/initialization/abstract_factory_with_debug.py diff --git a/python/initialization/factory_destroy.py b/python/initialization/factory_destroy.py new file mode 100755 index 0000000..e5a1cdb --- /dev/null +++ b/python/initialization/factory_destroy.py @@ -0,0 +1,21 @@ +#! /usr/bin/env python3 + +import os +from pathlib import Path + +from senzing import SzError +from senzing_core import SzAbstractFactoryCore + +INSTANCE_NAME = Path(__file__).stem +SETTINGS = os.getenv("SENZING_ENGINE_CONFIGURATION_JSON", "{}") + +try: + sz_abstract_factory = SzAbstractFactoryCore(INSTANCE_NAME, SETTINGS) + sz_engine = sz_abstract_factory.create_engine() + # Do work... +except SzError as err: + print(f"\n{err.__class__.__name__} - {err}") +finally: + # Destroys the abstract factory and all objects it created, such as sz_engine above + # If sz_abstract_factory goes out of scope destroy() is automatically called + sz_abstract_factory.destroy() diff --git a/python/loading/README.md b/python/loading/README.md index e6e1b9d..a4b8047 100644 --- a/python/loading/README.md +++ b/python/loading/README.md @@ -5,15 +5,15 @@ The loading snippets outline adding new source records. Adding source records in ## Snippets - **add_futures.py** - - Read and load source records from a file using multiple threads + - Read and load source records from a file using multiple threads. - **add_queue.py** - - Read and load source records using a queue + - Read and load source records using a queue. - **add_records_loop.py** - - Basic read and add source records from a file + - Basic read and add source records from a file. - **add_records.py** - - Basic iteration over a few records, adding each one + - Basic iteration over a few records, adding each one. - **add_truthset_loop.py** - - Read and load from multiple source files, adding a sample truth set + - Read and load from multiple source files, adding a sample truth set. - **add_with_info_futures.py** - - Read and load source records from a file using multiple threads - - Collect the response using the [SZ_WITH_INFO flag](../../README.md#with-info) on the `add_record()` method and write it to a file + - Read and load source records from a file using multiple threads. + - Collect the response using the [SZ_WITH_INFO flag](../../README.md#with-info) on the `add_record()` method and write it to a file. diff --git a/python/redo/README.md b/python/redo/README.md index 8d8447e..11a0be5 100644 --- a/python/redo/README.md +++ b/python/redo/README.md @@ -11,11 +11,11 @@ When an entity requires additional work a record is automatically created in the ## Snippets - **add_with_redo.py** - - Read and load source records from a file and then process any redo records + - Read and load source records from a file and then process any redo records. - **redo_continuous_futures.py** - - Continuously monitor for redo records to process using multiple threads + - Continuously monitor for redo records to process using multiple threads. - **redo_continuous.py** - - Basic example of continuously monitoring for redo records to process + - Basic example of continuously monitoring for redo records to process. - **redo_with_info_continuous.py** - - Continuously monitor for redo records to process - - Collect the response using the [SZ_WITH_INFO flag](../../README.md#with-info) on the `process_redo_record()` method and write it to a file + - Continuously monitor for redo records to process. + - Collect the response using the [SZ_WITH_INFO flag](../../README.md#with-info) on the `process_redo_record()` method and write it to a file. diff --git a/python/searching/README.md b/python/searching/README.md index cb3e2e2..6c1e448 100644 --- a/python/searching/README.md +++ b/python/searching/README.md @@ -7,8 +7,8 @@ There are [considerations](https://senzing.zendesk.com/hc/en-us/articles/3600078 ## Snippets - **search_futures.py** - - Read and search for records from a file using multiple threads - - To see results first load records with [add_futures.py](../loading/add_futures.py) + - Read and search for records from a file using multiple threads. + - To see results first load records with [add_futures.py](../loading/add_futures.py). - **search_records.py** - - Basic iteration over a few records, searching for each one - - To see results first load records with [add_truthset_loop.py](../loading/add_truthset_loop.py) + - Basic iteration over a few records, searching for each one. + - To see results first load records with [add_truthset_loop.py](../loading/add_truthset_loop.py). diff --git a/python/stewardship/README.md b/python/stewardship/README.md index a7fd681..9460bf0 100644 --- a/python/stewardship/README.md +++ b/python/stewardship/README.md @@ -10,9 +10,9 @@ In these examples, the current JSON data for a record is first retrieved and add ## Snippets - **force_resolve.py** - - Force resolve records together to a single entity + - Force resolve records together to a single entity. - **force_unresolve.py** - - Force un-resolve a record from an entity into a new entity + - Force un-resolve a record from an entity into a new entity. ## Example Usage