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(FAKER.docx(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 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.
- 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) StringValue[source]
- date(start_date: str = '-7d', end_date: str = '+0d', tzinfo=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.
- date_time(start_date: str = '-7d', end_date: str = '+0d', tzinfo=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.
- docx(nb_pages: Optional[int] = 1, texts: Optional[List[str]] = None, metadata: Optional[MetaData] = None) bytes[source]
- 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]
- generic_file(content: Union[bytes, str], extension: str, storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None) StringValue[source]
- gif(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255)) bytes[source]
Create a GIF image of a specified 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.
- 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) StringValue[source]
- image(image_format: Literal['png', 'svg', 'bmp', 'gif'] = 'png', size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255)) bytes[source]
- image_url(width: int = 800, height: int = 600, service_url: Optional[str] = None) str[source]
Image URL.
- 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]
- png(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255)) bytes[source]
Create a PNG image of a specified 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.
- 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) StringValue[source]
- 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.
- svg(size: Tuple[int, int] = (100, 100), color: Tuple[int, int, int] = (0, 0, 255)) bytes[source]
Create a SVG image of a specified 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.
- 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) StringValue[source]
- 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]
- 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.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