main_13.py 786 B

1234567891011121314151617181920212223
  1. def pseudonymize_columns(dataframe, cols,
  2. ps_key='test',
  3. api_key=SHARED_KEY):
  4. actions = [
  5. {"name": "pseudonymize-{}".format(c),
  6. "transform-value": {
  7. "key": c,
  8. "pseudonymize": {
  9. "method": "merengue",
  10. "key": ps_key,
  11. }
  12. }
  13. } for c in cols]
  14. items = dataframe.fillna('').T.to_dict()
  15. item_list = list(items.values())
  16. data = requests.post(
  17. 'https://api.kiprotect.com/v1/transform',
  18. data=json.dumps(
  19. {"actions": actions, "items": item_list},
  20. allow_nan=False),
  21. headers={
  22. 'Authorization': 'Bearer {}'.format(api_key)})
  23. return pd.DataFrame(data.json()['items'])