LinuxCommandLibrary

faker

Generate fake data for testing or development

TLDR

Show all fake data providers along with examples

$ faker
copy

Generate fake data of a specific type
$ faker [name|address|passport_full|credit_card_full|phone_number|email|company|date_time|user_name|password|job|...]
copy

Generate a number of fake addresses from a specific country (use localectl list-locales | cut --delimiter . --fields 1 to get list of locales)
$ faker [[-r|--repeat]] [number] [[-l|--lang]] [de_DE|de_CH|...] address
copy

Generate a number of cities in a specific country and output them to a file (use localectl list-locales | cut --delimiter . --fields 1 to get list of locales)
$ faker [[-r|--repeat]] [number] [[-l|--lang]] [en_AU|en_US|...] city -o [path/to/file.txt]
copy

Generate a number of random HTTP user-agents showing verbose output
$ faker [[-r|--repeat]] [number] [[-v|--verbose]] user_agent
copy

Generate a number of domain names and separate each using a specific separator
$ faker [[-r|--repeat]] [number] [[-s|--sep]] '[,]' domain_name
copy

SYNOPSIS

faker [options]

PARAMETERS

--version
    Show program's version number and exit

-h, --help
    Show help message and exit

-o OUTPUT, --output OUTPUT
    Write output to file

-r ROWS, --rows ROWS
    Number of rows to generate (default: 1)

-l LOCALE, --locale LOCALE
    Locale to use, e.g., en_US, fr_FR, etc. (default: en_US)

-f FORMAT, --format FORMAT
    Output format: csv, json, json_lines, pretty, sql, yaml (default: pretty)

-p PROVIDERS, --providers PROVIDERS
    Comma-separated list of faker providers, e.g., faker.providers.address,faker.providers.company

-t TEMPLATE, --template TEMPLATE
    Custom template. Can be file path or inline. Default format: '{{fake}}'

-e ENCODING, --encoding ENCODING
    Set output encoding (default: utf-8)

--include-header
    Include header for CSV and SQL formats

--table-name TABLE_NAME
    Table name for SQL format (default: fake_data)

--db-engine DB_ENGINE
    Database engine for SQL format e.g. postgresql+psycopg2://user:password@host:port/database

--create-db
    Create database if not exists.

DESCRIPTION

The faker command is a utility for generating fake data, primarily useful for testing, development, and demonstration purposes. It allows users to create realistic-looking but entirely fictional data sets of various types, such as names, addresses, phone numbers, email addresses, dates, and even company information.

Instead of relying on sensitive or real-world data during development, developers can use faker to quickly populate databases or test applications without risking data exposure or privacy violations. This command line tool relies on the Python package Faker, leveraging its rich collection of data providers and generators. It allows for customization using templates and various configuration options to match the data structure and formats required by your application. The tool supports generating data for various locales, enabling the creation of data sets with localized names, addresses, and other culture-specific information.

The command has been created as a standalone executable wrapper for the popular python package Faker.

CAVEATS

The quality and appropriateness of the generated data depend heavily on the selected locale and the available providers. It may not always produce perfectly realistic or comprehensive data sets. The `faker` command relies on the Python Faker library being installed in the system.

TEMPLATES

The faker command uses Jinja2 templating. Variables in templates are represented by double curly braces ({{ variable }}). You can use the word fake in your template to get a random entry from faker.

Example: faker -r 10 -t '{{name}}, {{email}}, {{address}}' -f csv

CUSTOMIZATION WITH PROVIDERS

The -p option is used to specify particular providers. Example: faker -r 2 -p faker.providers.address,faker.providers.internet -t '{{address}}, {{email}}'.

HISTORY

The `faker` command is a relatively recent addition to the command-line landscape, designed to provide easy access to the capabilities of the Python Faker library from the terminal. Its development is directly tied to the growing need for realistic test data in software development and data analysis. Faker was created in 2011. The Standalone executable command `faker` was created later to easily use the Faker package from the shell.

SEE ALSO

shred(1), dd(1)

Copied to clipboard