Utility for Generating Fake Data

In my past role as a performance tester, we often needed to generate fake data to populate a database or create a fake file system for backup job tests. Recently, I’ve discovered the Python implementation of Faker which is a useful utility that can generate fake personal data.

Faker documentation is available here

The utility comes complete with build in methods to fake names, addresses, phone numbers, ssn, web addresses, file paths, and bank code. It even provides localization options.

It is available to install from both pip and conda.

pip install Faker

To run it simply import, instantiate and add one of the prepackaged or external provideers.

from faker import Faker
from faker.providers import address, person, phone

fake = Faker('en_US')  #defaults to English if localization not specified
fake.add_provider(address)
fake.add_provider(person)
fake.add_provider(phone)

#generates a full address
address = fake.address()
city = fake.city()
zip = fake.postalcode()
street_address = fake.street_address()

The name provider provides the ability to generate general or generic specific names.

f_name = fake.first_name()
f_name_female = fake.first_name_femail()
f_name_male = fake.first_name_male()

It also provided an option to generate an entire user profile json object at once using the fake.profile call.

fake.profile(fields=None,sex=None) 
# {   'address': '34801 Richard Union Suite 310\nEast Ashleyberg, CT 22120',
#     'birthdate': datetime.date(1945, 7, 3),
#     'blood_group': 'O-',
#     'company': 'Ryan Inc',
#     'current_location': (Decimal('65.0444545'), Decimal('129.732926')),
#     'job': 'Arboriculturist',
#     'mail': 'fitzgeraldtravis@hotmail.com',
#     'name': 'Christopher Jensen',
#     'residence': '49824 Michael Spur\nTeresashire, NY 42820',
#     'sex': 'M',
#     'ssn': '726-99-4488',
#     'username': 'christopher50',
#     'website': [   'https://williams.info/',
#                    'https://www.montoya-young.com/',
#                    'https://www.morris.info/',
#                    'http://barrera-hernandez.com/']}