Skip to main content

Data pseudonymization functions used by SSB

Project description

SSB Pseudonymization Functions

Data pseudonymization functions used by Statistics Norway (SSB)

PyPI version Status License

Pseudonymization is a data management and de-identification procedure by which personally identifiable information fields within a data record are replaced by one or more artificial identifiers, or pseudonyms. A single pseudonym for each replaced field or collection of replaced fields makes the data record less identifiable while remaining suitable for data analysis and data processing.

This lib contains functions that can be used to implement data pseudonymization. In SSB we're invoking these functions within our Spark data management platform, by wrapping the lib as UDFs.

It is important to note that pseudonymization is not the same as anonymization. While pseudonymization targets directly identifying elements, the real information might still be identifiable e.g. by using inherent information such as correlation between data elements. Thus, sensitive data that has been pseudonomized using the functions in this library should still be regarded as sensitive.

The library is currently in a "pre-alpha" stage. We're currently experimenting with the architecture related to how and when psedonymization is being applied in our data management platform. Also, currently there are only a few and simplistic functions in this library. Breaking changes should be expected.

Installation

pip install ssb-pseudonymization

Usage example

Invoking a function

A pseudo function accepts a config dictionary and a value argument to be pseudonymized.

from ssb_pseudonymization.func import fpe

func_config = {
    'key': 'some-secret-key', 
    'alphabet': string.ascii_letters + ' '
}

p = fpe.apply(func_config, 'Ken sent me')
# p = 'fMLzJCeVJfP'

Invoking a function in a generic way

To invoke a pseudo function in a more generic way, you can use the pseudo_func facade:

from ssb_pseudonymization import pseudo_func

func_config_json = json.dumps({
    'func': 'fpe',
    'key': 'some-secret-key', 
    'alphabet': string.ascii_letters + ' '
})
p = pseudo_func.invoke(func_config_json, "Ken sent me")
# p = 'fMLzJCeVJfP'

Notice that the config must be a json string and you must specify the function in config (func='...').

For more examples and usage, have a look at the tests.

Development setup

Run make help to see common development commands.

install-build-tools            Install required tools for build/dev
build                          Build dist
test                           Run tests
clean                          Clean all build artifacts
release-validate               Validate that a distribution will render properly on PyPI
release-test                   Release a new version, uploading it to PyPI Test
release                        Release a new version, uploading it to PyPI
bump-version-patch             Bump patch version, e.g. 0.0.1 -> 0.0.2
bump-version-minor             Bump minor version, e.g. 0.0.1 -> 0.1.0

Refer to the Makefile to see details about the different tasks.

Testing

Run tests for all python distributions using

make test

This will require that your dev machine has the required python distributions installed locally. (You can install python distributions using pyenv.)

Releasing

Prerequisites: You will need to register accounts on PyPI and TestPyPI.

Before releasing, make sure you're working on a "new" version number. You can bump the version using the bumpversion tool.

Also, make sure to update release notes.

To release and publish a new version to PyPI:

make release-validate

This will run tests, build distribution packages and perform some rudimentary PyPI compliancy checking.

For a dress rehearsal, you can do a test release to the TestPyPI index. TestPyPI is very useful, as you can try all the steps of publishing a package without any consequences if you mess up. Read more about TestPyPI here.

make release-test

To perform the actual release, run:

make release

You should see the new release appearing here (it might take a couple of minutes for the index to update).

Release History

  • 0.0.1
    • Initial version with "Mickey Mouse" pseudo functions
  • 0.0.2
    • Improve docs

Meta

Statistics Norway – https://github.com/statisticsnorway

Distributed under the MIT license. See LICENSE for more information.

[https://github.com/statisticsnorway/ssb-pseudonymization-py]

Contributing

  1. Fork it (https://github.com/statisticsnorway/ssb-pseudonymization-py/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

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

ssb-pseudonymization-0.0.2.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

ssb_pseudonymization-0.0.2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file ssb-pseudonymization-0.0.2.tar.gz.

File metadata

  • Download URL: ssb-pseudonymization-0.0.2.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.4

File hashes

Hashes for ssb-pseudonymization-0.0.2.tar.gz
Algorithm Hash digest
SHA256 7a57114068e0324675d997e2b65673f531f2387c68d8ec43e391ed4f845cd068
MD5 7e6110ba6274d847a6466fb24d6e971f
BLAKE2b-256 1df2a7677c5c74c133edafc48f65fdf5878d0267d050e577532e571f7666a0d6

See more details on using hashes here.

File details

Details for the file ssb_pseudonymization-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: ssb_pseudonymization-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.4

File hashes

Hashes for ssb_pseudonymization-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 12e815768c7c29f3dedeed688140dc96a7f3de99c61f83f50cdd0323ac602418
MD5 10afae4dd56b9514db9969782e5d0a87
BLAKE2b-256 f51151002572cc3a6ebf64ffbebbf8f139ce8f098d74df8935f27461426faa58

See more details on using hashes here.

Supported by

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