When developing scripts, you sometimes need fake data to test your code and implementations. This is where Faker comes into play. Faker is a Python package that generates fake data for you. It can create nearly everything you need, particularly for network automation: user accounts, IP addresses, subnets, MAC addresses, and more. Whether you need to bootstrap your database or anonymize data taken from a production service, Faker is the tool for you.
Install#
pip install Faker
Usage examples#
Initialize Faker
from faker import Faker
fake = Faker()
User accounts#
for _ in range(5):
print(fake.user_name())
Results:
tcaldwell
kaylamoreno
richardbeck
gweber
loriatkinson
Names#
for _ in range(5):
print(fake.name())
Results
Joshua Turner
Jennifer Guzman
Brooke Jensen
Michael Riley
Tonya Jones
IP addresses#
# private
for _ in range(5):
print(fake.ipv4_private())
# public ips
for _ in range(5):
print(fake.ipv4_public())
Subnets#
# private networks
for _ in range(5):
print(fake.ipv4_private(network=True))
# public networks
for _ in range(5):
print(fake.ipv4_public(network=True))
MACs#
for _ in range(5):
print(fake.mac_address())