You Faker
Tags: python, flask
Published: 2024-01-27 01:21:44

Here we are at the end of week 12 at Flatiron School. In this phase, p4, my cohort mates and I were introduced to Flask. We're finally working with back-end and tying it into our front-end(React). It has been really exciting, but also very nerve-racking. We are so close to the finish line, only 3 weeks to go, but we also now have to go back and remember that stuff we possibly haven't touched in 5 weeks, because we were so focused on learning Python. 

And did I mention Deployment? 🤯 Trying to weed my way through that whole process has begun to add a whole new level of stress. But that's another story.

I have been feeling the imposter syndrome a lot this last week. Getting back into React things looked familiar, but I felt like I didn't know what I was doing. I kinda felt like I was faking it! Which happens to be something Python can do, with the Faker library.

**What is Faker?**

Faker is a Python library that allows developers to create fake data, such as names, addresses, sentences, and email addresses. It gives you a simple way to produce random data that looks like real information.

**Why Would I Want to Use Faker?**

It is good for testing or simulating interactions. We all likely  encountered it in our phase 4 projects, as we had to create databases that shared connections with other databases in one-to-many and many-to-many relationships. It would have taken a lot of time to manually fill in those databases with information that we would have had to make up anyway. So, in comes Faker.

**_Let's look at what Faker can do!_**

Faker can create names:
 - name() = a random full name
 - first_name() = a random first name only
 - last_name() = a random last name only
 - prefix() = a random prefix(Mr., Dr., Ms., etc)

Faker can create locations and addresses:
 - email() = a random email address
 - address() = a random street address
 - city() = a random city name
 - state() = a random state name or abbreviation
 - country() = a random country name
 - url() = a random URL

Faker can create dates and times:
 - date_of_birth() = a random date of birth
 - date() = a random date
 - time() = a random time
 - date_time() = a random date and time
 
Faker can create writing:
 - text() = a random paragraph(non-sensical) 
 - sentence() = a random sentence(non-sensical)
 - word() = a random word

Those are just a sample. Faker can also create phone numbers, credit card information, numbers, and colors, to name a few more.

_**Lets see how it looks in our code 👇🏻**_


![Faker code snippet](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v92vdts40tnw1f24o57z.png)


![Output from Faker snippet](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/14vjd505o6xutildztne.png)

Those all look reasonably real, if you don't look too close.


_**Faker's limitations**_

Faker can randomize locations, but it is limited to predefined locations. So, if you are trying to generate data for a specific region, it may not work.

Also, if I try to look up any of the output from above, like South Cynthia, in Google Maps, the first match for a destination is S. Cynthia St., McAllen, TX. It is not a town in Oklahoma. When I look up the zip code, I found that it belongs New Orleans, LA. Another run of the same code gave me the postal code, 26368, for a city called Kupinik, in Serbia. Not South Adam, MO.
If we look at the phone number, the country code(+1) is the USA, but the area code does not currently  exist. 375 is the country code(+375) for Belarus. 
*Fun Fact - on a little further digging, according to KMPH Fox 26, the Central Valley will be getting a 375 area code once they run out of 559 numbers.

_**Where does Faker really struggle?**_

Like I said above, if you don't look to close, the output looks good. But is there a situation where it's obviously not real?
Yes!
I give you: sentence()!


![Faker sentence](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gtbtvhrs9vxsc1g3wbt7.png)

![confused toddler](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ukcgvwv74wlcqze5x55f.jpg)
That sentence makes as much sense as the look on my face and that outfit(and my sister's outfit, behind me, given that it was Christmas. Ah, the 80's!).

**_Conclusion_**

Faker has some good uses and just like anything fake, not so good uses. If your using Faker to just auto-populate some databases that aren't really going to be seen, fake away! But if that data might actually be seen or needs to make sense, your better off manually entering it.

Happy Faking!


________

**Resources:**
Tellez, M. 'New area code coming to Central Valley'. Published 21 December 2023. Retrieved on 26 January 2024, from 
https://kmph.com/news/local/new-area-code-coming-to-central-valley-357-overlay-geographic-fresno-county-san-juaquin-madera-mariposa-merced-tulare-kings-counties-clovis-porterville-reedley-selma-visalia-coalinga

Das, M. 'Faker: Python is Just a Fake Away!'. Published 9 August 2023. Retrieved on 19 January 2024 from https://medium.com/@HeCanThink/faker-python-is-just-a-fake-away-ef626a0dcf8d