senzing Python package documentation

The senzing Python package contains the interface definitions for the senzing-core and senzing-grpc implementation packages.

By using interface definitions, implementation-agnostic code can be written. For example, the following code does not need to know the underlying implementation of the Senzing Abstract Factory:

1from senzing import SzAbstractFactory, SzEngineFlags
2
3
4def perform_senzing_search(sz_abstract_factory: SzAbstractFactory, attributes: str) -> str:
5    """Example Senzing search."""
6    sz_engine = sz_abstract_factory.create_engine()
7    flags = SzEngineFlags.SZ_SEARCH_BY_ATTRIBUTES_DEFAULT_FLAGS
8    search_profile = ""
9    return sz_engine.search_by_attributes(attributes, flags, search_profile)

Similarly, interface definitions for Senzing objects can be used. Example:

1from senzing import SzEngine, SzEngineFlags
2
3
4def perform_senzing_search(sz_engine: SzEngine, attributes: str) -> str:
5    """Example Senzing search."""
6    flags = SzEngineFlags.SZ_SEARCH_BY_ATTRIBUTES_DEFAULT_FLAGS
7    search_profile = ""
8    return sz_engine.search_by_attributes(attributes, flags, search_profile)

The senzing Python package also includes constants and errors used across different Senzing Python implementation packages.

As an abstract base class (abc), the senzing Python package is not used to create instances of Senzing objects. Concrete Python packages, such as senzing-core and senzing-grpc, are used in the creation of objects. Example:

 1import json
 2
 3import grpc
 4from senzing_core import SzAbstractFactoryCore
 5from senzing_grpc import SzAbstractFactoryGrpc
 6
 7from senzing import SzAbstractFactory, SzEngineFlags, SzError
 8
 9
10def perform_senzing_search(search_abstract_factory: SzAbstractFactory, search_attributes: str) -> str:
11    """Example Senzing search using Abstract Base Class SzAbstractFactory."""
12    sz_engine = search_abstract_factory.create_engine()
13    flags = SzEngineFlags.SZ_SEARCH_BY_ATTRIBUTES_DEFAULT_FLAGS
14    search_profile = ""
15    return sz_engine.search_by_attributes(search_attributes, flags, search_profile)
16
17
18# Example using SzAbstractFactoryCore implementation class.
19
20try:
21    instance_name = "Example"
22    settings = {
23        "PIPELINE": {
24            "CONFIGPATH": "/etc/opt/senzing",
25            "RESOURCEPATH": "/opt/senzing/er/resources",
26            "SUPPORTPATH": "/opt/senzing/data",
27        },
28        "SQL": {"CONNECTION": "sqlite3://na:na@/tmp/sqlite/G2C.db"},
29    }
30    sz_abstract_factory = SzAbstractFactoryCore(instance_name, settings)
31    attributes = json.dumps({"NAME_FULL": "Bob Smith", "EMAIL_ADDRESS": "bsmith@work.com"})
32    search_results = perform_senzing_search(sz_abstract_factory, attributes)
33    print(search_results)
34except SzError as err:
35    print(f"\nERROR: {err}\n")
36
37# Example using SzAbstractFactoryGrpc implementation class.
38
39try:
40    grpc_channel = grpc.insecure_channel("localhost:8261")
41    sz_abstract_factory = SzAbstractFactoryGrpc(grpc_channel)
42    attributes = json.dumps({"NAME_FULL": "Bob Smith", "EMAIL_ADDRESS": "bsmith@work.com"})
43    search_results = perform_senzing_search(sz_abstract_factory, attributes)
44    print(search_results)
45except SzError as err:
46    print(f"\nERROR: {err}\n")

Senzing has additional Software Development Kits (SDKs) for Java, Go, and C#. Information for these SDKs can be found at docs.senzing.com.

References

  1. Index

  2. Module Index

  3. Search Page

  4. GitHub

  5. Pypi

  6. senzing-core

  7. senzing-grpc