Connecting data sources¶
opp-engine generate reads one or more sources, samples their values in memory, and writes a privacy
model. Pass any mix of database URLs, files, folders and web pages:
opp-engine generate <source> [<source> ...] --name acme --org "Acme" -o acme.opp.yaml --report review.md
Before you start
- Use a read-only account. The engine only runs
SELECT/ find queries with a row limit. - Credentials and connection options are never written into the model: only the scheme, host, port
and database name are kept (
postgresql://db.internal:5432/crm). - Values are sampled (200 rows or documents per table by default,
--sample Nto change) and used only for classification. No value is ever written into the model, the report or the logs. - Keep passwords out of your shell history: put the URL in an environment variable.
export CRM_URL='postgresql://readonly:••••@db.internal:5432/crm'
opp-engine generate "$CRM_URL" --name acme --org "Acme" -o acme.opp.yaml
SQL databases¶
Any database with a SQLAlchemy dialect works. Install its driver next to the engine, then pass the URL. Every schema the account can read is scanned (system schemas are skipped).
| Database | Install | URL format |
|---|---|---|
| PostgreSQL | pip install "open-privacy-protocol-engine[postgres]" |
postgresql+psycopg://user:pass@host:5432/dbname |
| MySQL / MariaDB | pip install "open-privacy-protocol-engine[mysql]" |
mysql+pymysql://user:pass@host:3306/dbname |
| SQLite | nothing extra | sqlite:///path/to/file.db |
| Microsoft SQL Server / Azure SQL | pip install pyodbc (and the ODBC driver) |
mssql+pyodbc://user:pass@host/dbname?driver=ODBC+Driver+18+for+SQL+Server |
| Oracle | pip install oracledb |
oracle+oracledb://user:pass@host:1521/?service_name=ORCL |
| Snowflake | pip install snowflake-sqlalchemy |
snowflake://user:pass@account/database/schema?warehouse=WH |
| Google BigQuery | pip install sqlalchemy-bigquery |
bigquery://project-id/dataset |
| Amazon Redshift | pip install sqlalchemy-redshift redshift_connector |
redshift+redshift_connector://user:pass@cluster:5439/dbname |
| Databricks | pip install databricks-sqlalchemy |
databricks://token:TOKEN@host?http_path=/sql/1.0/warehouses/ID&catalog=main&schema=default |
| ClickHouse | pip install clickhouse-sqlalchemy |
clickhouse+native://user:pass@host:9000/dbname |
| DuckDB | pip install duckdb-engine |
duckdb:///path/to/file.duckdb |
| Trino / Presto | pip install trino |
trino://user@host:8080/catalog/schema |
| IBM Db2 | pip install ibm_db_sa |
db2+ibm_db://user:pass@host:50000/dbname |
Tables become datasets of type table; each column becomes a field, named as in the database.
opp-engine generate postgresql+psycopg://[email protected]/crm \
--name acme --org "Acme" --industry 541511 -o acme.opp.yaml --report review.md
NoSQL databases¶
MongoDB and MongoDB Atlas¶
pip install "open-privacy-protocol-engine[mongodb]"
opp-engine generate mongodb://localhost:27017/crm --name acme --org "Acme" -o acme.opp.yaml
opp-engine generate "mongodb+srv://readonly:••••@cluster0.example.mongodb.net/crm" --name acme --org "Acme" -o acme.opp.yaml
- With a database name in the URL, that database is scanned; without one, every database the user can read
(except
admin,localandconfig). - Each collection becomes a dataset of type
collection, sampled with$sample. - Nested data becomes field paths:
address.city,orders[].card.last4,tags[]. Binary values are skipped; dates and ObjectIds are read as text. - Up to 500 collections per run. For larger servers, run once per database by naming it in the URL.
- The account needs the
readrole on the databases you scan.
Other document and key-value stores¶
Elasticsearch, DynamoDB, Firestore, Cassandra, Redis and Couchbase do not have a built-in connector yet. Two ways to cover them today:
-
Export a sample to JSON Lines or Parquet and scan the file. Nested JSON gets the same field paths as MongoDB:
# Elasticsearch: the first 200 documents of an index curl -s "http://localhost:9200/customers/_search?size=200" | jq -c '.hits.hits[]._source' > customers.jsonl # DynamoDB aws dynamodb scan --table-name customers --max-items 200 --output json | jq -c '.Items[]' > customers.jsonl opp-engine generate customers.jsonl --name acme --org "Acme" -o acme.opp.yaml -
Write a connector. A connector returns datasets with field names and sampled values; see
src/opp_engine/nosql.pyfor the MongoDB one, and contribute yours.
Files and folders¶
| Kind | Extensions | Install |
|---|---|---|
| Tables | .csv, .tsv, .json, .jsonl, .ndjson |
nothing extra |
| Columnar | .parquet |
pip install "open-privacy-protocol-engine[parquet]" |
| Documents | .txt, .md, .html, .rst, .log |
nothing extra |
| Office and PDF | .pdf, .docx |
pip install "open-privacy-protocol-engine[documents]" |
A folder is scanned recursively. Tables become datasets with fields; documents become datasets with
topics (the confidential subjects found in their text).
Files in cloud storage (S3, GCS, Azure Blob): sync them to a local folder first, for example
aws s3 sync s3://bucket/exports ./exports, then scan the folder.
Web pages¶
The page is fetched once and read as a document.
Combining sources and keeping the model current¶
- Pass several sources in one run; each becomes its own
sourcein the model. - Re-run with
--merge acme.opp.yamlto keep entries people already certified and add only new findings. - Add
--industry <NAICS code>so the review report lists classes your industry usually holds that were not found. - Add
--opp-model ./opp-model-v1to find names, addresses and topics in free-text columns too.
Troubleshooting¶
| Problem | Fix |
|---|---|
No module named 'psycopg' (or another driver) |
Install the driver from the tables above |
ServerSelectionTimeoutError (MongoDB) |
Check the host and port, and that your IP is allowed (Atlas network access) |
| Only some tables appear | The account lacks read rights on the others, or the 500-table limit was reached |
| A column has no classes | Nothing private was found in the sample; raise --sample, or add an identifier pattern or term to the model |