DEV Community

Free Python Code
Free Python Code

Posted on

How to Generates fake data In Python

Hi 🙂🖐

Welcome in new post, today i will share with you How to Generates fake data In Python and module called Faker

Faker is a Python package that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you.

Install it from here : pip install Faker

Examples of how to use

Generate fake names

from faker import Faker

fake = Faker()

print(fake.name())
Enter fullscreen mode Exit fullscreen mode

Generate fake address

from faker import Faker

fake = Faker()

print(fake.address())
Enter fullscreen mode Exit fullscreen mode

Generate fake ipv4

from faker import Faker
from faker.providers import internet

fake = Faker()
fake.add_provider(internet)

print(fake.ipv4_private())
Enter fullscreen mode Exit fullscreen mode

Generate fake emails

from faker import Faker

fake = Faker()

print(fake.email())
Enter fullscreen mode Exit fullscreen mode

Localization
faker.Faker can take a locale as an argument, to return localized data. If no localized provider is found, the factory falls back to the default LCID string for US english, ie: en_US.

from faker import Faker
fake = Faker('it_IT')
for _ in range(10):
    print(fake.name())
Enter fullscreen mode Exit fullscreen mode

result

Marina Cuomo
Ludovica Bocca
Sig.ra Isabella Aporti
Antonietta Zeffirelli-Carnera
Agostino Cortese
Sig.ra Laura Chittolini
Sig. Geronimo Ferragni
Piergiorgio Sorrentino
Mariano Goldstein
Erika Vercelloni
Enter fullscreen mode Exit fullscreen mode

For more info : https://pypi.org/project/Faker/

Now we're done 🤗

Don't forget to like and follow 🙂

Support me on PayPal 🤗
https://www.paypal.com/paypalme/amr396

Top comments (0)