Cape Python API#
This guide provides an example of using Cape Python with either Pandas or Spark.
- Python 3.6 or above.
- Cape Privacy recommends using a virtual environment such as venv.
You can install Cape Python with pip:
pip install cape-privacy
Write the policy#
The data policy file defines the target data and permissions. It is written in YAML. Cape Python reads the
.yaml policy file and applies the policies based on your policy application script.
test-policy.yaml file in your project, with the following content:
label: test-policy version: 1 rules: # Set the column name - match: name: weight actions: - transform: # This example shows an unnamed transformation. # It tells the policy runner to: # (1) Apply the transformation numeric-rounding # (2) Round to one decimal place type: numeric-rounding dtype: Double precision: 1
Write the policy application script#
To apply the policy
.yaml to your data, you must run a script that defines which policy you apply to which data target.
test-transformation.py file in your project, with the following content:
Run your transformations#
The quickstart example creates a dataset programatically, so you can run the policy application script and view the output:
You can choose where in your workflow to run your transformation scripts. Refer to Best practices - Running transformations for guidance.