Skip to main content

Pyrify

A CLI tool for database sanitization

Installation

pip install pyrify

Initialize the sanitize config

Initialize from database

By providing the database URI, the tool will automatically generate a sanitize config file. Currently, the tool supports PostgreSQL, MySQL (with pymysql), and SQLite.

# PostgreSQL
pyrify init -d "postgresql://user:pass@localhost/db_name" > config.yml

# MySQL
pyrify init -d "mysql+pymysql://user:pass@localhost/db_name" > config.yml

# SQLite
pyrify init -d "sqlite:///db-sanitize.db" > config.yml

Use sanitize config template

You can use a template to generate the sanitize config file.

pyrify template -t ckan_211 > config.yml

To see the available templates, run:

pyrify template

Configure the sanitize config

The init command will create a config file with the following structure:

table_name:
  columns:
    column_name1: '~'
    column_name2: '~'
    column_name3: '~'

If you don't need to sanitize a table or a column, you can remove it from the config file.

There are 3 key options:

  • clean: This will clean the table (remove all data).
  • drop: This will drop the table.
  • columns: This will apply a specific sanitization strategy to the column.

Example:

activity:
  clean: true

unused_table:
  drop: true

user:
  columns:
    plugin_extras:
      strategy: json_update
      kwargs:
        columns:
          test: fake_password
    last_active: nullify
    fullname: fake_fullname
    image_url: nullify
    email: fake_email
    name: fake_username
    password: fake_password
    about: fake_text

Strategies

The following strategies are available:

  • fake_username: This will generate a fake username.
  • fake_fullname: This will generate a fake full name.
  • fake_text: This will generate a fake text.
  • fake_email: This will generate a fake email.
  • fake_password: This will generate a fake password.
  • fake_phone_number: This will generate a fake phone number.
  • fake_address: This will generate a fake address.
  • nullify: This will set the column to NULL.
  • json_update: This will update the JSON key with the new value.

Sanitize the database

Below are some examples of how to sanitize the database.

The -d option is the database URI and the -c option is the path to the sanitize config file.

pyrify sanitize -d "postgresql://root:root@localhost/db_name" -c config.yml
pyrify sanitize -d "mysql+pymysql://root:root@127.0.0.1:3306/db_name" -c config.yml

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrify-0.4.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyrify-0.4.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file pyrify-0.4.0.tar.gz.

File metadata

  • Download URL: pyrify-0.4.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for pyrify-0.4.0.tar.gz
Algorithm Hash digest
SHA256 5e5a7c8e3a19b6cf796f7f37d0e70925f0168a44a6b49a7e5d19d8dd11d5016e
MD5 6398fb823dea63afe718210eb5ad1f67
BLAKE2b-256 782769c0034d33ceccea5ff3cae5ce885ba48d7091016feae76269b840bb9e0d

See more details on using hashes here.

File details

Details for the file pyrify-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: pyrify-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for pyrify-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1a2c54f1b0539759617066f4704c474729eb715bcf347ccd948d02ef9cb5a1df
MD5 6ed7d0a178fa0086e444981d29216dee
BLAKE2b-256 a168492c6d2c98175bc6e1c13662ed717bd912d6876183d6f38c2d53cbfd802c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 files

0.3.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page