Sanitizes contents of a database.
Project description
Database sanitation tool
database-sanitizer
is a tool which retrieves an database dump from
relational database and performs sanitation on the retrieved data
according to rules defined in a configuration file. Currently the
sanitation tool supports both PostgreSQL and MySQL databases.
Installation
database-sanitizer
can be installed from PyPI with pip like this:
$ pip install database-sanitizer
If you are using MySQL, you need to install the package like this instead, so that additional requirements are included:
$ pip install database-sanitizer[MySQL]
Usage
Once the package has been installed, database-sanitizer
can be used
like this:
$ database-sanitizer <DATABASE-URL>
Command line argument DATABASE-URL
needs to be provided so the tool
knows how to retrieve the dump from the database. With PostgreSQL, it
would be something like this:
$ database-sanitizer postgres://user:password@host/database
However, unless an configuration file is provided, no sanitation will be performed on the retrieved database dump, which leads us to the next section which will be...
Configuration
Rules for the sanitation can be given in a configuration file written in
YAML. Path to the configuration file is then given to the command line
utility with --config
argument (-c
for shorthand) like this:
$ database-sanitizer -c config.yml postgres://user:password@host/database
The configuration file uses following kind of syntax:
config:
addons:
- some.other.package
- yet.another.package
strategy:
user:
first_name: name.first_name
last_name: name.last_name
secret_key: string.empty
Note: In Py2 environments you need to use !!python/unicode
yaml tag to
have the sanitizer config values properly converted into unicode
objects.
So e.g.:
strategy:
user:
first_name: !!python/unicode name.first_name
In the example configuration above, there are first listed two "addon
packages", which are names of Python packages where the sanitizer will
be looking for sanitizer functions. They are completely optional and can
be omitted, in which case only sanitizer functions defined in package
called sanitizers
and built-in sanitizers will be used instead.
The strategy
portion of the configuration contains the actual
sanitation rules. First you define name of the database table (in the
example that would be user
) followed by column names in that table
which each one mapped to sanitation function name. The name of the
sanitation function consists from two parts separated from each other by
a dot: Python module name and name of the actual function, which will
be prefixed with sanitize_
, so name.first_name
would be a function
called sanitize_first_name
in a file called name.py
.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for database_sanitizer-0.4.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a405f2a6c17c8151ddde3768dec98c15f3cef1ccd17337639544b3fd6ca0281 |
|
MD5 | 6591a9769de362810c9906f2731039fb |
|
BLAKE2b-256 | 7cd504bc3ce1627a1f56bafff14886f789b5b0bac109dc7c54fb30e505d43caa |