- Published on
Python Faker Package Common Usage
Faker is a package in Python for generating fake data. Fake data package is so useful for generating data for testing and mockup.
pip install Faker
You can create a python file and name it with anything you want like
main.py, but don’t name it with
faker.py or it will raise an exception error. Here is the initiation to use the package in the code:
from faker import Faker fake = Faker()
Generating person names
Random person’s full name (first and last name) with random gender
print(fake.name()) # 'Kayla Holland'
Random male or female name
print(fake.name_male()) # 'Don Brown' print(fake.name_female()) # 'Melissa Phillips'
Random person’s first or last name
print(fake.first_name()) # 'Darren' print(fake.last_name()) # 'Miller' print(fake.first_name_male()) # 'Christopher' print(fake.last_name_male()) # 'Ruiz' print(fake.first_name_female()) # 'April' print(fake.last_name_female()) # 'Turner'
print(fake.text()) """ Including very cover remain maintain. Worry food discover human cell. Expert store compare rock citizen small. """
Random paragraph with a defined number of sentences:
print(fake.paragraph(nb_sentences=5)) """ Name amount skill hot material different. Piece fact fly truth first. Factor health prove allow. Require hard sound believe. Practice game education later note receive beautiful. International coach politics. """
Random paragraphs with a defined amount of paragraphs:
print(fake.paragraphs(nb=3)) """ ['Interest stuff if once decide.', 'Society off back hear seven family wrong argue. Ever card culture under great phone range your. Talk involve because month service our black.', 'Direction tend create single life help. Thank machine may believe describe.'] """