{"id":163,"date":"2019-10-22T22:03:27","date_gmt":"2019-10-22T22:03:27","guid":{"rendered":"https:\/\/binaryopus.com\/?p=163"},"modified":"2019-10-22T22:04:52","modified_gmt":"2019-10-22T22:04:52","slug":"utility-for-generating-fake-data","status":"publish","type":"post","link":"https:\/\/binaryopus.com\/?p=163","title":{"rendered":"Utility for Generating Fake Data"},"content":{"rendered":"\n<p>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&#8217;ve discovered the Python implementation of Faker which is a useful utility that can generate fake personal data.<\/p>\n\n\n\n<p>Faker documentation is available <a href=\"https:\/\/faker.readthedocs.io\/en\/latest\/providers.html\">here<\/a><\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>It is available to install from both pip and conda.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install Faker<\/code><\/pre>\n\n\n\n<p>To run it simply import, instantiate and add one of the prepackaged or external provideers.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from faker import Faker\nfrom faker.providers import address, person, phone\n\nfake = Faker('en_US')  #defaults to English if localization not specified\nfake.add_provider(address)\nfake.add_provider(person)\nfake.add_provider(phone)\n\n#generates a full address\naddress = fake.address()\ncity = fake.city()\nzip = fake.postalcode()\nstreet_address = fake.street_address()\n<\/code><\/pre>\n\n\n\n<p>The name provider provides the ability to generate general or generic specific names.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>f_name = fake.first_name()\nf_name_female = fake.first_name_femail()\nf_name_male = fake.first_name_male()<\/code><\/pre>\n\n\n\n<p>It also provided an option to generate an entire user profile json object at once using the fake.profile call.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fake.profile(fields=None,sex=None) \n# {   'address': '34801 Richard Union Suite 310\\nEast Ashleyberg, CT 22120',\n#     'birthdate': datetime.date(1945, 7, 3),\n#     'blood_group': 'O-',\n#     'company': 'Ryan Inc',\n#     'current_location': (Decimal('65.0444545'), Decimal('129.732926')),\n#     'job': 'Arboriculturist',\n#     'mail': 'fitzgeraldtravis@hotmail.com',\n#     'name': 'Christopher Jensen',\n#     'residence': '49824 Michael Spur\\nTeresashire, NY 42820',\n#     'sex': 'M',\n#     'ssn': '726-99-4488',\n#     'username': 'christopher50',\n#     'website': [   'https:\/\/williams.info\/',\n#                    'https:\/\/www.montoya-young.com\/',\n#                    'https:\/\/www.morris.info\/',\n#                    'http:\/\/barrera-hernandez.com\/']}<\/code><\/pre>\n\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[24],"tags":[22,23,20,21],"_links":{"self":[{"href":"https:\/\/binaryopus.com\/index.php?rest_route=\/wp\/v2\/posts\/163"}],"collection":[{"href":"https:\/\/binaryopus.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/binaryopus.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/binaryopus.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/binaryopus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=163"}],"version-history":[{"count":2,"href":"https:\/\/binaryopus.com\/index.php?rest_route=\/wp\/v2\/posts\/163\/revisions"}],"predecessor-version":[{"id":165,"href":"https:\/\/binaryopus.com\/index.php?rest_route=\/wp\/v2\/posts\/163\/revisions\/165"}],"wp:attachment":[{"href":"https:\/\/binaryopus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/binaryopus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/binaryopus.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}