Examples#
Runnable demonstrations, and a starter configuration to copy. None needs a server or credentials; each runs against throwaway SQLite databases. The test suite runs every one, so none can drift from what the code accepts.
Each demo has the same shape:
| File or folder | What it is |
|---|---|
demo.py |
the script: python example/<demo>/demo.py from the repository root |
configuration/ |
what it reads: connections.yaml, and jobs.yaml where the demo doesn't generate its own |
transaction/ |
what it writes: databases, run state, logs, manifests. Emptied at the start of each run, and ignored by git |
The walkthrough runs the bauta command itself. The other demos call the Python API, and before each step print the bauta command that does the same, with the environment variables its configuration/ reads — paste it into a shell from the repository root to run that step yourself.
| Demo | Shows |
|---|---|
walkthrough/ |
the whole workflow, through the commands a person would type |
incremental/ |
streaming, and incremental loads that extract only what changed |
masking/ |
masking, discovery and subsetting, from Python |
orchestrators/ |
bauta under Airflow and Dagster: a DAG, a DAG with a task per job, and Dagster assets, with a demo that runs a task per job without either |
native-masking/ |
Python against Rust on a narrow table, and Rust on one core against all of them on a wide one: the speed, and identical results |
starter/ |
not a demo: a configuration to copy for your own databases |
walkthrough#
python example/walkthrough/demo.py
Builds a small shop's "production" database -- customers with national ids and phone numbers, orders, support tickets full of personal details, and payment cards -- and makes a safe staging copy of its Portuguese and Spanish customers:
discoverproposes a masking policy.subset --maskgenerates a job per table for those customers and everything they reference. The script then applies what a reviewer would decide, and records each decision at the top of the jobs file: masked ids sharing domains,fpefor national ids,redactfor ticket text, and no copy at all of payment cards.schemacreates staging's tables.audit --connect --strictchecks the reviewed policy against production.runcopies and masks, writing a signed manifest and run history.verify-manifestchecks the manifest.synthesizefills staging's payment cards with generated rows.historyshows what ran.
Its configuration/ holds only connections.yaml, since subset generates the jobs into transaction/. It ends by showing customers and a support ticket before and after, including what redact leaves behind, and writes the session to transaction/walkthrough.md.
Tested by tests/examples/test_walkthrough.py, which also checks that no production email, phone number or card number reaches staging.
incremental#
python example/incremental/demo.py
Loads its job the way the CLI does -- YAML, then ${NAME} expansion, then validation -- and runs it three times against one SQLite database.
Watch the second run: between runs, a loaded row is edited without its updatedAt changing, and a new row added. An incremental run sees only the new row, and the unchanged edit is the tell.
Tested by tests/examples/test_incremental_demo.py.
masking#
python example/masking/demo.py
Builds a "production" and a "staging" SQLite database, then:
- Masks customers and orders into staging. The two tables still join, because
customers.idandorders.customer_idshare thecustomerdomain. - Adds an
ssncolumn to production, which the policy doesn't cover. The next run fails before writing anything, and staging is left as it was. New columns never leak by default. - Proposes a policy for the changed table, as
bauta discoverdoes. - Plans a subset of European customers and their orders, as
bauta subsetdoes.
It uses a throwaway key unless MASKING_KEY is already set.
Tested by tests/examples/test_masking_demo.py.
orchestrators#
python example/orchestrators/demo.py
Working Airflow and Dagster files, described in run from Airflow or Dagster, and a demo that runs a bauta run --job process per job, each once its predecessors finish, as both orchestrators do. It deletes an order in production, which an incremental run leaves in the copy, and the weekly checks and full refresh take out.
Tested by tests/examples/test_orchestrators.py, which also loads each orchestrator's file against stand-ins, since Airflow and Dagster are too heavy to install for the suite.
native-masking#
python example/native-masking/demo.py # 100,000 narrow rows and 1,000,000 wide ones: about 2½ minutes
python example/native-masking/demo.py 100000 200000 # the same comparison, quicker
Masks two tables in Python and in Rust (the native masker, bauta-rs), each run into a staging copy of its own, and checks every copy of a table is identical.
A narrow table, six masked columns, where writing to the database sets the pace. Reading, masking and writing take turns or overlap (BAUTA_PIPELINE), in Python or in Rust (BAUTA_NATIVE):
Narrow table: 100,000 rows, 6 masked columns
seconds rows a second vs first
Python, in turn 7.4 13,587 1.0x
Python, overlapped 7.4 13,511 1.0x
Rust, in turn 1.5 65,919 4.9x
Rust, overlapped 1.0 96,077 7.1x
A wide table, 25 masked columns, where masking sets the pace. Rust masks on one core or on the half of them auto takes (BAUTA_MASKING_THREADS):
Wide table: 1,000,000 rows, 25 masked columns
seconds rows a second vs first
Rust, in turn 39.2 25,519 1.0x
Rust, overlapped 32.6 30,691 1.2x
Rust, in turn, auto threads 15.5 64,612 2.5x
Rust, overlapped, auto threads 9.4 106,080 4.2x
On a ten-core M1 Pro, where auto masks on five. Overlapping gains little for Python, whose masking leaves no wait to hide, and more for Rust; against a remote database it gains more still. The narrow table runs on one core only, since its time goes to writing.
Without the extension, the demo runs the Python runs and says how to install it (pip install ./mask-rs/py, with Rust 1.83 or newer).
Tested by tests/examples/test_native_masking_demo.py.
starter#
A complete configuration to start your own from:
mkdir configuration
cp example/starter/configuration/*.yaml configuration/
| File | What it holds |
|---|---|
connections.yaml |
two database aliases, with credentials read from the environment |
jobs.yaml |
a defaults: block, data jobs including an incremental one and two masked ones, and run state, history and the manifest kept in transaction/ |
Set the variables it reads -- SOURCE_DB_PASSWORD, TARGET_DB_PASSWORD and MASKING_KEY -- then edit it for your databases. The CLI reads ./configuration by default; --config DIR points it anywhere else.
Validated, with every demo's configuration, by tests/examples/test_shipped_example_configuration.py. See docs/reference/configuration.md for every field.