DEV Community

Cover image for Dummy data generation with Python
petercour
petercour

Posted on

1 2

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:

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay