Notebook Global Address Verification: Databricks Python Package

Notebook Global Address Verification: Databricks Python Package#

Introduction#

The Melissa Databricks Python Package provides efficient access to the Global Address Verification API directly within Databricks Notebooks. It enables seamless integration with Databricks tables, allowing you to process your data and write API results directly to Databricks tables.

Click here to learn more about the Global Address Verification Cloud API.

Prerequisites#

Before using the package, ensure the following requirements are met:

  • Access to a Databricks workspace.

  • An input table containing the data to be processed.

  • Appropriate permissions to read the input table and create or write to the output table.

  • The Melissa Databricks Python Package installed in the Databricks environment. See installation.

Usage#

Imports#

from melissadatacloudapi_databricks import Config, GLOBAL_ADDRESS_VERIFICATION, run

Components#

Name

Description

Config

Holds the settings for a run: license key, input and output tables, field mapping, request parameters, output columns, logging, and duplicate checking.

The settings are validated when run starts. A missing or unknown setting stops the run with an error before any records are sent.

See Configuration.

GLOBAL_ADDRESS_VERIFICATION

The product definition for Global Address Verification. It tells run which Cloud API to call, which input fields are accepted, which output columns are available, and how many records to send per request.

Required input fields: record_id and address_line_1.
Request parameter: options.
Records per request: 100.

run

Processes every record in the input table and writes the results to the output table.

run(product, config, df=None, spark=None, dbutils=None)

- product: GLOBAL_ADDRESS_VERIFICATION.
- config: The Config object.
- df: Optional.
- spark: The Spark session. In a notebook, pass spark.
- dbutils: Optional. In a notebook, pass dbutils.

See Execution.

Configuration#

config = Config(
   license_key=LICENSE_KEY,
   input_table="<catalog>.<schema>.<input_table>",
   output_table="<catalog>.<schema>.<output_table>",
   parameter_mapping={
      "record_id": "",
      "address_line_1": "",
      "locality": "",
      "administrative_area": "",
      "postal_code": "",
      "country": "",
      "last_name": "",
      "organization": "",
      "address_line_2": "",
      "address_line_3": "",
      "address_line_4": "",
      "address_line_5": "",
      "address_line_6": "",
      "address_line_7": "",
      "address_line_8": "",
      "double_dependent_locality": "",
      "dependent_locality": "",
      "sub_administrative_area": "",
      "sub_national_area": "",
   },
   request_parameters={
      "options": "",
   },
   output_columns="<field_1,field_2>",
   log_to_table=False,
   log_table="<catalog>.<schema>.<log_table>",
   duplicate_check=False,
)

Input Parameters#

Parameter

Data Type

Description

Example

license_key

STRING

Required.
The License Key with Credits issued by Melissa.

Get it here.

See more information on license key set up.

parameter_mapping

Connects each Melissa field to a column in your input table. See Input Fields.

request_parameters

Sent once with every batch, applied to every record.

options
[OptionName:Parameter], separated by commas (,).

See more information about endpoint options.

USPreferredCityNames:on,
USStandardizationType:short

input_table

STRING

Required.
Name of the input table.

catalog.schema.input_table_name

output_table

STRING

Required.
The output table name.

A new table will be created if it doesn’t exist.
If the table exists, its structure must remain unchanged.

catalog.schema.output_table_name

output_columns

STRING

Case-sensitive.

Fields in the output table; fields separated by commas (,) if not ‘ALL’.
Field names must match the available output column names in the example list. Use ALL to include every available field.
If omitted, see Default Output Fields.

RecordID,
InLastName,
InOrganization,
InAddressLine1,
InAddressLine2,
InAddressLine3,
InAddressLine4,
InAddressLine5,
InAddressLine6,
InAddressLine7,
InAddressLine8,
InDoubleDependentLocality,
InDependentLocality,
InLocality,
InSubAdministrativeArea,
InAdministrativeArea,
InPostalCode,
InSubNationalArea,
InCountry,
Results,
FormattedAddress,
Organization,
AddressLine1,
AddressLine2,
AddressLine3,
AddressLine4,
AddressLine5,
AddressLine6,
AddressLine7,
AddressLine8,
SubPremises,
DoubleDependentLocality,
DependentLocality,
Locality,
SubAdministrativeArea,
AdministrativeArea,
PostalCode,
PostalCodeType,
AddressType,
AddressKey,
SubNationalArea,
CountryName,
CountryISO3166_1_Alpha2,
CountryISO3166_1_Alpha3,
CountryISO3166_1_Numeric,
CountrySubdivisionCode,
Thoroughfare,
ThoroughfarePreDirection,
ThoroughfareLeadingType,
ThoroughfareName,
ThoroughfareTrailingType,
ThoroughfarePostDirection,
DependentThoroughfare,
DependentThoroughfarePreDirection,
DependentThoroughfareLeadingType,
DependentThoroughfareName,
DependentThoroughfareTrailingType,
DependentThoroughfarePostDirection,
Building,
PremisesType,
PremisesNumber,
SubPremisesType,
SubPremisesNumber,
PostBox,
Latitude,
Longitude,
DeliveryIndicator,
MelissaAddressKey,
MelissaAddressKeyBase,
PostOfficeLocation,
SubPremiseLevel,
SubPremiseLevelType,
SubPremiseLevelNumber,
SubBuilding,
SubBuildingType,
SubBuildingNumber,
UTC,
DST,
DeliveryPointSuffix,
CensusKey,
Extras,
JSON_Response,
Timestamp

log_to_table

BOOLEAN

Enable or disable logs to facilitate troubleshooting in case of any issues.
- False (Default): No action will be taken. The notebook will process with no log writes.
- True: Enable event, batch progress, and error logging.

True

log_table

STRING

Name of the log table. Only valid when log_to_table = True.

catalog.schema.log_table_name

duplicate_check

BOOLEAN

Enable or disable several checks for duplicate RecordID.
- False (Default): No action will be taken. The notebook will process records coming from the input source as is.
- True: Enable several checks for duplicate RecordID. When enabled, a repeated RecordID stops the run before anything is sent, and records already in the output table are skipped. This makes it safe to rerun after a failure without submitting the same records to the service again.

True

Example#

config = Config(
   license_key=LICENSE_KEY,
   input_table="main.default.addresses",
   output_table="main.default.addresses_verified",
   parameter_mapping={
      "record_id": "RecordID",
      "address_line_1": "AddressLine1",
      "locality": "City",
      "administrative_area": "State",
      "postal_code": "Zip",
      "country": "Country",
   },
   request_parameters={
      "options": "USPreferredCityNames:on",
   },
   output_columns="RecordID,Results,FormattedAddress,Latitude,Longitude",
   log_to_table=True,
   log_table="main.default.addresses_logs",
   duplicate_check=False,
)

Execution#

run(GLOBAL_ADDRESS_VERIFICATION, config, spark=spark, dbutils=dbutils)