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 toNULL.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
Metadata
Release files for pyrify 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyrify-0.4.0.tar.gz | 12.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyrify-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.7 kB
Release files / pyrify-0.4.0.tar.gz
| Download URL | pyrify-0.4.0.tar.gz |
|---|---|
| Size | 12.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5e5a7c8e3a19b6cf796f7f37d0e70925f0168a44a6b49a7e5d19d8dd11d5016e
|
|
BLAKE2b-256 checksum How to use checksums |
782769c0034d33ceccea5ff3cae5ce885ba48d7091016feae76269b840bb9e0d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.4
|
Release files / pyrify-0.4.0-py3-none-any.whl
| Download URL | pyrify-0.4.0-py3-none-any.whl |
|---|---|
| Size | 13.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1a2c54f1b0539759617066f4704c474729eb715bcf347ccd948d02ef9cb5a1df
|
|
BLAKE2b-256 checksum How to use checksums |
a168492c6d2c98175bc6e1c13662ed717bd912d6876183d6f38c2d53cbfd802c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.4
|