Skip to main content

Data Lab

import decentriq_platform.legacy as dq
from decentriq_platform.legacy.types import MatchingId

USER_EMAIL = "@@ YOUR EMAIL HERE @@"
OTHER_EMAIL = "@@ OTHER EMAIL HERE @@"
API_TOKEN = "@@ YOUR TOKEN HERE @@"

client = dq.create_client(USER_EMAIL, API_TOKEN)
enclave_specs = dq.enclave_specifications.versions([...])

# Build a Lookalike DCR to which we provision the DataLab
builder = dq.LookalikeMediaDcrBuilder(client)
builder.with_name("sdk-lmdcr")
builder.with_matching_id_format(MatchingId.STRING)
builder.with_publisher_emails(USER_EMAIL)
builder.with_advertiser_emails(OTHER_EMAIL)
lmdcr = builder.build_and_publish()

LMDCR_HASH = lmdcr.id
print("*** Building Data Lab")
builder = dq.DataLabBuilder(client)
builder.with_name("tutorial-data-lab")
builder.with_matching_id_format(dq.types.MatchingIdFormat.STRING)
builder.with_embeddings(50)
builder.with_demographics()
builder.with_segments()

data_lab = builder.build()

print(f"DataLab ID: {data_lab.data_lab_id}")

print("*** Provisioning datasets to Data Lab")

file_encryption_key = dq.Key()

data_lab.provision_local_datasets(
file_encryption_key,
"/path/to/matching_data.csv",
"/path/to/segments_data.csv",
demographics_data_path="/path/to/demographics_data.csv",
embeddings_data_path="/path/to/embeddings_data.csv",
)

print("*** Running Data Lab")
data_lab.run()
validation_report = data_lab.get_validation_report()
statistics_report = data_lab.get_statistics_report()

print("*** Data Lab validation report")
print(validation_report)
print("*** Data Lab statistics report")
print(statistics_report)

print("*** Building from existing Data Lab")
builder = dq.DataLabBuilder(client)
builder.from_existing(data_lab.data_lab_id)
data_lab_2 = builder.build()

print("*** Run the second Data Lab")
data_lab_2.run()

print("*** Provisioning Data Lab to LMDCR")
data_lab_2.provision_to_lookalike_media_data_room(LMDCR_HASH)