Skip to main content
  1. Posts/

Faker - a fake data generator

·169 words·1 min·
Netdevops Blog Python
Maximilian Thoma
Author
Maximilian Thoma
network engineer
Table of Contents

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())

Documentation
#

Faker documentation

Related

LiveLab: Netbox VLAN deployment to Cisco devices
·1886 words·9 mins
Netdevops Livelab Blog Python Netbox Apiflask
Flask decorator for Netbox webhook authentication
·151 words·1 min
Netdevops Blog Python Netbox Webhook Flask Apiflask
Netdevops python libraries toolbox
·1720 words·9 mins
Netdevops Blog Python Apiflask Flask Loguru Ciscoconfparse Dynaconf Pymongo Rq Netmiko Paramiko Ansible Pandas Ntc_templates Textfsm Requests