# CLI All current providers are supported through the CLI. The CLI entry point is the `fake-py` command. --- ## Help ### All commands overview *Command* ```sh fake-py --help ``` *Output* ```sh 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 colour. bmp_file Create a BMP image file of a specified size and colour. 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 colour. gif_file Create a GIF image file of a specified size and colour. image Create an image of a specified format, size and colour. 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 colour. png_file Create a PNG image file of a specified size and colour. 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 colour. svg_file Create an SVG image file of a specified size and colour. 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* ```default fake-py url --help ``` *Output* ```sh 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* ```sh fake-py company_email ``` *Output* ```text michaelfrechet@right.com ``` **With customisations** *Command* ```sh fake-py company_email --domain_names="github.com,microsoft.com" ``` *Output* ```text barrybaxter@github.com ``` --- ### date **With defaults** *Command* ```sh fake-py date ``` *Output* ```text 2024-06-21 ``` --- **With customisations** *Command* ```sh fake-py date --start_date="-7d" --end_date="7d" ``` *Output* ```text 2024-07-04 ``` Both `--start_date` and `--end_date` support: 1. **ISO format dates**: - `'YYYY-MM-DD'` (e.g., `'2000-01-01'`) - `'YYYY-MM-DD HH:MM:SS'` (e.g., `'2000-01-01 12:00:00'`) 2. **Relative shorthand notation**: `[+/-][number][unit]` Units: `d` days, `h` hours, `m` minutes, `w` weeks, `mo` months, `y` years Sign: `+` for future, `-` for past Special: `'now'`, `'today'` for current datetime Examples: - `-7d`: 7 days ago - `+3d` or `3d`: 3 days from now - `-2w`: 2 weeks ago - `+1mo`: 1 month from now - `-1y`: 1 year ago --- ### docx_file **With defaults** *Command* ```sh fake-py docx_file ``` *Output* ```text tmp/tmp_0tnpurz.docx ``` --- **With customisations** *Command* ```sh fake-py docx_file --nb_pages=100 --basename="my_docx_file" ``` *Output* ```text tmp/my_docx_file.docx ``` --- ### email **With defaults** *Command* ```sh fake-py email ``` *Output* ```text bad@not.org ``` **With customisations** *Command* ```sh fake-py email --domain_names="github.com,microsoft.com" ``` *Output* ```text guess@github.com ``` --- ### url **With defaults** *Command* ```sh fake-py url ``` *Output* ```text http://one.com/lets.php ``` --- **With customisations** *Command* ```sh fake-py url --tlds="am,nl,ie" ``` *Output* ```text https://readability.ie/face.go ``` --- ### slug *Command* ```sh fake-py slug ``` *Output* ```text unless-ambiguity-to-taaxihkoywxbolrienhq ``` --- ### text **With defaults** *Command* ```sh fake-py text ``` *Output* ```text 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* ```sh fake-py text --nb_chars=75 ``` *Output* ```text Complicated is than explain right. Be silently better idea hard. Break than ``` --- ### username *Command* ```sh fake-py username ``` *Output* ```text better_if_great_ldffdumuptmqtzssjbgv ``` --- ## Customisation By default, only standard (built-in) providers are available through CLI. However, you can easily expose your custom providers via the CLI as well. See the implementation below as an example. *Filename: data.py* ```python 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* ```python 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* ```python 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: ```sh python address_cli.py --help ``` ---