Skip to main content

Django Neuralyzer

PyPi - version Licence Python version Ruff

Anonymize instance data according to your need (GDPR, used in not-so-safe environments... )

Heavily inspired by django-anon

Like django-anon, django-neuralyzer will help you anonymize your model instance so it can be shared among developers, helping to reproduce bugs and make performance improvements in a production-like environment.

It also provide ability to target specific instance and not the whole database at once, so it can be use for GDPR compliance or "forget about be" feature of your app.

Usage

In your application, for instance in neuralyzers.py files, create a class that inherit of django-neuralyzer.BaseNeuralyzer to define your neuralyzer classes:

from django_neuralyzer.base import BaseNeuralyzer

from your_app.models import Person

class PersonNeuralyzer(BaseNeuralyzer):
   email = "example@anonymized.org"

   # You can use static values instead of callables
   is_admin = False

   class Meta:
      model = Person

Then, use the neuralyzer:

# run neuralyzer: be cautious, this will affect your current database!
person = Person.objects.last()

# neuralyze full table:
PersonNeuralyzer().run()

# neuralyze only some instance
PersonNeuralyzer().run(filters={"pk": person.pk})

Lazy attributes

Lazy attributes can be defined as inline lambdas or methods, as shown below, using the lazy_attribute function/decorator.

from django_neuralyzer.base import BaseNeuralyzer, lazy_attribute

from your_app.models import Person

class PersonNeuralyzer(BaseNeuralyzer):
   name = lazy_attribute(lambda o: 'x' * len(o.name))

   @lazy_attribute
   def date_of_birth(self):
      """Keep year and month"""
      return self.date_of_birth.replace(day=1)

   class Meta:
      model = Person

Management command

First, to have access to the management command, you need to register the app

INSTALLED_APPS = [
  ...
  "django_neuralyzer",
  ...
]

2 management command are given:

  1. ensure_fields_are_handled command
  2. export_neuralyzed_fields command

Ensure that all fields are neuralyzed

Ensure that all field of your model are handle by the neuralyzer:

django-manage ensure_fields_are_handled

If you want to ensure a field is handled, but you don't want to change its value, you can set it to NEURALYZER_NOOP:

from django_neuralyzer.base import BaseNeuralyzer, NEURALYZER_NOOP

from your_app.models import Person

class PersonNeuralyzer(BaseNeuralyzer):
   id = NEURALYZER_NOOP
   name = lazy_attribute(lambda o: 'x' * len(o.name))

   class Meta:
      model = Person

this way, ensure_fields_are_handled will not complain that id is not handled.

Export neuralyzed fields

It may be handy to export what fields are neuralyzed and how. Run the

django-manage export_neuralyzed_fields

and a neuralyzed_fields.csv will be created at the root of your application.

In order to document the lazy_attribute, the docstring of the function will be used to document how this field is neuralyzed.

Why neuralyzer ?

In Men in Black, a "neuralyzer" is a tool that wipe the mind of anybody who sees the flash via isolating and editing certain element of their memory.

This is exactly what this django package intent to do (remove or fake some attributes of instances), so we find it funny to name it like that.

Metadata

Release files for django-neuralyzer 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-neuralyzer 0.5.0
File Size Uploaded Provenance
django_neuralyzer-0.5.0.tar.gz 10.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-neuralyzer 0.5.0
File Interpreter ABI Platform
django_neuralyzer-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.2 kB

Release files / django_neuralyzer-0.5.0.tar.gz

Download URL django_neuralyzer-0.5.0.tar.gz
Size 10.5 kB
Tags Source
SHA-256 checksum
How to use checksums
792b678da271f78604e0673ded34f251bcb0a7c423669a2abade5c60ef8b55ec
BLAKE2b-256 checksum
How to use checksums
78b6af1fd6a6688e3c35b10557bfed881dfffd710e2a07113b182774b19c030a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / django_neuralyzer-0.5.0-py3-none-any.whl

Download URL django_neuralyzer-0.5.0-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d19793f9e2984452f9ce6d954b1579efcc1afbdb079230c851d00b3984f08ed3
BLAKE2b-256 checksum
How to use checksums
c7c2374e466457f2aa6b951f109218c8755fa5be9b592c612ca30b7ace52bfb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for django-neuralyzer 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page