Load a domain snapshot into SQLite with Python
Stream a compressed domain list into a local SQLite table using bounded batches and duplicate-safe inserts. Start a reproducible domain-data import.
All datasets are updated daily by 9:00 AM UTC.
A practical Data Engineering workflow
- Download a zone snapshot and record its actual date.
- Stream names into SQLite in batches with a composite primary key.
- Query snapshots locally or adapt the schema for your warehouse.
What the script produces
A local SQLite database keyed by domain and observation date; repeating an import does not duplicate rows.
Python example: Data Engineering
Requires Python 3.9 or later. Uses the standard library only, processes local files, and makes no network requests. Save the script beside your downloaded inputs, or provide full paths.
Run the example
python3 data-engineering.py com.txt.gz --database domains.sqlite --snapshot-date 2026-09-01
Results are printed to the terminal. Redirect standard output to a file if you want to save the report. For the SQLite example, the database is saved at the path you specify.
Complete script
import argparse
import csv
import gzip
import sys
def domains(path):
with gzip.open(path, "rt", encoding="utf-8") as source:
for line in source:
domain = line.strip().lower().rstrip(".")
if domain:
yield domain
import datetime
import sqlite3
parser = argparse.ArgumentParser(description="Import a dated domain snapshot into SQLite")
parser.add_argument("file")
parser.add_argument("--database", required=True)
parser.add_argument("--snapshot-date", required=True)
args = parser.parse_args()
try:
date = datetime.date.fromisoformat(args.snapshot_date).isoformat()
except ValueError:
parser.error("snapshot-date must be YYYY-MM-DD")
connection = sqlite3.connect(args.database)
try:
with connection:
connection.execute("CREATE TABLE IF NOT EXISTS snapshots "
"(domain TEXT, observed_date TEXT, "
"PRIMARY KEY (domain, observed_date))")
batch = []
for domain in domains(args.file):
batch.append((domain, date))
if len(batch) == 1000:
connection.executemany("INSERT OR IGNORE INTO snapshots VALUES (?, ?)", batch)
batch.clear()
connection.executemany("INSERT OR IGNORE INTO snapshots VALUES (?, ?)", batch)
print("Rows for date:", connection.execute(
"SELECT COUNT(*) FROM snapshots WHERE observed_date = ?", (date,)).fetchone()[0])
finally:
connection.close()
To automate input downloads, follow the API documentation for tokens, supported endpoints, and historical dates. Keep API tokens out of shared scripts.
How to interpret the results
This example appends snapshots rather than maintaining current registration state. Disk use grows with each date. Use dates from the downloaded files and plan storage for large imports.
Record the input filename and observation date with your results. Differences in zone coverage and source availability can affect comparisons. Review dataset formats and coverage before expanding the workflow.
Data Engineering example questions
What data do I need to run this example?
Use Current domain lists. Download gzip-compressed domain-name files and pass their local paths to the script. The research comparison requires two snapshots of the same zone.
How should I use the output?
A local SQLite database keyed by domain and observation date; repeating an import does not duplicate rows. This example appends snapshots rather than maintaining current registration state. Disk use grows with each date. Use dates from the downloaded files and plan storage for large imports.
Can I schedule this workflow?
Yes. Download the required dated files through the API, then run the script locally. Check file dates before processing and retain the inputs needed to reproduce your results.
Explore more use cases
Put domain data to work
Inspect the datasets, choose access, or discuss requirements for your team.