Skip to main content

Cape Python

License codecov PyPI version Chat on Slack

A Python library supporting data transformations and collaborative privacy policies, for data science projects in Pandas and Apache Spark

See below for instructions on how to get started or visit the documentation.

Getting started

Prerequisites

  • Python 3.6 or above, and pip
  • Pandas 1.0+
  • PySpark 3.0+ (if using Spark)
  • Make (if installing from source)

Install with pip

Cape Python is available through PyPi.

pip install cape-privacy

Support for Apache Spark is optional. If you plan on using the library together with Apache Spark, we suggest the following instead:

pip install cape-privacy[spark]

We recommend running it in a virtual environment, such as venv.

Install from source

It is possible to install the library from source. This installs all dependencies, including Apache Spark:

git clone https://github.com/capeprivacy/cape-python.git
cd cape-python
make bootstrap

Usage example

This example is an abridged version of the tutorial found here

df = pd.DataFrame({
    "name": ["alice", "bob"],
    "age": [34, 55],
    "birthdate": [pd.Timestamp(1985, 2, 23), pd.Timestamp(1963, 5, 10)],
})

tokenize = Tokenizer(max_token_len=10, key=b"my secret")
perturb_numeric = NumericPerturbation(dtype=dtypes.Integer, min=-10, max=10)

df["name"] = tokenize(df["name"])
df["age"] = perturb_numeric(df["age"])

print(df.head())
# >>
#          name  age  birthdate
# 0  f42c2f1964   34 1985-02-23
# 1  2e586494b2   63 1963-05-10

These steps can be saved in policy files so you can share them and collaborate with your team:

# my-policy.yaml
label: my-policy
version: 1
rules:
  - match:
      name: age
    actions:
      - transform:
          type: numeric-perturbation
          dtype: Integer
          min: -10
          max: 10
          seed: 4984
  - match:
      name: name
    actions:
      - transform:
          type: tokenizer
          max_token_len: 10
          key: my secret

You can then load this policy and apply it to your data frame:

# df can be a Pandas or Spark data frame 
policy = cape.parse_policy("my-policy.yaml")
df = cape.apply_policy(policy, df)

print(df.head())
# >>
#          name  age  birthdate
# 0  f42c2f1964   34 1985-02-23
# 1  2e586494b2   63 1963-05-10

You can see more examples and usage here or in our documentation.

About Cape Privacy and Cape Python

Cape Privacy helps teams share data and make decisions for safer and more powerful data science. Learn more at capeprivacy.com.

Cape Python brings Cape's policy language to Pandas and Apache Spark. The supported techniques include tokenization with linkability as well as perturbation and rounding. You can experiment with these techniques programmatically, in Python or in human-readable policy files.

Cape architecture

Cape is comprised of multiples services and libraries. You can use Cape Python as a standalone library, or you can integrate it with the Coordinator in Cape Core, which supports user and policy management.

Project status and roadmap

Cape Python 0.1.1 was released 24th June 2020. It is actively maintained and developed, alongside other elements of the Cape ecosystem.

Upcoming features:

  • Reversible tokenisation: allow reversing of tokenization to reveal the raw value.
  • Policy audit logging: create logging hooks to allow audit logs for policy downloads and usage in Cape Python.
  • Expand pipeline integrations: add Apache Beam, Apache Flink, Apache Arrow Flight or Dask integration as another pipeline we can support, either as part of Cape Python or in its own separate project.

The goal is a complete data management ecosystem. Cape Privacy provides Cape Coordinator, to manage policy and users. This will interact with the Cape Privacy libraries (such as Cape Python) through a workers interface, and with your own data services through an API.

Help and resources

If you need help using Cape Python, you can:

Please file feature requests and bug reports as GitHub issues.

Community

Contributing

View our contributing guide for more information.

Code of conduct

Our code of conduct is included on the Cape Privacy website. All community members are expected to follow it. Please refer to that page for information on how to report problems.

License

Licensed under Apache License, Version 2.0 (see LICENSE or http://www.apache.org/licenses/LICENSE-2.0). Copyright as specified in NOTICE.

Metadata

Release files for cape-privacy 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cape-privacy 0.3.0
File Size Uploaded Provenance Actions
cape-privacy-0.3.0.tar.gz 31.9 kB Without provenance Details for cape-privacy-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cape-privacy 0.3.0
File Interpreter ABI Platform Actions
cape_privacy-0.3.0-py3-none-any.whl Python 3 none any Details for cape_privacy-0.3.0-py3-none-any.whl

Total release size: 80.0 kB

Release files / cape-privacy-0.3.0.tar.gz

Download URL cape-privacy-0.3.0.tar.gz
Size 31.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9e3fa1c8d497dcc5080167a96b4ae9cef2c215e0ee16a07649c25dee34175d2c
BLAKE2b-256 checksum
How to use checksums
9fbadcbd91eca5a47550da5a05064485e8c7625968bf23f65523bb902bfa2f46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Release files / cape_privacy-0.3.0-py3-none-any.whl

Download URL cape_privacy-0.3.0-py3-none-any.whl
Size 48.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d389384d712c7507ba0201adb8fc6fb60e72d8dfad12d41d90dbaabba876e977
BLAKE2b-256 checksum
How to use checksums
be4f69b9dc6671da03440a0de6880019af2fff40b34f49495a2b05b8b8c065cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Security for cape-privacy 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page