Notebook Personator Consumer: Databricks Python Package

Notebook Personator Consumer: Databricks Python Package#

Introduction#

The Melissa Databricks Python Package provides access to the Personator Consumer API from Databricks notebooks. It reads consumer contact records from a Databricks table and writes check and enrichment results to an output table.

Click here to learn more about the Personator Consumer Cloud API.

Prerequisites#

  • Access to a Databricks workspace.

  • An input table containing consumer contact data. Provide at least one supported input combination described in Personator Consumer minimum input combinations.

  • Permission 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.

  • A Melissa License Key with Credits. See License Key Information.

Usage#

Imports#

from melissadatacloudapi_databricks import Config, PERSONATOR_CONSUMER, 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.

PERSONATOR_CONSUMER

The product definition for Personator Consumer. It tells run which Cloud API to call, which input fields are accepted, and which output columns are available.

Required input field: record_id, plus at least one of these input combinations:
- address_line_1 + postal_code
- address_line_1 + city + state
- address_line_1 + last_line
- email_address
- phone_number
- full_name
- ip_address
- free_form
- melissa_address_key
- melissa_identity_key
Request parameters: actions, columns and 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: PERSONATOR_CONSUMER.
- 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#

Map the package parameters to input table columns. At least one supported input combination is required. Use an empty string for optional values that are not in the input table.

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": "",
       "city": "City",
       "state": "State",
       "postal_code": "",
       "last_line": "",
       "email_address": "",
       "phone_number": "",
       "full_name": "",
       "ip_address": "",
       "free_form": "",
       "melissa_address_key": "",
       "melissa_identity_key": "",
       "first_name": "",
       "last_name": "",
       "company_name": "",
       "address_line_2": "",
       "country": "",
       "birth_day": "",
       "birth_month": "",
       "birth_year": "",
       "age_approximate": "",
       "age_greater_than": "",
       "age_less_than": "",
   },
   request_parameters={
       "actions": "Check",
       "columns": "",
       "options": "",
   },
   output_columns="",
   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.

actions
[ActionName], separated by commas (,). Blank input defaults to Check. See endpoint actions.

columns
[ColumnName,GrpColumnsName], separated by commas (,). See endpoint columns.

options
[OptionName:Parameter], separated by semicolons (;). See endpoint options.
If omitted, Default Input Options will be applied.

Check,Move
Plus4,GrpGeocode
UsePreferredCity:on;Diacritics:off

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 response fields. Use ALL to include every available field. This significantly increases the writing time to the output table, so we recommend using the default or specifying the output fields.
If omitted, see Default Output Fields.

RecordID,
InAddressLine1,
InAddressLine2,
InCity,
InCompany,
InCountry,
InEmail,
InFirstName,
InFullName,
InIPAddress,
InLastName,
InMelissaAddressKey,
InMelissaIdentityKey,
InPhone,
InPostalCode,
InState,
Results,
AddressExtras,
AddressKey,
AddressLine1,
AddressLine2,
City,
CompanyName,
EmailAddress,
MelissaAddressKey,
MelissaAddressKeyBase,
NameFull,
PhoneNumber,
PostalCode,
State,
DateLastConfirmed,
EstimatedHomeValue,
MedianHouseholdIncome,
MelissaIdentityKey,
MoveDate,
Occupation,
OwnRent,
PhoneCountryCode,
PhoneCountryName,
Plus4,
PrivateMailBox,
Suite,
AddressTypeCode,
CarrierRoute,
CityAbbreviation,
CountryCode,
CountryName,
DeliveryIndicator,
DeliveryPointCheckDigit,
DeliveryPointCode,
StateName,
UrbanizationName,
UTC,
CBSACode,
CBSADivisionCode,
CBSADivisionLevel,
CBSADivisionTitle,
CBSALevel,
CBSATitle,
CensusBlock,
CensusTract,
CongressionalDistrict,
CountyFIPS,
CountyName,
PlaceCode,
PlaceName,
CensusKey,
CountySubdivisionCode,
CountySubdivisionName,
ElementarySchoolDistrictCode,
ElementarySchoolDistrictName,
SecondarySchoolDistrictCode,
SecondarySchoolDistrictName,
StateDistrictLower,
StateDistrictUpper,
UnifiedSchoolDistrictCode,
UnifiedSchoolDistrictName,
Latitude,
Longitude,
ChildrenAgeRange,
CreditCardUser,
DateOfBirth,
DateOfDeath,
DemographicsGender,
DemographicsResults,
Education,
HouseholdIncome,
HouseholdSize,
LengthOfResidence,
MaritalStatus,
PoliticalParty,
PresenceOfChildren,
PresenceOfSenior,
DistanceAddressToIP,
IPAddress,
IPCity,
IPConnectionSpeed,
IPConnectionType,
IPContinent,
IPCountryAbbreviation,
IPCountryName,
IPDomainName,
IPISPName,
IPLatitude,
IPLongitude,
IPPostalCode,
IPProxyDescription,
IPProxyType,
IPRegion,
IPUTC,
Gender,
Gender2,
NameFirst,
NameFirst2,
NameLast,
NameLast2,
NameMiddle,
NameMiddle2,
NamePrefix,
NamePrefix2,
NameSuffix,
NameSuffix2,
Salutation,
AddressDeliveryInstallation,
AddressHouseNumber,
AddressLockBox,
AddressPostDirection,
AddressPreDirection,
AddressPrivateMailboxName,
AddressPrivateMailboxRange,
AddressRouteService,
AddressStreetName,
AddressStreetSuffix,
AddressSuiteName,
AddressSuiteNumber,
DomainName,
MailboxName,
TopLevelDomain,
AreaCode,
NewAreaCode,
PhoneExtension,
PhonePrefix,
PhoneSuffix,
RecordExtras,
Reserved,
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.contacts",
   output_table="main.default.contacts_verified",
   parameter_mapping={
      "record_id": "RecordID",
      "full_name": "FullName",
      "address_line_1": "AddressLine1",
      "city": "City",
      "state": "State",
      "postal_code": "PostalCode",
      "email_address": "Email",
   },
   request_parameters={
      "actions": "Check",
      "columns": "",
      "options": "UsePreferredCity:on",
   },
   output_columns="RecordID,Results,NameFull,AddressLine1,City,State,PostalCode,EmailAddress",
   log_to_table=True,
   log_table="main.default.contacts_logs",
   duplicate_check=False,
)

Execution#

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