Python Faker

    91 - Comments

last modified July 6, 2020

Python Faker tutorial shows how to generate fake data in Python with Faker package.We use the joke2k/faker library.

Faker is a Python package that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you. Everything listed here can be installed/updated via pacman. Depending on the mirror used, there might be a slight delay.


  • Everything listed here can be installed/updated via pacman. Depending on the mirror used, there might be a slight delay.
  • I have been using Python (along with bash et al) for a long time now for my Automation and Web Crawl i ng & Scraping endeavors. Create your own data stream for Kafka with Python and Faker.
  • Black Hat Python: Python Programming for Hackers and Pentesters Grey Hat Python: Python Programming for Hackers and Reverse Engineers The ability to program is a valuable asset for any aspiring security professional, especially if you’re interested in technical roles such as being a security engineer or penetration tester.

Faker is a Python library that generates fake data. Fake data is often used for testing or filling databases with some dummy data. Faker is heavily inspired by PHP's Faker,Perl's Data::Faker, and by Ruby's Faker.

Setting up Faker

The package is installed with composer.

We install the Faker module.

In addition, we install the Dumper, which provides nicer console output when dumping variables.

Faker generator

The faker.Faker() creates and initializes a faker generator, which cangenerate data by accessing properties named after the type of data.

Faker delegates the data generation to providers. The default provider uses theEnglish locale. Faker supports other locales; they differ in level ofcompletion.

Simple Faker

The following example is a simple demonstration of Faker.


The example outputs a fake name, address, and text.

This is a sample output.

Faking names

In the second example, we fake data related to user names.

The example creates fake full names, first names, last names of males and females.

This is a sample output.

Faking jobs

Jobs are generated with job().


The example creates six fake jobs.

This is a sample output.

Faking locale data

The Faker supports localized data to some extent. The locale is passed to the constructor method.Note that the locales are finished to various levels.

The example generates fake data in Czech language.

This is a sample output. Notice that Czech language has accents.

Faking currencies

The following example creates fake data for currencies.


The program generates fake currencies.

This is a sample output.

Faking words

Faker allows to create dummy words.

The example creates dummy words.

This line generates a fake word.

Here we generate six dummy words.

We can also create fake words from a predefined list of words.


This is a sample output.

Faking profiles

Faker can create simple dummy profiles with simple_profile() and extended profiles with profile().


The example creates dummy profiles for both males and females.

This is a sample output.

Faking numbers

The Faker allows to generate random digits and integers.


The example generates random digits and integers.

We can specify the bounds in the random_int() method.

This is a sample output.

Faking hashes and uuids

Faker support for dummy hashes and uuids.

The example generates three fake hash and one uuid values.

This is a sample output.

Faking internet related data

Faker has several accessors for faking internet related data.


The example shows various internet related data, including emails, domain names, slugs, IP addresses and URLs.

This is a sample output.

Faking date and time

Faker has plenty of methods for faking date and time values.

The first example shows fake methods for date of birth, datetime parts, timezone, and AM/PM.

This is a sample output.


The second example shows methods for generating datetime values in the current century, decade, year, or month. It also includes the generation of time series values.

This is a sample output.

The third example shows methods for various datetime formats, for getting datetime values for a chosen range, and for generating future or past values.

This is a sample output.

Generating XML data with Faker

In the following example, we generate XML data with Faker and Jinja2 template. The XML file will contain users.

We install the Jinja2 template engine.


The program generates a list of ten users. The list is passed to the Jinja2 template to be processed. The template is located in the templatesdirectory. The generated content is written to the users.xml file.

In the template, we use the for directive to process the list of users.

In this tutorial, we have used Python Faker to generate fake data in Python.

Read Python tutorial or list all Python tutorials.

Latest version


A tool to generate Databases with fake data

Project description

sql-faker is a python library that can be used to generate relational data structures and fill these structures with fake data.It is built upon python library sqlfaker made by kohleggermichael.sql-faker features Oracle SQL export support, enhanced handling of Faker methods and better foreign key generation.


Coming soon

Class structure

This project lets you define relational data structures that are build upon the concepts of Database, Table and Column.

A Database can have multiple Table objects which again can each have multiple Column objects.There are two classes that inherit from the Column class - ForeignKey and PrimaryKey. These allow you to create key columns.

Made possible thanks to kohleggermichaeland his package sqlfaker

Release historyRelease notifications RSS feed



Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for python-sql-faker, version 0.2
Filename, sizeFile typePython versionUpload dateHashes
Filename, size python_sql_faker-0.2-py3-none-any.whl (11.3 kB) File type Wheel Python version py3 Upload dateHashes
Filename, size python-sql-faker-0.2.tar.gz (7.5 kB) File type Source Python version None Upload dateHashes

Hashes for python_sql_faker-0.2-py3-none-any.whl

Hashes for python_sql_faker-0.2-py3-none-any.whl
AlgorithmHash digest

Python Faker Random Number

Hashes for python-sql-faker-0.2.tar.gz

Python Faker

Hashes for python-sql-faker-0.2.tar.gz
AlgorithmHash digest

Recent Pages