# fake module [https://github.com/barseghyanartur/fake.py/](https://github.com/barseghyanartur/fake.py/) ### *class* fake.AuthorshipData Bases: `object` #### first_names *: Set[str]* *= {'Andre', 'Andrew', 'Andrey', 'Anthony', 'Barry', 'Ben', 'Benjamin', 'Christian', 'Collin', 'David', 'Donald', 'Eric', 'Ezio', 'George', 'Gregor', 'Guido', 'Guilherme', 'Jack', 'Jacques', 'Jiwon', 'Ka-Ping', 'Keith', 'Kenneth', 'Lars', 'Marc-Andre', 'Martin', 'Michael', 'Mike', 'Nadeem', 'Nick', 'Paul', 'Piers', 'Skip', 'Steen', 'Steven', 'Thomas', 'Victor', 'Vinay', 'Zooko'}* #### last_names *: Set[str]* *= {'Ascher', 'Baxter', 'Bland', 'Boutsioukis', 'Dalke', 'Dart', 'Diederich', 'Dragon De Monsyne', 'Edds', 'Felt', 'Frechet', 'Gertzfield', 'Gust', 'Heimes', 'J', 'Kippes', 'Larson', 'Lauder', 'Lemburg', 'Lingl', 'Lumholt', 'Melotti', 'Montanaro', "O'Whielacronx", 'Peterson', 'Petrov', 'Polo', 'Reitz', 'Roberge', 'Sajip', 'Seo', 'Stinner', 'Stufft and individual contributors', 'Vawda', 'Warsaw', 'Winter', 'Wouters', 'Yee', 'van Rossum', 'von Loewis'}* ### *class* fake.BaseStorage(\*args, \*\*kwargs) Bases: `object` Base storage. #### *abstractmethod* abspath(filename: Any) → str Return absolute path. #### *abstractmethod* exists(filename: Any) → bool Check if file exists. #### generate_basename(prefix: str = 'tmp', length: int = 8) → str Generate a random alphanumeric sequence. #### *abstractmethod* generate_filename(extension: str, prefix: str | None = None, basename: str | None = None) → Any Generate filename. #### *abstractmethod* relpath(filename: Any) → str Return relative path. #### *abstractmethod* unlink(filename: Any) → None Delete the file. #### *abstractmethod* write_bytes(filename: Any, data: bytes) → int Write bytes. #### *abstractmethod* write_text(filename: Any, data: str, encoding: str | None = None) → int Write text. ### *class* fake.CLI(faker: [Faker](#fake.Faker) | None = None) Bases: `object` #### execute_command() → None #### setup_parser() → ArgumentParser ### *class* fake.DjangoModelFactory(\*\*kwargs) Bases: [`ModelFactory`](#fake.ModelFactory) Django ModelFactory. #### *classmethod* create(\*\*kwargs) #### *classmethod* save(instance) Save the instance. ### *class* fake.DocxGenerator(faker: [Faker](#fake.Faker)) Bases: `object` DocxGenerator - generates a DOCX file with text. Usage example: ```python from pathlib import Path from fake import FAKER Path("/tmp/example.docx").write_bytes( DocxGenerator(FAKER).create(nb_pages=100) ) ``` #### create(nb_pages: int | None = None, texts: List[str] | None = None, metadata: [MetaData](#fake.MetaData) | None = None) → bytes ### *class* fake.EpubGenerator(faker: [Faker](#fake.Faker)) Bases: `object` EpubGenerator - generates a minimal EPUB file with text pages. #### create(nb_pages: int | None = None, texts: List[str] | None = None, metadata: [MetaData](#fake.MetaData) | None = None) → bytes ### *class* fake.Factory(faker: [Faker](#fake.Faker) | None = None) Bases: `object` Factory. #### *property* faker ### *class* fake.FactoryMethod(method_name: str, faker: [Faker](#fake.Faker) | None = None, \*\*kwargs) Bases: `object` ### *class* fake.Faker(alias: str | None = None, seed: int | None = None) Bases: `object` fake.py - simplified, standalone alternative with no dependencies. --- Usage example: ```python from fake import FAKER print(FAKER.first_name()) # Random first name print(FAKER.last_name()) # Random last name print(FAKER.name()) # Random name print(FAKER.word()) # Random word from the Zen of Python print(FAKER.words(nb=3)) # List of 3 random words from Zen of Python print(FAKER.sentence()) # Random sentence (5 random words by default) print(FAKER.paragraph()) # Paragraph (5 random sentences by default) print(FAKER.paragraphs()) # 3 random paragraphs print(FAKER.text()) # Random text up to 200 characters print(FAKER.file_name()) # Random filename with '.txt' extension print(FAKER.email()) # Random email print(FAKER.url()) # Random URL print(FAKER.pyint()) # Random integer print(FAKER.pybool()) # Random boolean print(FAKER.pystr()) # Random string print(FAKER.pyfloat()) # Random float ``` --- PDF: ```python from pathlib import Path from fake import FAKER, TextPdfGenerator, GraphicPdfGenerator Path("/tmp/graphic_pdf.pdf").write_bytes( FAKER.pdf(nb_pages=100, generator=GraphicPdfGenerator) ) Path("/tmp/text_pdf.pdf").write_bytes( FAKER.pdf(nb_pages=100, generator=TextPdfGenerator) ) ``` --- Various image formats: ```python from pathlib import Path from fake import FAKER Path("/tmp/image.png").write_bytes(FAKER.png()) Path("/tmp/image.svg").write_bytes(FAKER.svg()) Path("/tmp/image.bmp").write_bytes(FAKER.bmp()) Path("/tmp/image.gif").write_bytes(FAKER.gif()) ``` Note, that all image formats accept size (default: (100, 100)) and color\`(default: \`(255, 0, 0)) arguments. #### bin(length: int = 16) → bytes Create random bytes. * **Parameters:** **length** – Length of the bytes to generate. Defaults to 16. * **Returns:** Byte content of the random bytes. * **Return type:** bytes #### bin_file(length: int = 16, storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create a BIN file. #### bmp(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255)) → bytes Create a BMP image of a specified size and colour. * **Parameters:** * **size** – Tuple of width and height of the image in pixels. Defaults to (100, 100). * **color** – Colour of the image in RGB format (tuple of three integers). Defaults to (0, 0, 255). * **Returns:** Byte content of the BMP image. * **Return type:** bytes #### bmp_file(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255), storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, extension: str | None = None) → [StringValue](#fake.StringValue) Create a BMP image file of a specified size and colour. * **Parameters:** * **size** – Tuple of width and height of the image in pixels. Defaults to (100, 100). * **color** – Colour of the image in RGB format (tuple of three integers). Defaults to (0, 0, 255). * **storage** – Storage backend to use. Defaults to None, in which case FileSystemStorage is used. * **basename** – Base name for the file. Defaults to None. * **prefix** – Prefix for the file name. Defaults to None. * **extension** – File extension. Defaults to None, in which case the image_format value is used. * **Returns:** StringValue containing the relative path of the generated BMP file. * **Return type:** [StringValue](#fake.StringValue) #### bothify(value: str, letters: str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', digits: str = '0123456789') → str Randomise string: ? is replaced with letter, # with number. Usage example: ```python from fake import FAKER FAKER.randomise_string(value="10.####/####-####") # '10.4613/4636-8596' FAKER.randomise_string(value="???? ##") # '1234 AB' ``` * **Parameters:** * **value** – Input string containing ? and # placeholders. * **letters** – String of characters to use for ? replacement. Defaults to uppercase ASCII letters. * **digits** – String of characters to use for # replacement. Defaults to digits 0-9. * **Returns:** String with ? replaced by random letters and # by random digits. * **Return type:** str #### city() → str Get a random city. * **Returns:** A random city name. * **Return type:** str #### company_email(domain_names: Tuple[str, ...] | None = None) → str Generate a random company email. * **Parameters:** **domain_names** – List of domains to randomly choose from. If not given or None, random words are used. * **Returns:** Company email. * **Return type:** str #### company_emails(nb: int = 5, domain_names: Tuple[str, ...] | None = None) → List[str] Generate a list of random company emails. * **Parameters:** * **nb** – Number of emails to generate. * **domain_names** – List of domains to randomly choose from. If not given or None, random words are used. * **Returns:** List of emails. * **Return type:** List[str] #### country() → str Get a random country. * **Returns:** A random country name. * **Return type:** str #### country_code() → str Get a random country code. * **Returns:** A random country code. * **Return type:** str #### date(start_date: str = '-7d', end_date: str = '+0d', tzinfo: timezone = datetime.timezone.utc) → date Generate random date between start_date and end_date. 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 Deprecated (still work, emit warnings): H -> h, M -> m Sign: ‘+’ for future, ‘-’ for past, or omit ‘+’ for future Special: ‘now’, ‘today’ for current datetime Shorthand notation 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 - ‘-24h’: 24 hours ago - ‘+2h’: 2 hours from now - ‘-30m’: 30 minutes ago - ‘today’ or ‘now’: current datetime ISO format examples: - ‘2000-01-01’: January 1, 2000 - ‘2025-12-31’: December 31, 2025 - ‘2000-01-01 00:00:00’: with time component Usage example: ```python FAKER.date() # random date between 7 days ago and today FAKER.date('-7d', '+0d') # same as above (explicit) FAKER.date('-30d', '-1d') # between 30 days ago and yesterday FAKER.date('+1d', '+7d') # between tomorrow and next week FAKER.date('today', '+3d') # between today and 3 days from now FAKER.date('-2w', '+1w') # within 3-week window around now FAKER.date( '-3mo', '+6mo' ) # between 3 months ago and 6 months from now FAKER.date('-1y', '+1y') # within 1 year window around now FAKER.date('2000-01-01', '2025-12-31') # ISO date range FAKER.date('-1d', '-1d') # yesterday only FAKER.date('-365d', 'today') # in the past year FAKER.date('+1d', '+30d') # in the next month ``` * **Parameters:** * **start_date** – The start date (ISO format or shorthand notation). * **end_date** – The end date (ISO format or shorthand notation). * **tzinfo** – The timezone. * **Returns:** A string representing the formatted date. * **Return type:** date #### date_time(start_date: str = '-7d', end_date: str = '+0d', tzinfo: timezone = datetime.timezone.utc) → datetime Generate a random datetime between start_date and end_date. 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 Deprecated (still work, emit warnings): H -> h, M -> m Sign: ‘+’ for future, ‘-’ for past, or omit ‘+’ for future Special: ‘now’, ‘today’ for current datetime Shorthand notation 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 > - ‘-24h’: 24 hours ago > - ‘+2h’: 2 hours from now > - ‘-30m’: 30 minutes ago > - ‘today’ or ‘now’: current datetime ISO format examples: > - ‘2000-01-01’: January 1, 2000 > - ‘2025-12-31 23:59:59’: with time component Usage example: ```python FAKER.date_time() # random datetime between 7 days ago and now FAKER.date_time('-7d', '+0d') # same as above (explicit) FAKER.date_time('-24h', '+0h') # in the past 24 hours FAKER.date_time('-30m', '+30m') # within 1-hour window around now FAKER.date_time('-2w', '+1w') # within 3-week window FAKER.date_time('-3mo', '+6mo') # within 9-month window FAKER.date_time('-1y', '+1y') # within 1 year window FAKER.date_time('today', '+1d') # between now and tomorrow FAKER.date_time('+1h', '+4h') # between 1-4 hours from now FAKER.date_time('-1d', 'now') # since yesterday FAKER.date_time('-2h', '-1h') # between 2-1 hours ago FAKER.date_time('+15m', '+45m') # in 15-45 minutes FAKER.date_time('-365d', 'today') # in the past year FAKER.date_time( '2000-01-01', '2025-12-31' ) # ISO date range ``` * **Parameters:** * **start_date** – The start datetime (ISO format or shorthand notation). Defaults to -7d. * **end_date** – The end datetime (ISO format or shorthand notation). Defaults to +0d. * **tzinfo** – The timezone. Defaults to timezone.utc. * **Returns:** A string representing the formatted datetime. * **Return type:** datetime #### dir_path(depth: int = 1) → str Generate a random dir path. * **Parameters:** **depth** – Depth to add to dir path. Defaults to 1. * **Returns:** Dir path. * **Return type:** str #### docx(nb_pages: int | None = 1, texts: List[str] | None = None, metadata: [MetaData](#fake.MetaData) | None = None) → bytes Create a DOCX document. Usage example without params: ```python FAKER.docx() ``` Usage example with params: ```python FAKER.docx(texts=("Page 1", "Page 2", "Page 3")) FAKER.docx(nb_pages=5) ``` * **Parameters:** * **nb_pages** – Number of pages to show. Defaults to 1. * **texts** – List of texts to show. Defaults to None. * **metadata** – Metadata to show. Defaults to None. * **Returns:** Byte content of the DOCX document. * **Return type:** bytes #### docx_file(nb_pages: int = 1, texts: List[str] | None = None, metadata: [MetaData](#fake.MetaData) | None = None, storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None) → [StringValue](#fake.StringValue) Create a DOCX document file. Usage example without params: ```python FAKER.docx_file() ``` Usage example with params: ```python FAKER.docx_file(nb_pages=5, prefix="custom_docx_") FAKER.docx_file(texts=["First page", "Second page", "Third page"]) ``` * **Parameters:** * **nb_pages** – Number of pages to show. Defaults to 1. * **texts** – List of texts to show. Defaults to None. * **metadata** – Metadata to show. Defaults to None. * **storage** – Storage backend to use. Defaults to None, in which case FileSystemStorage is used. * **basename** – Base name for the file. Defaults to None. * **prefix** – Prefix for the file name. Defaults to None. * **Returns:** StringValue containing the relative path of the generated DOCX file. * **Return type:** [StringValue](#fake.StringValue) #### domain_name(tlds: Tuple[str, ...] | None = None) → str Generate a random domain name. * **Parameters:** **tlds** – List of TLDs to use. If not given or None, a default list of TLDs is used. * **Returns:** Domain name. * **Return type:** str #### email(domain_names: Tuple[str, ...] | None = None) → str Generate a random email. * **Parameters:** **domain_names** – List of domains to randomly choose from. If not given or None, random words are used. * **Returns:** Email. * **Return type:** str #### emails(nb: int = 5, domain_names: Tuple[str, ...] | None = None) → List[str] Generate a list of random emails. * **Parameters:** * **nb** – Number of emails to generate. * **domain_names** – List of domains to randomly choose from. If not given or None, random words are used. * **Returns:** List of emails. * **Return type:** List[str] #### eml(options: Dict[str, Any] | None = None, content: str | None = None, subject: str | None = None, cte_type: str | None = None, policy: Policy | None = None, \*\*kwargs) → BytesValue Generate an EML file bytes. * **Parameters:** * **options** – Options (non-structured) for complex types, such as ZIP. * **content** – Email body text. * **subject** – Email subject. * **cte_type** – Content-Transfer-Encoding (CTE) type. * **policy** – Email message policy. * **\*\*kwargs** – Additional keyword arguments to pass to the function. * **Return type:** BytesValue * **Returns:** Relative path (from root directory) of the generated file or raw content of the file. Usage example. A complex case. ```python from fake import create_inner_docx_file, FAKER eml_file = FAKER.eml_file( prefix="zzz_email_", options={ "count": 5, "create_inner_file_func": create_inner_docx_file, "create_inner_file_args": { "prefix": "zzz_file_", }, } ) ``` #### eml_file(metadata: [MetaData](#fake.MetaData) | None = None, storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, options: Dict[str, Any] | None = None, content: str | None = None, subject: str | None = None, cte_type: str | None = None, policy: Policy | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create an EML file. * **Parameters:** * **metadata** – Metadata for the EML file. Defaults to None. * **storage** – Storage backend to use. Defaults to None, in which case FileSystemStorage is used. * **basename** – Base name for the file. Defaults to None. * **prefix** – Prefix for the file name. Defaults to None. * **options** – Additional options for EML generation. Defaults to None. * **content** – Content of the email. Defaults to None. * **subject** – Subject of the email. Defaults to None. * **cte_type** – Content-Transfer-Encoding type. Defaults to None. * **policy** – Email policy to use. Defaults to None. * **\*\*kwargs** – Additional keyword arguments. * **Returns:** StringValue containing the relative path of the generated EML file. * **Return type:** [StringValue](#fake.StringValue) #### epub(nb_pages: int | None = 1, texts: List[str] | None = None, metadata: [MetaData](#fake.MetaData) | None = None) → bytes Create a minimal EPUB document. Usage example without params: ```python FAKER.epub() ``` Usage example with params: ```python FAKER.epub(texts=("Page 1", "Page 2", "Page 3")) FAKER.epub(nb_pages=5) ``` * **Parameters:** * **nb_pages** – Number of pages to show. Defaults to 1. * **texts** – List of texts to show. Defaults to None. * **metadata** – Metadata to show. Defaults to None. * **Returns:** Byte content of the minimal EPUB document. * **Return type:** bytes #### epub_file(nb_pages: int = 1, texts: List[str] | None = None, metadata: [MetaData](#fake.MetaData) | None = None, storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None) → [StringValue](#fake.StringValue) Create a EPUB document file. Usage example without params: ```python FAKER.epub_file() ``` Usage example with params: ```python FAKER.epub_file(nb_pages=5, prefix="custom_epub_") FAKER.epub_file(texts=["First page", "Second page", "Third page"]) ``` * **Parameters:** * **nb_pages** – Number of pages to show. Defaults to 1. * **texts** – List of texts to show. Defaults to None. * **metadata** – Metadata to show. Defaults to None. * **storage** – Storage backend to use. Defaults to None, in which case FileSystemStorage is used. * **basename** – Base name for the file. Defaults to None. * **prefix** – Prefix for the file name. Defaults to None. * **Returns:** StringValue containing the relative path of the generated EPUB file. * **Return type:** [StringValue](#fake.StringValue) #### file_extension() → str Generate a random extension. * **Returns:** File extension. * **Return type:** str #### file_name(prefix: str | None = '', extension: str = 'txt') → str Generate a random filename. * **Parameters:** * **prefix** – Prefix to add to filename. Defaults to empty string. * **extension** – Extension to add to filename. Defaults to ‘.txt’. * **Returns:** Filename. * **Return type:** str #### file_path(prefix: str | None = '', extension: str = 'txt') → str Generate a random file path. * **Parameters:** * **prefix** – Prefix to add to file path. Defaults to empty string. * **extension** – Extension to add to file path. Defaults to ‘.txt’. * **Returns:** File path. * **Return type:** str #### first_name() → str Generate a first name. * **Returns:** First name. * **Return type:** str #### first_names(nb: int = 5) → List[str] Generate a list of first names. * **Parameters:** **nb** – Number of first names to generate. * **Returns:** List of first names. * **Return type:** List[str] #### free_email(domain_names: Tuple[str, ...] | None = None) → str Generate a random free email. * **Parameters:** **domain_names** – List of domains to randomly choose from. If not given or None, random words are used. * **Returns:** Free email. * **Return type:** str #### free_email_domain() → str Generate a random free email domain. * **Returns:** Free email domain. * **Return type:** str #### free_emails(nb: int = 5, domain_names: Tuple[str, ...] | None = None) → List[str] Generate a list of random free emails. * **Parameters:** * **nb** – Number of emails to generate. * **domain_names** – List of domains to randomly choose from. If not given or None, random words are used. * **Returns:** List of emails. * **Return type:** List[str] #### generic_file(content: bytes | str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate), extension: str, storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None) → [StringValue](#fake.StringValue) Create a generic file. * **Parameters:** * **content** – Content to write to the file. Can be bytes, string, [`StringTemplate`](#fake.StringTemplate), or [`LazyStringTemplate`](#fake.LazyStringTemplate). Templates are rendered fresh on each call before writing. * **extension** – File extension. * **storage** – Storage backend to use. Defaults to None, in which case FileSystemStorage is used. * **basename** – Base name for the file. Defaults to None. * **prefix** – Prefix for the file name. Defaults to None. * **Returns:** StringValue containing the relative path of the generated file. * **Return type:** [StringValue](#fake.StringValue) #### geo_location() → str Get a random geo-location. * **Returns:** A random geo-location name. * **Return type:** str #### *static* get_by_alias(alias: str) → [Faker](#fake.Faker) | None #### *static* get_by_uid(uid: str) → [Faker](#fake.Faker) | None #### gif(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255)) → bytes Create a GIF image of a specified size and colour. * **Parameters:** * **size** – Tuple of width and height of the image in pixels. Defaults to (100, 100). * **color** – Colour of the image in RGB format (tuple of three integers). Defaults to (0, 0, 255). * **Returns:** Byte content of the GIF image. * **Return type:** bytes #### gif_file(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255), storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, extension: str | None = None) → [StringValue](#fake.StringValue) Create a GIF image file of a specified size and colour. * **Parameters:** * **size** – Tuple of width and height of the image in pixels. Defaults to (100, 100). * **color** – Colour of the image in RGB format (tuple of three integers). Defaults to (0, 0, 255). * **storage** – Storage backend to use. Defaults to None, in which case FileSystemStorage is used. * **basename** – Base name for the file. Defaults to None. * **prefix** – Prefix for the file name. Defaults to None. * **extension** – File extension. Defaults to None, in which case the image_format value is used. * **Returns:** StringValue containing the relative path of the generated GIF file. * **Return type:** [StringValue](#fake.StringValue) #### iban(country_code: str | None = None, bank_length: int = 8, account_length: int = 10) → str Generate a random valid IBAN number. Usage example without params: ```python from fake import FAKER FAKER.iban() # 'BA36243707341183493142' ``` Usage example with params: ```python from fake import FAKER FAKER.iban(country_code="DE", bank_length=8, account_length=10) # 'DE45984597116997556579' ``` * **Parameters:** * **country_code** – Optional country code. If None, a random country code is selected. Defaults to None. * **bank_length** – Length of the bank identifier part. Defaults to 8. * **account_length** – Length of the account number part. Defaults to 10. * **Returns:** A random valid IBAN number. * **Return type:** str #### image(image_format: Literal['png', 'svg', 'bmp', 'gif', 'tif', 'ppm', 'jpg'] = 'png', size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255)) → bytes Create an image of a specified format, size and colour. * **Parameters:** * **image_format** – Format of the image. Defaults to “png”. * **size** – Tuple of width and height of the image in pixels. Defaults to (100, 100). * **color** – Colour of the image in RGB format, tuple of three integers: (0-255, 0-255, 0-255). Defaults to (128, 128, 128). * **Returns:** Byte content of the image. * **Return type:** bytes * **Raises:** **ValueError** – If the image format is not supported. #### image_url(width: int = 800, height: int = 600, service_url: str | None = None) → str Generate a random image URL. * **Parameters:** * **width** – Width of the image. Defaults to 800. * **height** – Height of the image. Defaults to 600. * **service_url** – Service URL. If not given or None, randomly picked service URL is used. * **Returns:** Image URL. * **Return type:** str #### ipv4() → str Generate a random IP v4. * **Returns:** Random IP v4. * **Return type:** str #### isbn10() → str Generate a random valid ISBN-10. * **Returns:** A random valid ISBN-10 number in the format ‘XXX-XXX-XXX-X’. * **Return type:** str #### isbn13() → str Generate a random valid ISBN-13, starting with 978 or 979. * **Returns:** A random valid ISBN-13 number in the format ‘XXX-X-XXX-XXXXX-X’. * **Return type:** str #### jpg(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (128, 128, 128)) → bytes Create a JPG image of a specified size and colour. * **Parameters:** * **size** – Tuple of width and height of the image in pixels. Defaults to (100, 100). * **color** – Colour of the image in RGB format, tuple of three integers: (0-255, 0-255, 0-255). Defaults to (128, 128, 128). * **Returns:** Byte content of the JPG image. * **Return type:** bytes #### jpg_file(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (128, 128, 128), storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, extension: str | None = None) → [StringValue](#fake.StringValue) Create a JPG image file of a specified size and colour. * **Parameters:** * **size** – Tuple of width and height of the image in pixels. Defaults to (100, 100). * **color** – Colour of the image in RGB format (tuple of three integers). Defaults to (128, 128, 128). * **storage** – Storage backend to use. Defaults to None, in which case FileSystemStorage is used. * **basename** – Base name for the file. Defaults to None. * **prefix** – Prefix for the file name. Defaults to None. * **extension** – File extension. Defaults to None, in which case the image_format value is used. * **Returns:** StringValue containing the relative path of the generated JPG file. * **Return type:** [StringValue](#fake.StringValue) #### last_name() → str Generate a last name. * **Returns:** Last name. * **Return type:** str #### last_names(nb: int = 5) → List[str] Generate a list of last names. * **Parameters:** **nb** – Number of last names to generate. * **Returns:** List of last names. * **Return type:** List[str] #### lat() → float Generate a random latitude. * **Returns:** A random latitude. * **Return type:** float #### latitude() → float Generate a random latitude. * **Returns:** A random latitude. * **Return type:** float #### latitude_longitude() → Tuple[float, float] Generate a random (latitude, longitude) pair. * **Returns:** A tuple containing a random latitude and longitude. * **Return type:** Tuple[float, float] #### latlng() → Tuple[float, float] Generate a random (latitude, longitude) pair. * **Returns:** A tuple containing a random latitude and longitude. * **Return type:** Tuple[float, float] #### latlon() → Tuple[float, float] Generate a random (latitude, longitude) pair. * **Returns:** A tuple containing a random latitude and longitude. * **Return type:** Tuple[float, float] #### lazy_string_template(template: str, wrap_chars_after: int | None = None, faker: [Faker](#fake.Faker) | None = None) → [LazyStringTemplate](#fake.LazyStringTemplate) Lazy string template. Generate a string by substituting placeholders in a template with fake data or provided values. Usage example: ```python from fake import FAKER tpl = FAKER.lazy_string_template( "Hello {first_name}! I have two words for you: {words(nb=2)}" ) print(tpl) # "Hello Mike! I have two words for you: ['idea', 'first']" print(tpl) # Hello Lars! I have two words for you: ['be', 'if'] ``` * **Parameters:** * **template** – Template string containing placeholders in curly braces (e.g., ‘{name}’, ‘{words(nb=2)}’). Placeholders should match Faker method names or be overridden by kwargs. * **wrap_chars_after** – Number of characters to wrap around. * **faker** – Faker instance to use. * **Return type:** [LazyStringTemplate](#fake.LazyStringTemplate) * **Returns:** String with placeholders replaced with correspondent fake values. #### lng() → float Generate a random longitude. * **Returns:** A random longitude. * **Return type:** float #### load_data() #### load_geo_locations() → None #### load_locales_and_country_codes() → None #### load_names() → None #### load_words() → None #### locale() → str Get a random locale. * **Returns:** A random locale. * **Return type:** str #### lon() → float Generate a random longitude. * **Returns:** A random longitude. * **Return type:** float #### longitude() → float Generate a random longitude. * **Returns:** A random longitude. * **Return type:** float #### mime_type() → str Generate a random mime type. * **Returns:** Mime type. * **Return type:** str #### name() → str Generate a name. * **Returns:** Name. * **Return type:** str #### names(nb: int = 5) → List[str] Generate a list of names. * **Parameters:** **nb** – Number of names to generate. * **Returns:** List of names. * **Return type:** List[str] #### odt(nb_pages: int | None = 1, texts: List[str] | None = None, metadata: [MetaData](#fake.MetaData) | None = None) → bytes Create a ODT document. Usage example without params: ```python FAKER.odt() ``` Usage example with params: ```python FAKER.odt(texts=("Page 1", "Page 2", "Page 3")) FAKER.odt(nb_pages=5) ``` * **Parameters:** * **nb_pages** – Number of pages to show. Defaults to 1. * **texts** – List of texts to show. Defaults to None. * **metadata** – Metadata to show. Defaults to None. * **Returns:** Byte content of the ODT document. * **Return type:** bytes #### odt_file(nb_pages: int = 1, texts: List[str] | None = None, metadata: [MetaData](#fake.MetaData) | None = None, storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None) → [StringValue](#fake.StringValue) Create a ODT document file. Usage example without params: ```python FAKER.odt_file() ``` Usage example with params: ```python FAKER.odt_file(nb_pages=5, prefix="custom_odt_") FAKER.odt_file(texts=["First page", "Second page", "Third page"]) ``` * **Parameters:** * **nb_pages** – Number of pages to show. Defaults to 1. * **texts** – List of texts to show. Defaults to None. * **metadata** – Metadata to show. Defaults to None. * **storage** – Storage backend to use. Defaults to None, in which case FileSystemStorage is used. * **basename** – Base name for the file. Defaults to None. * **prefix** – Prefix for the file name. Defaults to None. * **Returns:** StringValue containing the relative path of the generated ODT file. * **Return type:** [StringValue](#fake.StringValue) #### paragraph(nb_sentences: int = 5) → str Generate a paragraph. * **Parameters:** **nb_sentences** – Number of sentences to generate. * **Returns:** Paragraph. * **Return type:** str #### paragraphs(nb: int = 3) → List[str] Generate a list of paragraphs. * **Parameters:** **nb** – Number of paragraphs to generate. * **Returns:** List of paragraphs. * **Return type:** List[str] #### password(length: int = 10, min_lower: int = 1, min_upper: int = 1, min_digits: int = 3, min_special: int = 0) → str Generate a random password. * **Parameters:** * **length** – Total length of the password. Default is 10. * **min_lower** – Minimum number of lowercase letters. Defaults to 1. * **min_upper** – Minimum number of uppercase letters. Defaults to 1. * **min_digits** – Minimum number of digits. Default is 3. * **min_special** – Minimum number of special characters. Defaults to 0. * **Returns:** Random password string. * **Return type:** str * **Raises:** **ValueError** – if the total `length` is less than the sum of all minimum character constraints. #### pdf(nb_pages: int = 1, generator: Type[[TextPdfGenerator](#fake.TextPdfGenerator)] | Type[[GraphicPdfGenerator](#fake.GraphicPdfGenerator)] = , metadata: [MetaData](#fake.MetaData) | None = None, \*\*kwargs) → bytes Create a PDF document of a given size. * **Parameters:** * **nb_pages** – The number of pages to generate. Defaults to 1. * **generator** – The PDF generator to use. Defaults to GraphicPdfGenerator. * **metadata** – The metadata to use. Defaults to None. * **\*\*kwargs** – Additional arguments to pass to generator. * **Returns:** A bytes object representing the PDF document. * **Return type:** bytes #### pdf_file(nb_pages: int = 1, generator: Type[[TextPdfGenerator](#fake.TextPdfGenerator)] | Type[[GraphicPdfGenerator](#fake.GraphicPdfGenerator)] = , metadata: [MetaData](#fake.MetaData) | None = None, storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create a PDF file. Usage example without params: ```python FAKER.pdf_file() ``` Usage example with params: ```python FAKER.pdf_file(nb_pages=5, prefix="custom_pdf_") ``` * **Parameters:** * **nb_pages** – Number of pages in the PDF. Defaults to 1. * **generator** – PDF generator class to use. Defaults to GraphicPdfGenerator. * **metadata** – Metadata for the PDF. Defaults to None. * **storage** – Storage backend to use. Defaults to None, in which case FileSystemStorage is used. * **basename** – Base name for the file. Can also be a [`StringTemplate`](#fake.StringTemplate) or [`LazyStringTemplate`](#fake.LazyStringTemplate). Defaults to None. * **prefix** – Prefix for the file name. Can also be a [`StringTemplate`](#fake.StringTemplate) or [`LazyStringTemplate`](#fake.LazyStringTemplate). Defaults to None. * **\*\*kwargs** – Additional keyword arguments to pass to the PDF generator. * **Returns:** StringValue containing the relative path of the generated PDF file. * **Return type:** [StringValue](#fake.StringValue) #### png(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255)) → bytes Create a PNG image of a specified size and colour. * **Parameters:** * **size** – Tuple of width and height of the image in pixels. Defaults to (100, 100). * **color** – Colour of the image in RGB format (tuple of three integers). Defaults to (0, 0, 255). * **Returns:** Byte content of the PNG image. * **Return type:** bytes #### png_file(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255), storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, extension: str | None = None) → [StringValue](#fake.StringValue) Create a PNG image file of a specified size and colour. * **Parameters:** * **size** – Tuple of width and height of the image in pixels. Defaults to (100, 100). * **color** – Colour of the image in RGB format (tuple of three integers). Defaults to (0, 0, 255). * **storage** – Storage backend to use. Defaults to None, in which case FileSystemStorage is used. * **basename** – Base name for the file. Defaults to None. * **prefix** – Prefix for the file name. Defaults to None. * **extension** – File extension. Defaults to None, in which case the image_format value is used. * **Returns:** StringValue containing the relative path of the generated PNG file. * **Return type:** [StringValue](#fake.StringValue) #### ppm(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255)) → bytes Create a PPM image of a specified size and colour. * **Parameters:** * **size** – Tuple of width and height of the image in pixels. Defaults to (100, 100). * **color** – Colour of the image in RGB format, tuple of three integers: (0-255, 0-255, 0-255). Defaults to (0, 0, 255). * **Returns:** Byte content of the PPM image. * **Return type:** bytes #### ppm_file(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255), storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, extension: str | None = None) → [StringValue](#fake.StringValue) Create a PPM image file of a specified size and colour. * **Parameters:** * **size** – Tuple of width and height of the image in pixels. Defaults to (100, 100). * **color** – Colour of the image in RGB format (tuple of three integers). Defaults to (0, 0, 255). * **storage** – Storage backend to use. Defaults to None, in which case FileSystemStorage is used. * **basename** – Base name for the file. Defaults to None. * **prefix** – Prefix for the file name. Defaults to None. * **extension** – File extension. Defaults to None, in which case the image_format value is used. * **Returns:** StringValue containing the relative path of the generated PPM file. * **Return type:** [StringValue](#fake.StringValue) #### pybool() → bool Generate a random boolean. * **Returns:** Random boolean. * **Return type:** bool #### pydecimal(left_digits: int = 5, right_digits: int = 2, positive: bool = True) → Decimal Generate a random Decimal number. * **Parameters:** * **left_digits** – Number of digits to the left of the decimal point. * **right_digits** – Number of digits to the right of the decimal point. * **positive** – If True, the number will be positive, otherwise it can be negative. * **Returns:** Random Decimal number. * **Return type:** Decimal * **Raises:** **ValueError** – if `left_digits` or `right_digits` is less than 0. #### pyfloat(min_value: float = 0.0, max_value: float = 10.0) → float Generate a random float number. * **Parameters:** * **min_value** – Min value of the generated number. Defaults to 0. * **max_value** – Max value of the generated number. Defaults to 10. * **Returns:** Random float number. * **Return type:** float #### pyint(min_value: int = 0, max_value: int = 9999) → int Generate a random integer. * **Parameters:** * **min_value** – Min value of the generated integer. Defaults to 0. * **max_value** – Max value of the generated integer. Defaults to 9999. * **Returns:** Random integer within the range [min_value, max_value]. * **Return type:** int #### pystr(nb_chars: int = 20) → str Generate a random string. * **Parameters:** **nb_chars** – Number of characters to generate. * **Returns:** Random string. * **Return type:** str #### random_choice(elements: Sequence[T]) → T Random choice: pick a single element from the given list. Example usage: ```python from fake import FAKER FAKER.random_choice(("Art", "Photography", "Generative AI")) # 'Photography' ``` * **Parameters:** **elements** – A list or tuple of elements to choose from. * **Returns:** A randomly selected element from the input list. * **Return type:** T #### random_element(elements: Sequence[T]) → T Random choice: pick a single element from the given list. Example usage: ```python from fake import FAKER FAKER.random_choice(("Art", "Photography", "Generative AI")) # 'Photography' ``` * **Parameters:** **elements** – A list or tuple of elements to choose from. * **Returns:** A randomly selected element from the input list. * **Return type:** T #### random_elements(elements: Sequence[T], length: int) → List[T] Random sample: pick random length elements from the given list. Example usage: ```python from fake import FAKER FAKER.random_sample(("Art", "Photography", "Generative AI"), 2) # ['Photography', 'Art'] ``` #### random_sample(elements: Sequence[T], length: int) → List[T] Random sample: pick random length elements from the given list. Example usage: ```python from fake import FAKER FAKER.random_sample(("Art", "Photography", "Generative AI"), 2) # ['Photography', 'Art'] ``` #### randomise_string(value: str, letters: str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', digits: str = '0123456789') → str Randomise string: ? is replaced with letter, # with number. Usage example: ```python from fake import FAKER FAKER.randomise_string(value="10.####/####-####") # '10.4613/4636-8596' FAKER.randomise_string(value="???? ##") # '1234 AB' ``` * **Parameters:** * **value** – Input string containing ? and # placeholders. * **letters** – String of characters to use for ? replacement. Defaults to uppercase ASCII letters. * **digits** – String of characters to use for # replacement. Defaults to digits 0-9. * **Returns:** String with ? replaced by random letters and # by random digits. * **Return type:** str #### randomize_string(value: str, letters: str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', digits: str = '0123456789') → str Randomise string: ? is replaced with letter, # with number. Usage example: ```python from fake import FAKER FAKER.randomise_string(value="10.####/####-####") # '10.4613/4636-8596' FAKER.randomise_string(value="???? ##") # '1234 AB' ``` * **Parameters:** * **value** – Input string containing ? and # placeholders. * **letters** – String of characters to use for ? replacement. Defaults to uppercase ASCII letters. * **digits** – String of characters to use for # replacement. Defaults to digits 0-9. * **Returns:** String with ? replaced by random letters and # by random digits. * **Return type:** str #### rtf(nb_pages: int | None = 1, texts: List[str] | None = None, metadata: [MetaData](#fake.MetaData) | None = None) → bytes Create an RTF document. Usage example without params: ```python FAKER.rtf() ``` Usage example with params: ```python FAKER.rtf(texts=("Page 1", "Page 2", "Page 3")) FAKER.rtf(nb_pages=5) ``` * **Parameters:** * **nb_pages** – Number of pages to show. Defaults to 1. * **texts** – List of texts to show. Defaults to None. * **metadata** – Metadata to show. Defaults to None. * **Returns:** Byte content of the RTF document. * **Return type:** bytes #### rtf_file(nb_pages: int = 1, texts: List[str] | None = None, metadata: [MetaData](#fake.MetaData) | None = None, storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None) → [StringValue](#fake.StringValue) Create an RTF document file. Usage example without params: ```python FAKER.rtf_file() ``` Usage example with params: ```python FAKER.rtf_file(nb_pages=5, prefix="custom_rtf_") FAKER.rtf_file(texts=["First page", "Second page", "Third page"]) ``` * **Parameters:** * **nb_pages** – Number of pages to show. Defaults to 1. * **texts** – List of texts to show. Defaults to None. * **metadata** – Metadata to show. Defaults to None. * **storage** – Storage backend to use. Defaults to None, in which case FileSystemStorage is used. * **basename** – Base name for the file. Defaults to None. * **prefix** – Prefix for the file name. Defaults to None. * **Returns:** StringValue containing the relative path of the generated RTF file. * **Return type:** [StringValue](#fake.StringValue) #### seed(seed: int | None) → None Reset the RNG state with a new seed. #### sentence(nb_words: int = 5, suffix: str = '.') → str Generate a sentence. * **Parameters:** * **nb_words** – Number of words to generate. * **suffix** – Suffix to add to sentence. Defaults to .. * **Returns:** Sentence. * **Return type:** str #### sentences(nb: int = 3) → List[str] Generate a list of sentences. * **Parameters:** **nb** – Number of sentences to generate. * **Returns:** List of sentences. * **Return type:** List[str] #### slug() → str Generate a slug. * **Returns:** Slug. * **Return type:** str #### slugs(nb: int = 5) → List[str] Generate a list of slugs. * **Parameters:** **nb** – Number of slugs to generate. * **Returns:** List of slugs. * **Return type:** List[str] #### string_template(template: str, wrap_chars_after: int | None = None, faker: [Faker](#fake.Faker) | None = None) → str String template. Generate a string by substituting placeholders in a template with fake data or provided values. Usage example: ```python from fake import FAKER FAKER.string_template( "Hello {first_name}! I have two words for you: {words(nb=2)}" ) # "Hello Mike! I have two words for you: ['idea', 'first']" ``` * **Parameters:** * **template** – Template string containing placeholders in curly braces (e.g., ‘{name}’, ‘{words(nb=2)}’). Placeholders should match Faker method names or be overridden by kwargs. * **wrap_chars_after** – Number of characters to wrap around. * **faker** – Faker instance to use. * **Return type:** str * **Returns:** String with placeholders replaced with correspondent fake values. #### svg(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255)) → bytes Create an SVG image of a specified size and colour. * **Parameters:** * **size** – Tuple of width and height of the image in pixels. Defaults to (100, 100). * **color** – Colour of the image in RGB format (tuple of three integers). Defaults to (0, 0, 255). * **Returns:** Byte content of the SVG image. * **Return type:** bytes #### svg_file(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255), storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, extension: str | None = None) → [StringValue](#fake.StringValue) Create an SVG image file of a specified size and colour. * **Parameters:** * **size** – Tuple of width and height of the image in pixels. Defaults to (100, 100). * **color** – Colour of the image in RGB format (tuple of three integers). Defaults to (0, 0, 255). * **storage** – Storage backend to use. Defaults to None, in which case FileSystemStorage is used. * **basename** – Base name for the file. Defaults to None. * **prefix** – Prefix for the file name. Defaults to None. * **extension** – File extension. Defaults to None, in which case the image_format value is used. * **Returns:** StringValue containing the relative path of the generated SVG file. * **Return type:** [StringValue](#fake.StringValue) #### tar(options: Dict[str, Any] | None = None, compression: Literal['gz', 'bz2', 'xz'] | None = None, \*\*kwargs) → BytesValue Generate a TAR archive file as bytes. * **Parameters:** * **options** – Options (non-structured) for complex types, such as ZIP. * **compression** – Desired compression. Can be None or gz, bz2 or xz. * **\*\*kwargs** – Additional keyword arguments to pass to the function. * **Return type:** BytesValue * **Returns:** Relative path (from root directory) of the generated file or raw content of the file. Usage example. Complex case. ```python from fake import create_inner_txt_file, FAKER tar_file = FAKER.tar( prefix="ttt_archive_", options={ "count": 5, "create_inner_file_func": create_inner_txt_file, "create_inner_file_args": { "prefix": "ttt_file_", }, "directory": "ttt", }, ) ``` #### tar_file(metadata: [MetaData](#fake.MetaData) | None = None, storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, options: Dict[str, Any] | None = None, compression: Literal['gz', 'bz2', 'xz'] | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create a TAR archive file. #### text(nb_chars: int = 200, suffix: str = '.', allow_overflow: bool = False) → str Generate a text. * **Parameters:** * **nb_chars** – Number of characters to generate. * **suffix** – Suffix to add to text. Defaults to .. * **allow_overflow** – Allow overflow. Defaults to False. * **Returns:** Text. * **Return type:** str #### text_pdf(nb_pages: int = 1, generator: Type[[TextPdfGenerator](#fake.TextPdfGenerator)] = , metadata: [MetaData](#fake.MetaData) | None = None, \*\*kwargs) → bytes Create a PDF document of a given size. * **Parameters:** * **nb_pages** – The number of pages to generate. Defaults to 1. * **generator** – The PDF generator to use. Defaults to TextPdfGenerator. * **metadata** – The metadata to use. Defaults to None. * **\*\*kwargs** – Additional arguments to pass to generator. * **Returns:** A bytes object representing the PDF document. * **Return type:** bytes #### text_pdf_file(nb_pages: int = 1, generator: Type[[TextPdfGenerator](#fake.TextPdfGenerator)] = , metadata: [MetaData](#fake.MetaData) | None = None, storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create a text PDF file. Usage example without params: ```python FAKER.text_pdf_file() ``` Usage example with params: ```python FAKER.text_pdf_file(nb_pages=5, prefix="custom_text_pdf_") ``` * **Parameters:** * **nb_pages** – Number of pages in the PDF. Defaults to 1. * **generator** – PDF generator class to use. Defaults to TextPdfGenerator. * **metadata** – Metadata for the PDF. Defaults to None. * **storage** – Storage backend to use. Defaults to None, in which case FileSystemStorage is used. * **basename** – Base name for the file. Defaults to None. * **prefix** – Prefix for the file name. Defaults to None. * **\*\*kwargs** – Additional keyword arguments to pass to the PDF generator. * **Returns:** StringValue containing the relative path of the generated PDF file. * **Return type:** [StringValue](#fake.StringValue) #### texts(nb: int = 3) → List[str] Generate a list of texts. * **Parameters:** **nb** – Number of texts to generate. * **Returns:** List of texts. * **Return type:** List[str] #### tif(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255)) → bytes Create a TIF image of a specified size and colour. * **Parameters:** * **size** – Tuple of width and height of the image in pixels. Defaults to (100, 100). * **color** – Colour of the image in RGB format (tuple of three integers). Defaults to (0, 0, 255). * **Returns:** Byte content of the TIF image. * **Return type:** bytes #### tif_file(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255), storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, extension: str | None = None) → [StringValue](#fake.StringValue) Create a TIF image file of a specified size and colour. * **Parameters:** * **size** – Tuple of width and height of the image in pixels. Defaults to (100, 100). * **color** – Colour of the image in RGB format (tuple of three integers). Defaults to (0, 0, 255). * **storage** – Storage backend to use. Defaults to None, in which case FileSystemStorage is used. * **basename** – Base name for the file. Defaults to None. * **prefix** – Prefix for the file name. Defaults to None. * **extension** – File extension. Defaults to None, in which case the image_format value is used. * **Returns:** StringValue containing the relative path of the generated TIF file. * **Return type:** [StringValue](#fake.StringValue) #### time(fmt: str = '%H:%M:%S') → str Generate a random time string formatted according to fmt. * **Parameters:** **fmt** – The format to use. Defaults to %H:%M:%S. * **Returns:** A random time string formatted according to fmt. * **Return type:** str #### tld(tlds: Tuple[str, ...] | None = None) → str Generate a random TLD. * **Parameters:** **tlds** – List of TLDs to use. If not given or None, a default list of TLDs is used. * **Returns:** TLD. * **Return type:** str #### txt_file(nb_chars: int | None = 200, storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, text: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None) → [StringValue](#fake.StringValue) Create a text document file. * **Parameters:** * **nb_chars** – Number of characters in the text file. Defaults to 200. * **storage** – Storage backend to use. Defaults to None, in which case FileSystemStorage is used. * **basename** – Base name for the file. Defaults to None. * **prefix** – Prefix for the file name. Defaults to None. * **text** – Text content to write to the file. If None, random text will be generated. Can also be a [`StringTemplate`](#fake.StringTemplate) or [`LazyStringTemplate`](#fake.LazyStringTemplate). Defaults to None. * **Returns:** StringValue containing the relative path of the generated text file. * **Return type:** [StringValue](#fake.StringValue) #### url(protocols: Tuple[str, ...] | None = None, tlds: Tuple[str, ...] | None = None, suffixes: Tuple[str, ...] | None = None) → str Generate a random URL. Example without params: ```python FAKER.url() ``` Example with params: ```python FAKER.url( protocols=("https",), tlds=("com",), suffixes=(".py",), ) ``` * **Parameters:** * **protocols** – List of protocols to use. If not given or None, default protocols are used. * **tlds** – List of TLDs to use. If not given or None, default TLDs are used. * **suffixes** – List of suffixes to use. If not given or None, default suffixes are used. * **Returns:** URL. * **Return type:** str #### username() → str Generate a username. * **Returns:** Username. * **Return type:** str #### usernames(nb: int = 5) → List[str] Generate a list of usernames. * **Parameters:** **nb** – Number of usernames to generate. * **Returns:** List of usernames. * **Return type:** List[str] #### uuid() → UUID Generate a UUID. * **Returns:** UUID * **Return type:** UUID #### uuids(nb: int = 5) → List[UUID] Generate a list of UUIDs. * **Parameters:** **nb** – Number of UUIDs to generate. * **Returns:** List of UUIDs * **Return type:** List[UUID] #### wav(frequency: int = 440, duration: int = 1, volume: float | int = 0.5, sample_rate: int = 44100) → bytes Create a WAV audio. * **Parameters:** * **frequency** – The frequency of the tone in Hz. Defaults to 440. * **duration** – Duration of the tone in seconds. Defaults to 1. * **volume** – Volume of the tone, scale between 0.0 and 1.0. Defaults to 0.5. * **sample_rate** – Sampling rate in Hz. Defaults to 44100. * **Returns:** Byte content of the WAV audio. * **Return type:** bytes #### wav_file(frequency: int = 440, duration: int = 1, volume: float | int = 0.5, sample_rate: int = 44100, storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None) → [StringValue](#fake.StringValue) Create a WAV audio file. * **Parameters:** * **frequency** – Frequency of the audio in Hertz. Defaults to 440. * **duration** – Duration of the audio in seconds. Defaults to 1. * **volume** – Volume of the audio (0.0 to 1.0). Defaults to 0.5. * **sample_rate** – Sample rate of the audio in samples per second. Defaults to 44100. * **storage** – Storage backend to use. Defaults to None, in which case FileSystemStorage is used. * **basename** – Base name for the file. Defaults to None. * **prefix** – Prefix for the file name. Defaults to None. * **Returns:** StringValue containing the relative path of the generated WAV file. * **Return type:** [StringValue](#fake.StringValue) #### word() → str Generate a word. * **Returns:** Word. * **Return type:** str #### words(nb: int = 5) → List[str] Generate a list of words. * **Parameters:** **nb** – Number of words to generate. * **Returns:** List of words. * **Return type:** List[str] #### year(start_year: int = 1900, end_year: int = 2100) → int Generate a random year between start_year and end_year (inclusive). * **Parameters:** * **start_year** – The lower bound for the random year. Defaults to 1900. * **end_year** – The upper bound for the random year. Defaults to 2100. * **Returns:** A random year as an integer. * **Return type:** int #### zip(options: Dict[str, Any] | None = None, \*\*kwargs) Create a ZIP archive file as bytes. Usage example. A complex case. ```python from fake import create_inner_txt_file, FAKER zip_file = FAKER.zip( options={ "count": 5, "create_inner_file_func": create_inner_txt_file, "create_inner_file_args": { "prefix": "zzz_file_", }, "directory": "zzz", }, ) ``` #### zip_file(metadata: [MetaData](#fake.MetaData) | None = None, storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, options: Dict[str, Any] | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create a ZIP archive file. Usage example. A simple case. ```python from fake import FAKER zip_archive = FAKER.zip() ``` Usage example. A complex case. ```python from fake import create_inner_txt_file, FAKER zip_file = FAKER.zip( prefix="zzz_archive_", options={ "count": 5, "create_inner_file_func": create_inner_txt_file, "create_inner_file_args": { "prefix": "zzz_file_", }, "directory": "zzz", }, ) ``` ### *class* fake.FileRegistry Bases: `object` Stores list StringValue instances. ```python from fake import FAKER, FILE_REGISTRY txt_file_1 = FAKER.txt_file() txt_file_2 = FAKER.txt_file() ... txt_file_n = FAKER.txt_file() # The FileRegistry._registry would then contain this: { txt_file_1, txt_file_2, ..., txt_file_n, } # Clean up created files as follows: FILE_REGISTRY.clean_up() ``` #### add(string_value: [StringValue](#fake.StringValue)) → None #### clean_up() → None #### remove(string_value: [StringValue](#fake.StringValue) | str) → bool #### search(value: str) → [StringValue](#fake.StringValue) | None ### *class* fake.FileSystemStorage(root_path: str | Path | None = '/tmp', rel_path: str | None = 'tmp', \*args, \*\*kwargs) Bases: [`BaseStorage`](#fake.BaseStorage) File storage class using pathlib for path handling. Usage example: ```python from fake import FAKER, FileSystemStorage storage = FileSystemStorage() docx_file = storage.generate_filename(prefix="zzz_", extension="docx") storage.write_bytes(docx_file, FAKER.docx()) ``` Initialization with params: ```python from fake import FAKER, FileSystemStorage storage = FileSystemStorage() docx_file = FAKER.docx_file(storage=storage) ``` #### abspath(filename: str) → str Return absolute path. #### exists(filename: str) → bool Check if file exists. #### generate_filename(extension: str, prefix: str | None = None, basename: str | None = None) → str Generate filename. #### relpath(filename: str) → str Return relative path. #### unlink(filename: str) → None Delete the file. #### write_bytes(filename: str, data: bytes) → int Write bytes. #### write_text(filename: str, data: str, encoding: str | None = None) → int Write text. ### *class* fake.GraphicPdfGenerator(faker: [Faker](#fake.Faker)) Bases: `object` Graphic PDF generatr. Usage example: ```python from pathlib import Path from fake import FAKER, GraphicPdfGenerator Path("/tmp/graphic_example.pdf").write_bytes( FAKER.pdf(nb_pages=100, generator=GraphicPdfGenerator) ) ``` #### create(nb_pages: int = 1, image_size: Tuple[int, int] = (100, 100), image_color: Tuple[int, int, int] = (255, 0, 0), \*\*kwargs) → bytes #### image_color *: Tuple[int, int, int]* #### image_size *: Tuple[int, int]* #### nb_pages *: int* ### *class* fake.LazyAttribute(func) Bases: `object` ### *class* fake.LazyFunction(func) Bases: `object` ### *class* fake.LazyStringTemplate(template: str, wrap_chars_after: int | None = None, faker: [Faker](#fake.Faker) | None = None) Bases: `StringTemplateMixin` LazyStringTemplate. Usage example: ```python from fake import FAKER, LazyStringTemplate template = ''' {date(start_date='-7d')}, Dear {name}, {sentence(nb_words=25)} Best regards, {name} ''' string_template = LazyStringTemplate(template) print(string_template.render()) ``` Integration with providers: ```python from fake import FAKER, LazyStringTemplate template = ''' {date(start_date='-7d')}, Dear {name}, {sentence(nb_words=25)} Best regards, {name} ''' string_template = LazyStringTemplate(template) FAKER.docx_file(texts=[str(string_template)]) FAKER.eml_file(content=str(string_template)) FAKER.txt_file(text=str(string_template)) FAKER.text_pdf_file(texts=[str(string_template) for _ in range(10)]) ``` ### *class* fake.MetaData Bases: `object` #### add_content(content: str | List[str]) → None #### content *: str | None* ### *class* fake.ModelFactory(\*\*kwargs) Bases: `object` ModelFactory. #### *class* Meta Bases: `object` #### get_or_create *= ('id',)* #### *classmethod* create(\*\*kwargs) #### *classmethod* create_batch(count, \*\*kwargs) #### *classmethod* save(instance) Save the instance. ### *class* fake.OdtGenerator(faker: [Faker](#fake.Faker)) Bases: `object` OdtGenerator - generates an ODT file with text. Usage example: ```python from pathlib import Path from fake import FAKER Path("/tmp/example.odt").write_bytes( OdtGenerator(FAKER).create(nb_pages=100) ) ``` #### create(nb_pages: int | None = None, texts: List[str] | None = None, metadata: [MetaData](#fake.MetaData) | None = None) → bytes ### *class* fake.PostSave(func, \*args, \*\*kwargs) Bases: `object` #### execute(instance) ### *class* fake.PreInit(func, \*args, \*\*kwargs) Bases: `object` #### execute(data: Dict[str, Any]) → None ### *class* fake.PreSave(func, \*args, \*\*kwargs) Bases: `object` #### execute(instance) ### *class* fake.PydanticModelFactory(\*\*kwargs) Bases: [`ModelFactory`](#fake.ModelFactory) Pydantic ModelFactory. ### *class* fake.RtfGenerator(faker: [Faker](#fake.Faker)) Bases: `object` RtfGenerator - generates an RTF file with text. Usage example: ```python from pathlib import Path from fake import FAKER Path("/tmp/example.rtf").write_bytes( RtfGenerator(FAKER).create(nb_pages=5) ) ``` #### create(nb_pages: int | None = None, texts: List[str] | None = None, metadata: [MetaData](#fake.MetaData) | None = None) → bytes ### *class* fake.SQLAlchemyModelFactory(\*\*kwargs) Bases: [`ModelFactory`](#fake.ModelFactory) SQLAlchemy ModelFactory. #### *classmethod* create(\*\*kwargs) #### *classmethod* save(instance) Save the instance. ### *class* fake.StringTemplate(template: str, wrap_chars_after: int | None = None, faker: [Faker](#fake.Faker) | None = None) Bases: `str`, `StringTemplateMixin` LazyStringTemplate. Usage example: ```python from fake import FAKER, StringTemplate template = ''' {date(start_date='-7d')}, Dear {name}, {sentence(nb_words=25)} Best regards, {name} ''' string_template = StringTemplate(template) print(string_template) ``` Integration with providers: ```python from fake import FAKER, StringTemplate template = ''' {date(start_date='-7d')}, Dear {name}, {sentence(nb_words=25)} Best regards, {name} ''' string_template = StringTemplate(template) FAKER.docx_file( texts=[StringTemplate(template) for _ in range(10)] ) FAKER.eml_file(content=string_template) FAKER.txt_file(text=string_template) FAKER.text_pdf_file( texts=[StringTemplate(template) for _ in range(10)] ) ``` ### *class* fake.StringValue(value: str, \*args, \*\*kwargs) Bases: `str` #### data *: Dict[str, Any]* ### *class* fake.SubFactory(factory_class, \*\*kwargs) Bases: `object` ### *class* fake.TestCLI(methodName='runTest') Bases: `TestCase` #### setUp() Hook method for setting up the test fixture before exercising it. #### test_date_provider() #### test_date_provider_with_args() #### test_docx_file_provider() #### test_generic_file_provider() #### test_no_command() #### test_provider_list() #### test_pyint_provider() ### *class* fake.TestFaker(methodName='runTest') Bases: `TestCase` #### *classmethod* is_valid_email(email: str) → bool #### setUp() → None Hook method for setting up the test fixture before exercising it. #### tearDown() Hook method for deconstructing the test fixture after testing it. #### test_authorship_data() Test AuthorshipData. #### test_bin() → None #### test_bin_file() → None #### test_bmp() → None #### test_bmp_file() → None #### test_city() #### test_clean_up_exceptions() #### test_company_email() → None #### test_company_email_custom_domain_names() → None #### test_company_emails() → None #### test_country() #### test_country_code() #### test_create_inner_bmp_file() #### test_create_inner_docx_file() #### test_create_inner_eml_file() #### test_create_inner_eml_file_with_options() #### test_create_inner_eml_file_with_options_list_create() #### test_create_inner_epub_file() #### test_create_inner_generic_file_with_lazy_string_template_and_dir_path() create_inner_generic_file with LazyStringTemplate content and dir_path produces independently rendered files at the correct in-archive path. #### test_create_inner_gif_file() #### test_create_inner_jpg_file() #### test_create_inner_odt_file() #### test_create_inner_pdf_file() #### test_create_inner_png_file() #### test_create_inner_ppm_file() #### test_create_inner_rtf_file() #### test_create_inner_svg_file() #### test_create_inner_tar_file() #### test_create_inner_tar_file_with_options() #### test_create_inner_tar_file_with_options_list_create() #### test_create_inner_text_pdf_file() #### test_create_inner_tif_file() #### test_create_inner_txt_file() #### test_create_inner_wav_file() #### test_create_inner_zip_file() #### test_create_inner_zip_file_with_options() #### test_create_inner_zip_file_with_options_list_create() #### test_date() → None #### test_date_deprecated_units() → None Test deprecated H and M units still work but emit warnings. #### test_date_iso_range() → None Test ISO date format support. #### test_date_relative_months() → None Test months unit. #### test_date_relative_weeks() → None Test weeks unit. #### test_date_relative_years() → None Test years unit. #### test_date_time() → None #### test_date_time_iso_range() → None Test ISO datetime format with time component. #### test_date_time_relative_months() → None Test months unit for datetime. #### test_date_time_relative_weeks() → None Test weeks unit for datetime. #### test_date_time_relative_years() → None Test years unit for datetime. #### test_dir_path() → None #### test_docx() → None #### test_docx_file() → None #### test_domain_name_custom_domain_names() → None #### test_domain_name_with_defaults() → None #### test_email() → None #### test_email_custom_domain_names() → None #### test_emails() → None #### test_eml() → None #### test_eml_file() → None #### test_epub() → None #### test_factory_method() → None Test FactoryMethod. #### test_factory_methods() → None #### test_faker_init() → None #### test_file_extension() → None #### test_file_name() → None #### test_file_path() → None #### test_first_name() → None #### test_first_names() → None #### test_free_email() → None #### test_free_email_domain() #### test_free_emails() → None #### test_generic_file() → None #### test_generic_file_accepts_lazy_string_template() generic_file renders a LazyStringTemplate fresh on each call. #### test_generic_file_accepts_string_template() generic_file renders a StringTemplate before writing. #### test_generic_file_basename_absolute_path() generic_file rejects absolute path in basename. #### test_generic_file_basename_invalid_chars() generic_file rejects invalid characters in basename. #### test_generic_file_basename_lazy_string_template() generic_file accepts LazyStringTemplate as basename. #### test_generic_file_basename_path_traversal() generic_file rejects path traversal in basename. #### test_generic_file_basename_string_template() generic_file accepts StringTemplate as basename. #### test_generic_file_prefix_absolute_path() generic_file rejects absolute path in prefix. #### test_generic_file_prefix_invalid_chars() generic_file rejects invalid characters in prefix. #### test_generic_file_prefix_lazy_string_template() generic_file accepts LazyStringTemplate as prefix. #### test_generic_file_prefix_path_traversal() generic_file rejects path traversal in prefix. #### test_generic_file_prefix_string_template() generic_file accepts StringTemplate as prefix. #### test_geo_location() #### test_get_by_alias() → None #### test_get_by_uid() → None #### test_gif() → None #### test_gif_file() → None #### test_graphic_pdf() → None #### test_iban() #### test_image() #### test_image_url() → None #### test_ipv4() → None #### test_isbn10() #### test_isbn13() #### test_isbn13_checksum() #### test_jpg() → None #### test_jpg_file() → None #### test_last_name() → None #### test_last_names() → None #### test_latitude() Test that the latitude function returns a valid latitude. #### test_latitude_longitude() Test that the latlng returns a valid (latitude, longitude) pair. #### test_lazy_string_template() → None #### test_locale() #### test_longitude() Test that the longitude function returns a valid longitude. #### test_metadata() → None Test MetaData. #### test_mime_type() → None #### test_name() → None #### test_names() → None #### test_odt() → None #### test_odt_file() → None #### test_paragraph() → None #### test_paragraphs() → None #### test_parse_date_string() → None #### test_password() Test password. #### test_pdf_file() → None #### test_pdf_file_basename_string_template() pdf_file accepts StringTemplate as basename. #### test_pdf_file_basename_validation() pdf_file validates basename. #### test_pdf_file_prefix_lazy_string_template() pdf_file accepts LazyStringTemplate as prefix. #### test_png() → None #### test_png_file() → None #### test_ppm() → None #### test_ppm_file() → None #### test_pybool() → None #### test_pydecimal() #### test_pyfloat() → None #### test_pyint() → None #### test_pystr() → None #### test_random_choice() → None #### test_random_sample() → None #### test_randomise_string() #### test_registry_integration() → None Test add. #### test_remove_by_string_not_found() #### test_remove_exceptions() #### test_rtf() → None #### test_seed() → None #### test_sentence() → None #### test_sentences() → None #### test_slug() → None #### test_slugs() → None #### test_storage() → None #### test_storage_integration() → None #### test_string_template() → None #### test_sub_factory() → None Test FACTORY and SubFactory. #### test_svg() → None #### test_svg_file() → None #### test_tar() → None #### test_tar_dir_path_literal() Same guarantee holds for tar(). #### test_tar_file() → None #### test_text() → None #### test_text_pdf() → None #### test_text_pdf_file() → None #### test_texts() → None #### test_tif() → None #### test_tif_file() → None #### test_time() → None #### test_tld_with_custom_tlds() → None #### test_tld_with_defaults() → None #### test_txt_file() → None #### test_txt_file_basename_string_template() txt_file accepts StringTemplate as basename. #### test_txt_file_prefix_lazy_string_template() txt_file accepts LazyStringTemplate as prefix. #### test_txt_file_prefix_validation() txt_file validates prefix. #### test_url() → None #### test_username() → None #### test_usernames() → None #### test_uuid() → None #### test_uuids() → None #### test_wav() → None #### test_wav_file() → None #### test_word() → None #### test_words() → None #### test_year() → None Test that the default year is between 1900 and 2100. #### test_zip() → None #### test_zip_dir_path_literal() dir_path as a literal string places the file at that subpath. #### test_zip_dir_path_sanitization() dir_path with unsafe paths like .., absolute paths, drive letters. #### test_zip_dir_path_template() dir_path as a string_template expression is resolved before use. #### test_zip_file() → None #### test_zip_without_dir_path_unaffected() Existing callers that omit dir_path behave exactly as before. ### *class* fake.TestLazyStringTemplate(methodName='runTest') Bases: `TestCase` #### setUp() Hook method for setting up the test fixture before exercising it. #### test_argument_parsing_error_raises_value_error() #### test_complex_argument_parsing() #### test_escape_braces() #### test_method_call_error_raises_value_error() #### test_missing_method_raises_attribute_error() #### test_multiple_placeholders() #### test_nested_placeholders() #### test_no_placeholders() #### test_no_wrapping_when_not_specified() #### test_placeholder_with_arguments() #### test_placeholder_with_boolean_arguments() #### test_placeholder_with_empty_arguments() #### test_placeholder_with_no_parentheses() #### test_placeholder_with_numeric_method_name() #### test_placeholder_with_spaces_in_arguments() #### test_placeholder_with_underscores_in_method_name() #### test_repr_method() #### test_simple_placeholder_replacement() #### test_str_method() #### test_wrapping_functionality() ### *class* fake.TestOrganiseProviders(methodName='runTest') Bases: `TestCase` #### setUp() Hook method for setting up the test fixture before exercising it. #### test_organise_providers_category_sorting() #### test_organise_providers_empty() #### test_organise_providers_multiple_providers() #### test_organise_providers_multiple_tags() #### test_organise_providers_single_tag() #### test_organise_providers_sorting() ### *class* fake.TestScript(methodName='runTest') Bases: `TestCase` #### test_main() ### *class* fake.TestSlugify(methodName='runTest') Bases: `TestCase` #### test_slugify_empty_string() Test slugify with an empty string. #### test_slugify_mixed_characters() Test slugify with a mix of alphanumeric and special characters. #### test_slugify_non_english_characters() Test slugify with non-English characters. #### test_slugify_numbers() Test slugify with numbers in the string. #### test_slugify_simple() Test slugify with a simple alphanumeric string. #### test_slugify_spaces() Test slugify with spaces. #### test_slugify_special_characters() Test slugify with special characters. ### *class* fake.TestStringTemplate(methodName='runTest') Bases: `TestCase` #### setUp() Hook method for setting up the test fixture before exercising it. #### test_argument_parsing_error_raises_value_error() #### test_complex_argument_parsing() #### test_escape_braces() #### test_instance_is_str() #### test_join_with_no_templates() #### test_join_with_single_template() #### test_join_with_string_template() #### test_large_number_of_placeholders() #### test_method_call_error_raises_value_error() #### test_missing_method_raises_attribute_error() #### test_multiple_placeholders() #### test_nested_placeholders() #### test_no_placeholders() #### test_no_wrapping_when_not_specified() #### test_placeholder_with_arguments() #### test_placeholder_with_boolean_arguments() #### test_placeholder_with_empty_arguments() #### test_placeholder_with_no_parentheses() #### test_placeholder_with_numeric_method_name() #### test_placeholder_with_spaces_in_arguments() #### test_placeholder_with_underscores_in_method_name() #### test_repr_method() #### test_simple_placeholder_replacement() #### test_str_method() #### test_wrapping_functionality() ### *class* fake.TextPdfGenerator(faker: [Faker](#fake.Faker)) Bases: `object` Text PDF generatr. Usage example: ```python from pathlib import Path from fake import FAKER, TextPdfGenerator Path("/tmp/text_example.pdf").write_bytes( FAKER.pdf(nb_pages=100, generator=TextPdfGenerator) ) ``` #### create(nb_pages: int | None = None, texts: List[str] | None = None, metadata: [MetaData](#fake.MetaData) | None = None, \*\*kwargs) → bytes #### nb_pages *: int* #### texts *: List[str]* ### *class* fake.TortoiseModelFactory(\*\*kwargs) Bases: [`ModelFactory`](#fake.ModelFactory) Tortoise ModelFactory. #### *classmethod* create(\*\*kwargs) #### *classmethod* save(instance) Save the instance. ### fake.create_inner_bmp_file(storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255), dir_path: str | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create inner BMP file. ### fake.create_inner_docx_file(storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, nb_pages: int | None = 1, texts: List[str] | None = None, metadata: [MetaData](#fake.MetaData) | None = None, dir_path: str | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create inner DOCX file. ### fake.create_inner_eml_file(storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, options: Dict[str, Any] | None = None, content: str | None = None, subject: str | None = None, cte_type: str | None = None, policy: Policy | None = None, metadata: [MetaData](#fake.MetaData) | None = None, dir_path: str | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create inner EML file. ### fake.create_inner_generic_file(storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, content: bytes | str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) = '', extension: str = 'txt', dir_path: str | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create an inner file of any format with arbitrary content. Unlike the other `create_inner_*` functions which each target a specific file format, this function accepts any `extension` and any `content` — including a [`StringTemplate`](#fake.StringTemplate) or [`LazyStringTemplate`](#fake.LazyStringTemplate), which is rendered fresh on each call. Usage examples: ```default # Plain string content create_inner_generic_file( content="", extension="xml", ) # StringTemplate — rendered once at call-site construction time create_inner_generic_file( content=StringTemplate("{sentence(nb_words=4)}"), extension="xml", ) # LazyStringTemplate — rendered fresh on every call, useful with # count > 1 so each file gets independently generated content create_inner_generic_file( content=LazyStringTemplate("{sentence(nb_words=4)}"), extension="xml", dir_path="{dir_path(depth=2)}", ) ``` * **Parameters:** * **storage** – Storage backend to use. Defaults to `FileSystemStorage`. * **basename** – Base name for the file. Defaults to `None`. * **prefix** – Prefix for the file name. Defaults to `None`. * **content** – File content. Accepts `bytes`, `str`, [`StringTemplate`](#fake.StringTemplate), or [`LazyStringTemplate`](#fake.LazyStringTemplate). Defaults to `""`. * **extension** – File extension without leading dot. Defaults to `"txt"`. * **dir_path** – Optional in-archive subdirectory. Resolved through `FAKER.string_template()` so template expressions such as `"{dir_path(depth=3)}"` are supported. Defaults to `None`. * **\*\*kwargs** – Reserved for API compatibility. Currently ignored. * **Returns:** `StringValue` containing the relative path of the generated file. * **Return type:** [StringValue](#fake.StringValue) ### fake.create_inner_gif_file(storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255), dir_path: str | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create inner GIF file. ### fake.create_inner_jpg_file(storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (128, 128, 128), dir_path: str | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create inner JPG file. ### fake.create_inner_odt_file(storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, nb_pages: int | None = 1, texts: List[str] | None = None, metadata: [MetaData](#fake.MetaData) | None = None, dir_path: str | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create inner ODT file. ### fake.create_inner_pdf_file(storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, nb_pages: int | None = 1, generator: Type[[TextPdfGenerator](#fake.TextPdfGenerator)] | Type[[GraphicPdfGenerator](#fake.GraphicPdfGenerator)] = , metadata: [MetaData](#fake.MetaData) | None = None, dir_path: str | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create inner PDF file. ### fake.create_inner_png_file(storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255), dir_path: str | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create inner PNG file. ### fake.create_inner_ppm_file(storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255), dir_path: str | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create inner PPM file. ### fake.create_inner_rtf_file(storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, nb_pages: int | None = 1, texts: List[str] | None = None, metadata: [MetaData](#fake.MetaData) | None = None, dir_path: str | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create inner RTF file. ### fake.create_inner_svg_file(storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255), dir_path: str | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create inner SVG file. ### fake.create_inner_tar_file(storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, options: Dict[str, Any] | None = None, compression: Literal['gz', 'bz2', 'xz'] | None = None, metadata: [MetaData](#fake.MetaData) | None = None, dir_path: str | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create inner TAR file. ### fake.create_inner_text_pdf_file(storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, nb_pages: int | None = 1, generator: Type[[TextPdfGenerator](#fake.TextPdfGenerator)] = , metadata: [MetaData](#fake.MetaData) | None = None, dir_path: str | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create inner text PDF file. ### fake.create_inner_tif_file(storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255), dir_path: str | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create inner TIF file. ### fake.create_inner_txt_file(storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, text: str | None = None, dir_path: str | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create inner TXT file. ### fake.create_inner_wav_file(storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, frequency: int = 440, duration: int = 1, volume: float | int = 0.5, sample_rate: int = 44100, dir_path: str | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create inner WAV file. ### fake.create_inner_zip_file(storage: [BaseStorage](#fake.BaseStorage) | None = None, basename: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, prefix: str | [StringTemplate](#fake.StringTemplate) | [LazyStringTemplate](#fake.LazyStringTemplate) | None = None, options: Dict[str, Any] | None = None, metadata: [MetaData](#fake.MetaData) | None = None, dir_path: str | None = None, \*\*kwargs) → [StringValue](#fake.StringValue) Create inner ZIP file. ### fake.fill_dataclass(dataclass_type: Type) → Any Fill dataclass with data. ### fake.fill_pydantic_model(object_type: Type) → Any ### fake.format_type_hint(type_hint) → str Format the type hint for display. ### fake.fuzzy_choice_create_inner_file(func_choices: List[Tuple[Callable[[...], [StringValue](#fake.StringValue)], Dict[str, Any]]], \*\*kwargs) → [StringValue](#fake.StringValue) Create inner file from given list of function choices. * **Parameters:** * **func_choices** – List of functions to choose from. * **\*\*kwargs** – Additional keyword arguments to pass to the function. * **Return type:** [StringValue](#fake.StringValue) * **Returns:** StringValue instance. Usage example: ```python from fake import ( FAKER, FileSystemStorage, create_inner_docx_file, create_inner_png_file, create_inner_txt_file, fuzzy_choice_create_inner_file, ) STORAGE = FileSystemStorage() kwargs = {"storage": STORAGE} file = fuzzy_choice_create_inner_file( [ (create_inner_docx_file, kwargs), (create_inner_png_file, kwargs), (create_inner_txt_file, kwargs), ] ) ``` You could use it in archives to make a variety of different file types within the archive. ```python from fake import ( FAKER, FileSystemStorage, create_inner_docx_file, create_inner_png_file, create_inner_txt_file, fuzzy_choice_create_inner_file, ) STORAGE = FileSystemStorage() kwargs = {"storage": STORAGE} file = FAKER.zip_file( prefix="zzz_archive_", options={ "count": 50, "create_inner_file_func": fuzzy_choice_create_inner_file, "create_inner_file_args": { "func_choices": [ (create_inner_docx_file, kwargs), (create_inner_png_file, kwargs), (create_inner_txt_file, kwargs), ], }, "directory": "zzz", } ) ``` ### fake.get_argparse_type(param_type) → Any Get the corresponding argparse type for a given parameter type. ### fake.get_provider_args(func: Callable) → Dict[str, Any] Retrieve the argument list and types for a provider function by inspecting its signature. ### fake.get_provider_defaults(func: Callable) → Dict[str, Any] Retrieve the argument list and defaults for a provider function by inspecting its signature. ### fake.is_optional_type(type_hint) → bool Check if the type hint is an Optional. ### fake.list_create_inner_file(func_list: List[Tuple[Callable[[...], [StringValue](#fake.StringValue)], Dict[str, Any]]], \*\*kwargs) → List[[StringValue](#fake.StringValue)] Generates multiple files based on the provided list of functions and arguments. * **Parameters:** * **func_list** – List of tuples, each containing a function to generate a file and its arguments. * **\*\*kwargs** – Additional keyword arguments to pass to the functions. * **Return type:** List[[StringValue](#fake.StringValue)] * **Returns:** List of generated file names. Usage example: ```python from fake import ( FAKER, FileSystemStorage, create_inner_docx_file, create_inner_txt_file, list_create_inner_file, ) file = FAKER.zip_file( basename="alice-looking-through-the-glass", options={ "create_inner_file_func": list_create_inner_file, "create_inner_file_args": { "func_list": [ (create_inner_docx_file, {"basename": "doc"}), (create_inner_txt_file, {"basename": "doc_metadata"}), (create_inner_txt_file, {"basename": "doc_isbn"}), ], }, } ) ``` Note, that while all other inner functions return back StringValue value, list_create_inner_file returns back a List[StringValue] value. Notably, all inner functions were designed to support archives (such as ZIP, TAR and EML, but the list may grow in the future). If the inner function passed in the create_inner_file_func argument returns a List of StringValue values, the option argument is being ignored and generated files are simply limited to what has been passed in the func_list list of tuples. ### fake.main() → None ### fake.organise_providers(provider_tags) → Dict[str, Any] Organise providers by category for easier navigation. ### fake.post_save(func) ### fake.pre_init(func) ### fake.pre_save(func) ### fake.provider(\*args: Any, tags: Tuple[str, ...] | None = None) → Callable ### fake.resolve_inner_directory(file: [StringValue](#fake.StringValue), directory: str) → Path Resolve the in-archive path for an inner file. Combines three components: 1. *directory* — the static `options["directory"]` prefix supplied by the caller of `zip()` / `tar()`. 2. `file.data.get("directory", "")` — an optional subdirectory set by the creator function via its `dir_path` parameter. 3. `Path(file).name` — the bare filename of the generated file, derived from the real on-disk path as always. When `data["directory"]` is absent (i.e. `dir_path` was not passed to the creator), this returns the same result as the current `Path(directory) / Path(file).name` expression, preserving full backwards compatibility. * **Parameters:** * **file** – The `StringValue` returned by a creator function. * **directory** – The `options["directory"]` prefix (may be `""`). * **Returns:** The resolved in-archive path. * **Return type:** Path ### fake.run_async_in_thread(coroutine: Coroutine) → Awaitable Run an asynchronous coroutine in a separate thread. * **Parameters:** **coroutine** – An asyncio coroutine to be run. * **Returns:** The result of the coroutine. * **Return type:** Awaitable ### fake.slugify(value: str, separator: str = '') → str Slugify. ### fake.trait(func) ### fake.wrap_text(text: str, wrap_chars_after: int) → str ### fake.xor_transform(val: str, key: int = 10) → str Simple, deterministic string encoder/decoder. Usage example: ```python val = "abcd" encoded_val = xor_transform(val) decoded_val = xor_transform(encoded_val) ```