DEV Community

Cover image for Dummy data generation with Python
petercour
petercour

Posted on

Dummy data generation with Python

Do you need Dummy data for your app? You can do that with the Python programming language. The module Faker lets you generate fake data.

That is very useful when you are just starting out building an app and do not have any data yet.

#!/usr/bin/python3
from faker import Faker
fake = Faker()

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

It will generate a new name each run:

λ  python3 test.py  
Sean Weber
λ  python3 test.py
Angelica Watson
Enter fullscreen mode Exit fullscreen mode

It can automatically generate an address to:

#!/usr/bin/python3
from faker import Faker
fake = Faker()

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

Example run:

Dr. Derek Scott
010 Ortega Spring
Samanthaburgh, CT 36146
Enter fullscreen mode Exit fullscreen mode

These are all English names and addresses. It works for international fake data too:

Just add the locale, for Italy:

fake = Faker('it_IT')
Enter fullscreen mode Exit fullscreen mode

If you need many fake names and addresses, use a for loop to wrap it in.

Related links:

Top comments (0)