CLI

All current providers are supported through CLI.

The entrypoint command is fake-py.


Help

All commands overview

Command

fake-py --help

Output

usage: fake-py [-h]
               {bmp,bmp_file,company_email,date,date_time,docx,docx_file,
                domain_name,email,file_name,first_name,first_names,
                free_email,free_email_domain,generic_file,gif,gif_file,
                image,image_url,ipv4,last_name,last_names,name,names,
                paragraph,paragraphs,pdf,pdf_file,png,png_file,pybool,
                pydecimal,pyfloat,pyint,pystr,random_choice,random_sample,
                sentence,sentences,slug,slugs,svg,svg_file,text,text_pdf,
                text_pdf_file,texts,tld,txt_file,url,username,usernames,
                uuid,uuids,word,words}
               ...

CLI for fake.py

positional arguments:
  {bmp,bmp_file,company_email,date,date_time,docx,docx_file,domain_name,
   email,file_name,first_name,first_names,free_email,free_email_domain,
   generic_file,gif,gif_file,image,image_url,ipv4,last_name,last_names,
   name,names,paragraph,paragraphs,pdf,pdf_file,png,png_file,pybool,
   pydecimal,pyfloat,pyint,pystr,random_choice,random_sample,sentence,
   sentences,slug,slugs,svg,svg_file,text,text_pdf,text_pdf_file,texts,
   tld,txt_file,url,username,usernames,uuid,uuids,word,words}
                        Available commands
    bmp                 Create a BMP image of a specified size and color.
    bmp_file            Create a BMP image file of a specified size and
                        color.
    company_email       Generate a random company email.
    date                Generate random date between `start_date`
                        and `end_date`.
    date_time           Generate a random datetime between `start_date`
                        and `end_date`.
    docx                Create a DOCX document.
    docx_file           Create a DOCX document file.
    domain_name         Generate a random domain name.
    email               Generate a random email.
    file_name           Generate a random filename.
    first_name          Generate a first name.
    first_names         Generate a list of first names.
    free_email          Generate a random free email.
    free_email_domain   Generate a random free email domain.
    generic_file        Create a generic file.
    gif                 Create a GIF image of a specified size and color.
    gif_file            Create a GIF image file of a specified size and
                        color.
    image               Create an image of a specified format, size and
                        color.
    image_url           Generate a random image URL.
    ipv4                Generate a random IP v4.
    last_name           Generate a last name.
    last_names          Generate a list of last names.
    name                Generate a name.
    names               Generate a list of names.
    paragraph           Generate a paragraph.
    paragraphs          Generate a list of paragraphs.
    pdf                 Create a PDF document of a given size.
    pdf_file            Create a PDF file.
    png                 Create a PNG image of a specified size and color.
    png_file            Create a PNG image file of a specified size and
                        color.
    pybool              Generate a random boolean.
    pydecimal           Generate a random Decimal number.
    pyfloat             Generate a random float number.
    pyint               Generate a random integer.
    pystr               Generate a random string.
    random_choice
    random_sample
    sentence            Generate a sentence.
    sentences           Generate a list of sentences.
    slug                Generate a slug.
    slugs               Generate a list of slugs.
    svg                 Create an SVG image of a specified size and color.
    svg_file            Create an SVG image file of a specified size and
                        color.
    text                Generate a text.
    text_pdf            Create a PDF document of a given size.
    text_pdf_file       Create a text PDF file.
    texts               Generate a list of texts.
    tld                 Generate a random TLD.
    txt_file            Create a text document file.
    url                 Generate a random URL.
    username            Generate a username.
    usernames           Generate a list of usernames.
    uuid                Generate a UUID.
    uuids               Generate a list of UUIDs.
    word                Generate a word.
    words               Generate a list of words.

options:
  -h, --help            show this help message and exit

Specific command help

Each command has help too.

Command

fake-py url --help

Output

usage: fake-py url [-h] [--protocols PROTOCOLS] [--tlds TLDS] [--suffixes SUFFIXES]

options:
  -h, --help            show this help message and exit
  --protocols PROTOCOLS
                        protocols (type: Optional[tuple[str, ...]])
  --tlds TLDS           tlds (type: Optional[tuple[str, ...]])
  --suffixes SUFFIXES   suffixes (type: Optional[tuple[str, ...]])

Common commands

company_email

With defaults

Command

fake-py company_email

Output

michaelfrechet@right.com

With customisations

Command

fake-py company_email --domain_names="github.com,microsoft.com"

Output

barrybaxter@github.com

date

With defaults

Command

fake-py date

Output

2024-06-21

With customisations

Command

fake-py date --start_date="-7d" --end_date="7d"

Output

2024-07-04

docx_file

With defaults

Command

fake-py docx_file

Output

tmp/tmp_0tnpurz.docx

With customisations

Command

fake-py docx_file --nb_pages=100 --basename="my_docx_file"

Output

tmp/my_docx_file.docx

email

With defaults

Command

fake-py email

Output

bad@not.org

With customisations

Command

fake-py email --domain_names="github.com,microsoft.com"

Output

guess@github.com

url

With defaults

Command

fake-py url

Output

http://one.com/lets.php

With customisations

Command

fake-py url --tlds="am,nl,ie"

Output

https://readability.ie/face.go

slug

Command

fake-py slug

Output

unless-ambiguity-to-taaxihkoywxbolrienhq

text

With defaults

Command

fake-py text

Output

Should sparse and of idea. Is is is it than. Idea should is should
explicitly. Are often practicality refuse than. Of the of in do.
Is errors namespaces the better. Never to is do idea. The complicate.

With customisations

Command

fake-py text --nb_chars=75

Output

Complicated is than explain right. Be silently better idea hard. Break than

username

Command

fake-py username

Output

better_if_great_ldffdumuptmqtzssjbgv

Customisation

By default, only standard (built-in) providers are available through CLI.

However, you can easily expose your providers via CLI too. See the implementation below as an example.

Filename: data.py

STREET_NAMES = [
    "Oranjestraat",
    "Groningerweg",
    "Kamperfoeliestraat",
    "Larixlaan",
]

CITIES = [
    "Amsterdam",
    "Rotterdam",
    "Den Haag",
    "Capelle aan den IJssel",
    "Assen",
]

REGIONS = [
    "Drenthe",
    "Flevoland",
    "Zeeland",
    "Zuid-Holland",
]

Filename: fake_address.py

import random
import string

from fake import Factory, Faker, provider

from data import CITIES, REGIONS, STREET_NAMES


class FakerAddress(Faker):
    """Custom Faker class for addresses."""

    @provider
    def address_line(self) -> str:
        """Generate a random Dutch address line like 'Oranjestraat 1'.

        :return: A randomly generated Dutch address line as a string.
        :rtype: str
        """
        # Generate components of the address
        street = random.choice(STREET_NAMES)
        house_number = random.randint(1, 200)
        suffixes = [""] * 10 + ["A", "B", "C"]  # Optional suffixes
        suffix = random.choice(suffixes)

        # Combine components into a Dutch address format
        return f"{street} {house_number}{suffix}"

    @provider
    def city(self) -> str:
        return random.choice(CITIES)

    @provider
    def region(self) -> str:
        return random.choice(REGIONS)

    @provider
    def postal_code(self) -> str:
        """Generate a random Dutch postal code in the format '1234 AB'.

        :return: A randomly generated Dutch postal code as a string.
        :rtype: str
        """
        number_part = "".join(random.choices(string.digits, k=4))
        letter_part = "".join(random.choices(string.ascii_uppercase, k=2))
        return f"{number_part} {letter_part}"


FAKER = FakerAddress(alias="address")
FACTORY = Factory(FAKER)

Filename: address_cli.py

from fake import CLI

from fake_address import FAKER


def main():
    cli = CLI(faker=FAKER)
    cli.execute_command()


if __name__ == "__main__":
    main()

After that you can use it as follows:

python address_cli.py --help