fake module
https://github.com/barseghyanartur/fake.py/
- class fake.AuthorshipData[source]
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', 'McGuire', '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)[source]
Bases:
objectBase storage.
- class fake.DjangoModelFactory(**kwargs)[source]
Bases:
ModelFactoryDjango ModelFactory.
- class fake.DocxGenerator(faker: Faker)[source]
Bases:
objectDocxGenerator - generates a DOCX file with text.
Usage example:
from pathlib import Path from fake import FAKER Path("/tmp/example.docx").write_bytes( DocxGenerator(FAKER).create(nb_pages=100) )
- class fake.FactoryMethod(method_name: str, faker: Optional[Faker] = None, **kwargs)[source]
Bases:
object
- class fake.Faker(alias: Optional[str] = None)[source]
Bases:
objectfake.py - simplified, standalone alternative with no dependencies.
Usage example:
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:
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:
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.
- bmp(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255)) bytes[source]
Create a BMP image of a specified size and color.
- Parameters:
size – Tuple of width and height of the image in pixels.
color – Color of the image in RGB format (tuple of three integers).
- 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: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, extension: Optional[str] = None) StringValue[source]
Create a BMP image file of a specified size and color.
- company_email(domain_names: Optional[Tuple[str, ...]] = None) str[source]
Generate a random company email.
- date(start_date: str = '-7d', end_date: str = '+0d', tzinfo: timezone = datetime.timezone.utc) date[source]
Generate random date between start_date and end_date.
- Parameters:
start_date – The start date from which the random date should be generated in the shorthand notation.
end_date – The end date up to which the random date should be generated in the 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[source]
Generate a random datetime between start_date and end_date.
- Parameters:
start_date – The start datetime from which the random datetime should be generated in the shorthand notation.
end_date – The end datetime up to which the random datetime should be generated in the shorthand notation.
tzinfo – The timezone.
- Returns:
A string representing the formatted datetime.
- Return type:
datetime
- docx(nb_pages: Optional[int] = 1, texts: Optional[List[str]] = None, metadata: Optional[MetaData] = None) bytes[source]
Create a DOCX document.
- docx_file(nb_pages: int = 1, texts: Optional[List[str]] = None, metadata: Optional[MetaData] = None, storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None) StringValue[source]
Create a DOCX document file.
- free_email(domain_names: Optional[Tuple[str, ...]] = None) str[source]
Generate a random free email.
- generic_file(content: Union[bytes, str], extension: str, storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None) StringValue[source]
Create a generic file.
- gif(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255)) bytes[source]
Create a GIF image of a specified size and color.
- Parameters:
size – Tuple of width and height of the image in pixels.
color – Color of the image in RGB format (tuple of three integers).
- 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: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, extension: Optional[str] = None) StringValue[source]
Create a GIF image file of a specified size and color.
- iban(country_code: Optional[str] = None, bank_length: int = 8, account_length: int = 10) str[source]
Generate a random valid IBAN number.
- image(image_format: Literal['png', 'svg', 'bmp', 'gif', 'tif', 'ppm'] = 'png', size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255)) bytes[source]
Create an image of a specified format, size and color.
- image_url(width: int = 800, height: int = 600, service_url: Optional[str] = None) str[source]
Generate a random image URL.
- odt(nb_pages: Optional[int] = 1, texts: Optional[List[str]] = None, metadata: Optional[MetaData] = None) bytes[source]
Create a ODT document.
- odt_file(nb_pages: int = 1, texts: Optional[List[str]] = None, metadata: Optional[MetaData] = None, storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None) StringValue[source]
Create a ODT document file.
- pdf(nb_pages: int = 1, generator: ~typing.Union[~typing.Type[~fake.TextPdfGenerator], ~typing.Type[~fake.GraphicPdfGenerator]] = <class 'fake.GraphicPdfGenerator'>, metadata: ~typing.Optional[~fake.MetaData] = None, **kwargs) bytes[source]
Create a PDF document of a given size.
- pdf_file(nb_pages: int = 1, generator: ~typing.Union[~typing.Type[~fake.TextPdfGenerator], ~typing.Type[~fake.GraphicPdfGenerator]] = <class 'fake.GraphicPdfGenerator'>, metadata: ~typing.Optional[~fake.MetaData] = None, storage: ~typing.Optional[~fake.BaseStorage] = None, basename: ~typing.Optional[str] = None, prefix: ~typing.Optional[str] = None, **kwargs) StringValue[source]
Create a PDF file.
- png(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255)) bytes[source]
Create a PNG image of a specified size and color.
- Parameters:
size – Tuple of width and height of the image in pixels.
color – Color of the image in RGB format (tuple of three integers).
- 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: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, extension: Optional[str] = None) StringValue[source]
Create a PNG image file of a specified size and color.
- ppm(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255)) bytes[source]
Create a PPM image of a specified size and color.
- Parameters:
size – Tuple of width and height of the image in pixels.
color – Color of the image in RGB format, tuple of three integers: (0-255, 0-255, 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: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, extension: Optional[str] = None) StringValue[source]
Create a PPM image file of a specified size and color.
- pydecimal(left_digits: int = 5, right_digits: int = 2, positive: bool = True) Decimal[source]
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:
A randomly generated Decimal number.
- Return type:
Decimal
- Raises:
ValueError
- pyfloat(min_value: float = 0.0, max_value: float = 10.0) float[source]
Generate a random float number.
- random_element(elements: Sequence[T]) T
- random_elements(elements: Sequence[T], length: int) List[T]
- svg(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255)) bytes[source]
Create an SVG image of a specified size and color.
- Parameters:
size – Tuple of width and height of the image in pixels.
color – Color of the image in RGB format (tuple of three integers).
- 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: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, extension: Optional[str] = None) StringValue[source]
Create an SVG image file of a specified size and color.
- text_pdf(nb_pages: int = 1, generator: ~typing.Type[~fake.TextPdfGenerator] = <class 'fake.TextPdfGenerator'>, metadata: ~typing.Optional[~fake.MetaData] = None, **kwargs) bytes[source]
Create a PDF document of a given size.
- text_pdf_file(nb_pages: int = 1, generator: ~typing.Type[~fake.TextPdfGenerator] = <class 'fake.TextPdfGenerator'>, metadata: ~typing.Optional[~fake.MetaData] = None, storage: ~typing.Optional[~fake.BaseStorage] = None, basename: ~typing.Optional[str] = None, prefix: ~typing.Optional[str] = None, **kwargs) StringValue[source]
Create a text PDF file.
- tif(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255)) bytes[source]
Create a TIF image of a specified size and color.
- Parameters:
size – Tuple of width and height of the image in pixels.
color – Color of the image in RGB format (tuple of three integers).
- 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: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, extension: Optional[str] = None) StringValue[source]
Create a TIF image file of a specified size and color.
- txt_file(nb_chars: Optional[int] = 200, storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, text: Optional[str] = None) StringValue[source]
Create a text document file.
- class fake.FileRegistry[source]
Bases:
objectStores list StringValue instances.
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) None[source]
- remove(string_value: Union[StringValue, str]) bool[source]
- search(value: str) Optional[StringValue][source]
- class fake.FileSystemStorage(root_path: Optional[Union[str, Path]] = '/tmp', rel_path: Optional[str] = 'tmp', *args, **kwargs)[source]
Bases:
BaseStorageFile storage class using pathlib for path handling.
Usage example:
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:
from fake import FAKER, FileSystemStorage storage = FileSystemStorage() docx_file = FAKER.docx_file(storage=storage)
- class fake.GraphicPdfGenerator(faker: Faker)[source]
Bases:
objectGraphic PDF generatr.
Usage example:
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[source]
- image_color: Tuple[int, int, int]
- image_size: Tuple[int, int]
- nb_pages: int
- class fake.OdtGenerator(faker: Faker)[source]
Bases:
objectOdtGenerator - generates an ODT file with text.
Usage example:
from pathlib import Path from fake import FAKER Path("/tmp/example.odt").write_bytes( OdtGenerator(FAKER).create(nb_pages=100) )
- class fake.PydanticModelFactory(**kwargs)[source]
Bases:
ModelFactoryPydantic ModelFactory.
- class fake.SQLAlchemyModelFactory(**kwargs)[source]
Bases:
ModelFactorySQLAlchemy ModelFactory.
- class fake.TextPdfGenerator(faker: Faker)[source]
Bases:
objectText PDF generatr.
Usage example:
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: Optional[int] = None, texts: Optional[List[str]] = None, metadata: Optional[MetaData] = None, **kwargs) bytes[source]
- nb_pages: int
- texts: List[str]
- class fake.TortoiseModelFactory(**kwargs)[source]
Bases:
ModelFactoryTortoise ModelFactory.
- fake.fill_dataclass(dataclass_type: Type) Any
Fill dataclass with data.
- fake.fill_pydantic_model(object_type: Type) Any
- fake.get_argparse_type(param_type) Any[source]
Get the corresponding argparse type for a given parameter type.
- fake.get_provider_args(func: Callable) Dict[str, Any][source]
Retrieve the argument list and types for a provider function by inspecting its signature.
- fake.get_provider_defaults(func: Callable) Dict[str, Any][source]
Retrieve the argument list and defaults for a provider function by inspecting its signature.
- fake.organize_providers(provider_tags) Dict[str, Any][source]
Organize providers by category for easier navigation.