A ‘replacer’ is a source of faked data. The replacers in this module can be referred to using a string that is simply the name of the function. They are listed below.
Returns a random boolean value (True/False)
Randomly chooses one of the choices set on the field.
Generates a random city name. Resembles the name of US/UK city.
Generates a random company name
Returns a random date
Returns a random datetime
Returns a random decimal
Generates a random email address.
Returns a random first name
Generates a random full address, using newline characters between the lines. Resembles a US address
Returns a random integer (for a Django IntegerField)
Returns a random second name
Generates a paragraph of lorem ipsum text
Generates a random full name (using first name and last name)
Generates a random US-style phone number
Returns a random positive integer (for a Django PositiveIntegerField)
Returns a positive small random integer (for a Django PositiveSmallIntegerField)
Returns a date that is within plus/minus two years of the original date
Returns a datetime that is within plus/minus two years of the original datetime
Generates lorem ipsum text with the same length and same pattern of linebreaks as the original. If the original often takes a standard form (e.g. a single word ‘yes’ or ‘no’), this could easily fail to hide the original data.
Returns a random small integer (for a Django SmallIntegerField)
Returns a randomly selected US state code
Generates a random street address - the first line of a full address
Returns a randomly selected country that is part of the UK
Returns a randomly selected county from the UK
Generates a random UK postcode (not necessarily valid, but it will look like one).
Generates a random username
Returns random data for a varchar field.
Returns a randomly generated US zip code (not necessarily valid, but will look like one).
Custom replacers can be used by defining them as callables.
When run by the anonymizer, the callable will be passed the Anonymizer object, the object being altered, the field being altered, and the current value of the field. It must return random data of the appropriate type. You can use lambda *args: my_constant_value to return a constant.
All of the replacers defined in this module use a anonymizer.base.DjangoFaker instance to generate fake data, and this object may be of use to you in writing your own replacers. The DjangoFaker instance is available on the Anonymizer instance in the faker attribute. So, you could have a replacer callable defined like this, which uses anonymizer.base.DjangoFaker.simple_pattern():
lambda anon, obj, field, val: anon.faker.simple_pattern('???##', field=field)