Online Faker Compiler

Generate fake names, emails, addresses and dates in your browser, with seeds, locales, pandas DataFrames and custom values.

Python
from faker import Faker
fake = Faker('it_IT')

print("Name,Email,Date of birth")
for _ in range(10):
    name = fake.name()
    email = fake.email()
    dob = fake.date_of_birth()
    print(f"{name},{email},{dob}")
Name,Email,Date of birth
Gianluca Majewski,[email protected],1966-03-26
Serena Borgia,[email protected],1980-04-07
Annamaria Finzi-Baglioni,[email protected],1921-04-04
Baccio Surian,[email protected],1955-10-16
Dott. Loredana Sollima,[email protected],1913-05-13
Domenico Zaguri,[email protected],2009-05-21
Sig. Salvatore Einaudi,[email protected],1938-02-19
Enzo Agostini,[email protected],1992-07-21
Maurizio Donà,[email protected],2003-06-27
Sig.ra Lisa Roncalli,[email protected],1988-03-16

Faker generates realistic but made-up data: names, addresses, emails, phone numbers, dates, companies, text and more. Each kind of value is a method on a Faker object, such as fake.address() or fake.company(). Developers use it to fill test databases, build demo datasets and try code on personal data without touching real records. This page is an online Faker compiler: the code runs in your browser, so you can try it without installing anything. Run the example first, then paste any snippet below into a new cell to try it.

What the example does

Faker("it_IT") creates a generator for Italian data, so the names are Italian and some start with a title such as "Dott." or "Sig.ra". Each call to fake.name(), fake.email() or fake.date_of_birth() returns a new random value, and the loop prints ten rows as CSV under a header line. The email is built from a random user name, so it does not match the person's name. Without a seed, every run prints different people.

Get the same data on every run

Faker.seed() fixes the random sequence, which is what tests need. It applies to every Faker object. fake.seed_instance(42) seeds one object only:

from faker import Faker

fake = Faker()
Faker.seed(42)
first = [fake.name() for _ in range(3)]
Faker.seed(42)
second = [fake.name() for _ in range(3)]
print(first)
print(first == second)

Use other locales

A locale code gives names, addresses and phone numbers in that country's format. A list of codes mixes them, and indexing picks one:

from faker import Faker

Faker.seed(0)
de = Faker("de_DE")
print(de.address())
print(de.phone_number())

mixed = Faker(["en_US", "ja_JP", "pt_BR"])
for _ in range(3):
    print(mixed.name())
print(mixed["ja_JP"].city())

faker.config.AVAILABLE_LOCALES lists every supported code.

Build a pandas DataFrame

Generate one dict per row and hand the list to pandas. date_between() counts back from today by default, so fixed start and end dates keep the output the same from day to day:

import datetime
import pandas as pd
from faker import Faker

fake = Faker()
Faker.seed(1)
rows = [
    {
        "name": fake.name(),
        "email": fake.unique.email(),
        "signup": fake.date_between(datetime.date(2024, 1, 1), datetime.date(2024, 12, 31)),
        "plan": fake.random_element(["free", "pro", "team"]),
        "seats": fake.pyint(1, 50),
    }
    for _ in range(100)
]
df = pd.DataFrame(rows)
df.to_csv("customers.csv", index=False)
print(df.head())

fake.unique.email() makes sure no two rows share an address, and df.to_csv() writes the table to customers.csv.

Add your own values

DynamicProvider adds a method that picks from your own list. bothify() fills a pattern, turning each ? into a letter and each # into a digit, which suits order numbers and codes. numerify() and lexify() fill digits only or letters only:

from faker import Faker
from faker.providers import DynamicProvider

fake = Faker()
fake.add_provider(DynamicProvider(
    provider_name="department",
    elements=["Sales", "Support", "Engineering", "Finance"],
))
Faker.seed(3)
for _ in range(3):
    print(fake.department(), fake.bothify("ORD-??-####", letters="ABCDEF"))

Good to know

  • fake.email() only produces addresses at example.com, example.org and example.net, unless you pass your own, as in fake.email(domain="acme.test"). fake.free_email() uses gmail.com, yahoo.com and hotmail.com instead.
  • date_of_birth() covers ages 0 to 115 by default, which is why the example can print a child's birth date. Pass minimum_age=18 for adults.
  • fake.unique never repeats a value and raises UniquenessException when it runs out, as fake.unique.random_int(1, 3) does on its fourth call. fake.unique.clear() starts it over.