diff --git a/README.rst b/README.rst index 129b78a..5acdf05 100644 --- a/README.rst +++ b/README.rst @@ -6,7 +6,17 @@ fake.py .. _Faker: https://faker.readthedocs.io/ .. _Django: https://www.djangoproject.com/ .. _TortoiseORM: https://tortoise.github.io/ -.. _Pydantic: https://docs.pydantic.dev/l +.. _Pydantic: https://docs.pydantic.dev/ + +.. Internal references + +.. _Read the Docs: http://fakepy.readthedocs.io/ +.. _Quick start: https://fakepy.readthedocs.io/en/latest/quick_start.html +.. _Recipes: https://fakepy.readthedocs.io/en/latest/recipes.html +.. _Creating PDF: https://fakepy.readthedocs.io/en/latest/creating_pdf.html +.. _Creating DOCX: https://fakepy.readthedocs.io/en/latest/creating_docx.html +.. _Creating images: https://fakepy.readthedocs.io/en/latest/creating_images.html +.. _Contributor guidelines: https://fakepy.readthedocs.io/en/latest/contributor_guidelines.html Minimalistic, standalone alternative fake data generator with no dependencies. @@ -39,35 +49,38 @@ Minimalistic, standalone alternative fake data generator with no dependencies. Overview ======== +``fake.py`` is a standalone, portable library designed for generating various +random data types for testing. + +It offers a simplified, dependency-free alternative for creating random +texts, (person) names, URLs, dates, file names, IPs, primitive Python data +types (such as `uuid`, `str`, `int`, `float`, `bool`) and byte content +for multiple file formats including `PDF`, `DOCX`, `PNG`, `SVG`, `BMP`, +and `GIF`. -``fake.py`` is a standalone and portable library that allows you to generate -various types of random data for testing purposes. The package provides a -simplified, dependency-free alternative for generating random words, -sentences, paragraphs, file names, URLs, person names, as well as -bytes content for ``PDF``-, ``DOCX``- and various image formats (such as -``PNG``, ``SVG``, ``BMP`` and ``GIF``). It can create files directly -on your filesystem too. It comes with basic factories (that work with -`Django`_, `TortoiseORM`_ and `Pydantic`_). +The package also supports file creation on the filesystem and includes +factories (dynamic fixtures) compatible with `Django`_, `TortoiseORM`_, +and `Pydantic`_. Features ======== -- Generate random texts. -- Create files of ``PDF``, ``DOCX``, ``TXT``, ``PNG``, ``SVG``, ``BMP`` - and ``GIF`` formats. -- Built-in basic factoies, that work well with `Django`_, `Pydantic`_ and - `TortoiseORM`_. - -Requirements -============ +- Generation of random texts, (person) names, emails, URLs, dates, IPs, and + primitive Python data types. +- Support for various file formats (`PDF`, `DOCX`, `TXT`, `PNG`, `SVG`, + `BMP`, `GIF`) and file creation on the filesystem. +- Basic factories for integration with `Django`_, `Pydantic`_, + and `TortoiseORM`_. -* Python 3.8+ +Prerequisites +============= +Python 3.8+ Installation ============ pip --- -.. code-block:: bash +.. code-block:: sh pip install fake.py @@ -80,611 +93,154 @@ tests too. If it's more convenient to you, you could simply download the Since tests are included, it won't have a negative impact on your test coverage (you might need to apply tweaks to your coverage configuration). +Documentation +============= +- Documentation is available on `Read the Docs`_. +- For bootstrapping check the `Quick start`_. +- For various ready to use code examples see the `Recipes`_. +- For tips on ``PDF`` creation see `Creating PDF`_. +- For tips on ``DOCX`` creation see `Creating DOCX`_. +- For tips on images creation see `Creating images`_. +- For guidelines on contributing check the `Contributor guidelines`_. + Usage ===== Generate data ------------- -**Imports and initialization** - +Person names +~~~~~~~~~~~~ .. code-block:: python - from fake import Faker - - FAKER = Faker() - ----- - -**first_name** - -Returns a random first name. - -.. code-block:: python + from fake import FAKER FAKER.first_name() - ----- - -**last_name** - -Returns a random last name. - -.. code-block:: python - FAKER.last_name() - ----- - -**name** - -Returns a random full name. - -.. code-block:: python - FAKER.name() + FAKER.username() ----- - -**word** - -Returns a random word. - +Random texts +~~~~~~~~~~~~ .. code-block:: python - FAKER.word() - ----- - -**words** - -Returns a list of ``nb`` random words. - -.. code-block:: python - - FAKER.words() - -Arguments: - -- ``nb`` (type: ``int``, default value: ``5``) is an optional argument. - ----- - -**sentence** - -Returns a random sentence with ``nb_words`` number of words. - -.. code-block:: python + from fake import FAKER + FAKER.slug() + FAKER.word() FAKER.sentence() - -Arguments: - -- ``nb_words`` (type: ``int``, default value: ``5``) is an optional argument. - ----- - -**sentences** - -Returns ``nb`` number of random sentences. - -.. code-block:: python - - FAKER.sentences() - -Arguments: - -- ``nb`` (type: ``int``, default value: ``3``) is an optional argument. - ----- - -**paragraph** - -Returns a random paragraph with ``nb_sentences`` number of sentences. - -.. code-block:: python - FAKER.paragraph() - -Arguments: - -- ``nb_sentences`` (type: ``int``, default value: ``5``) is an optional - argument. - ----- - -**paragraphs** - -Returns ``nb`` number of random paragraphs. - -.. code-block:: python - - FAKER.paragraphs() - -Arguments: - -- ``nb`` (type: ``int``, default value: ``3``) is an optional argument. - ----- - -**text** - -Returns random text with up to ``nb_chars`` characters. - -.. code-block:: python - FAKER.text() -Arguments: - -- ``nb_chars`` (type: ``int``, default value: ``200``) is an optional argument. - ----- - -**texts** - -Returns ``nb`` number of random texts. - +Internet +~~~~~~~~ .. code-block:: python - FAKER.texts() - -Arguments: - -- ``nb`` (type: ``int``, default value: ``3``) is an optional argument. - ----- - -**file_name** - -Returns a random file name with the given extension. - -.. code-block:: python - - FAKER.file_name() - -Arguments: - -- ``extension`` (type: ``str``, default value: ``txt``) is an optional - argument. - ----- - -**email** - -Returns a random email with the specified domain. - -.. code-block:: python + from fake import FAKER FAKER.email() - -Arguments: - -- ``domain`` (type: ``str``, default value: ``example.com``) is an optional - argument. - ----- - -**url** - -Returns a random URL. - -.. code-block:: python - FAKER.url() + FAKER.ipv4() -Arguments: - -- ``protocols`` (type: ``Optional[Tuple[str]]``, default value: ``None``) is - an optional argument. -- ``tlds`` (type: ``Optional[Tuple[str]]``, default value: ``None``) is - an optional argument. -- ``suffixes`` (type: ``Optional[Tuple[str]]``, default value: ``None``) is - an optional argument. - ----- - -**pyint** - -Returns a random integer between ``min_value`` and ``max_value``. - +Filenames +~~~~~~~~~ .. code-block:: python - FAKER.pyint() - -Arguments: - -- ``min_value`` (type: ``int``, default value: ``0``) is an optional argument. -- ``max_value`` (type: ``int``, default value: ``9999``) is an optional - argument. + from fake import FAKER ----- - -**pybool** - -Returns a random boolean value. + FAKER.filename() +Primitive data types +~~~~~~~~~~~~~~~~~~~~ .. code-block:: python - FAKER.pybool() - ----- - -**pystr** - -Returns a random string of ``nb_chars`` length. - -.. code-block:: python + from fake import FAKER + FAKER.pyint() + FAKER.pybool() FAKER.pystr() - -Arguments: - -- ``nb_chars`` (type: ``int``, default value: ``20``) is an optional argument. - ----- - -**pyfloat** - -Returns a random float between ``min_value`` and ``max_value``. - -.. code-block:: python - FAKER.pyfloat() -Arguments: - -- ``min_value`` (type: ``float``, default value: ``0.0``) is an optional - argument. -- ``max_value`` (type: ``float``, default value: ``10.00``) is an optional - argument. - ----- - -**ipv4** - -Returns a random IPv4 address. - +Dates +~~~~~ .. code-block:: python - FAKER.ipv4() - ----- + from fake import FAKER -**date_between** - -Generates a random date between ``start_date`` and ``end_date``. + FAKER.date() + FAKER.date_time() +Generate files +-------------- +As bytes +~~~~~~~~ .. code-block:: python - FAKER.date_between(start_date="-1d", end_date="+1d") - -Arguments: - -- ``start_date`` (type: ``str``) is a required argument. -- ``end_date`` (type: ``str``, default value: ``+0d``) is an optional - argument. - ----- - -**date_time_between** - -Generates a random datetime between ``start_date`` and ``end_date``. - -.. code-block:: python - - FAKER.date_time_between(start_date="-1d", end_date="+1d") - -Arguments: - -- ``start_date`` (type: ``str``) is a required argument. -- ``end_date`` (type: ``str``, default value: ``+0d``) is an optional - argument. - ----- - -**pdf** - -Generates a content (``bytes``) of a PDF document. - -.. code-block:: python + from fake import FAKER FAKER.pdf() - -Arguments: - -- ``nb_pages`` (type: ``int``, default value: ``1``) is an optional argument. -- ``texts`` (type: ``List[str]``, default value: ``None``) is an optional - argument. -- ``generator`` - (type: ``Union[Type[TextPdfGenerator], Type[GraphicPdfGenerator]]``, - default value: ``GraphicPdfGenerator``) is an optional argument. - -.. note:: - - ``texts`` is valid only in case ``TextPdfGenerator`` is used. - -.. note:: - - Either ``nb_pages`` or ``texts`` shall be provided. ``nb_pages`` is by - default set to ``1``, but if ``texts`` is given, the value of ``nb_pages`` - is adjusted accordingly. - ----- - -**image** - -Generates a content (``bytes``) of a image of the specified format and colour. - -.. code-block:: python - - FAKER.image() # Supported formats are `png`, `svg`, `bmp` and `gif` - -Arguments: - -- ``image_format`` (type: ``str``, default value: ``png``) is an optional - argument. -- ``size`` (type: ``Tuple[int, int]``, default value: ``(100, 100)``) is an - optional argument. -- ``color`` (type: ``Tuple[int, int, int]``, default value: ``(0, 0, 255)``) - is an optional argument. - ----- - -**docx** - -Generates a content (``bytes``) of a DOCX document. - -.. code-block:: python - FAKER.docx() + FAKER.png() + FAKER.svg() + FAKER.bmp() + FAKER.gif() -Arguments: - -- ``nb_pages`` (type: ``int``, default value: ``1``) is an optional argument. -- ``texts`` (type: ``List[str]``, default value: ``None``) is an optional - argument. - -.. note:: - - Either ``nb_pages`` or ``texts`` shall be provided. ``nb_pages`` is by - default set to ``1``, but if ``texts`` is given, the value of ``nb_pages`` - is adjusted accordingly. - ----- - -**pdf_file** - -Generates a ``PDF`` file. - +As files on the file system +~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: python - FAKER.pdf_file() - -Arguments: - -.. note:: - - Accepts all arguments of ``pdf`` + the following: - -- ``storage`` (type: ``BaseStorage``, default value: ``None``) is an optional - argument. -- ``basename`` (type: ``str``, default value: ``None``) is an optional - argument. -- ``prefix`` (type: ``str``, default value: ``None``) is an optional argument. - ----- - -**png_file** - -Generates a ``PNG`` file. - -.. code-block:: python + from fake import FAKER + FAKER.pdf_file() + FAKER.docx_file() FAKER.png_file() - -Arguments: - -.. note:: - - Accepts all arguments of ``png`` + the following: - -- ``storage`` (type: ``BaseStorage``, default value: ``None``) is an optional - argument. -- ``basename`` (type: ``str``, default value: ``None``) is an optional - argument. -- ``prefix`` (type: ``str``, default value: ``None``) is an optional argument. - ----- - -**svg_file** - -Generates an ``SVG`` file. - -.. code-block:: python - FAKER.svg_file() - -Arguments: - -.. note:: - - Accepts all arguments of ``svg`` + the following: - -- ``storage`` (type: ``BaseStorage``, default value: ``None``) is an optional - argument. -- ``basename`` (type: ``str``, default value: ``None``) is an optional - argument. -- ``prefix`` (type: ``str``, default value: ``None``) is an optional argument. - ----- - -**bmp_file** - -Generates a ``BMP`` file. - -.. code-block:: python - FAKER.bmp_file() - -Arguments: - -.. note:: - - Accepts all arguments of ``bmp`` + the following: - -- ``storage`` (type: ``BaseStorage``, default value: ``None``) is an optional - argument. -- ``basename`` (type: ``str``, default value: ``None``) is an optional - argument. -- ``prefix`` (type: ``str``, default value: ``None``) is an optional argument. - ----- - -**gif_file** - -Generates a ``GIF`` file. - -.. code-block:: python - FAKER.gif_file() - -Arguments: - -.. note:: - - Accepts all arguments of ``gif`` + the following: - -- ``storage`` (type: ``BaseStorage``, default value: ``None``) is an optional - argument. -- ``basename`` (type: ``str``, default value: ``None``) is an optional - argument. -- ``prefix`` (type: ``str``, default value: ``None``) is an optional argument. - ----- - -**txt_file** - -Generates a ``TXT`` file. - -.. code-block:: python - FAKER.txt_file() -Arguments: - -.. note:: - - Accepts all arguments of ``text`` + the following: - -- ``storage`` (type: ``BaseStorage``, default value: ``None``) is an optional - argument. -- ``basename`` (type: ``str``, default value: ``None``) is an optional - argument. -- ``prefix`` (type: ``str``, default value: ``None``) is an optional argument. - Factories --------- -Django example -~~~~~~~~~~~~~~ -**factories.py** +This is how you could define a factory for `Django`_'s built-in ``User`` model. .. code-block:: python from django.conf import settings + from django.contrib.auth.models import User from fake import ( + FACTORY, DjangoModelFactory, - Factory, FileSystemStorage, SubFactory, pre_save, ) - from article.models import Article - STORAGE = FileSystemStorage(root_path=settings.MEDIA_ROOT, rel_path="tmp") - class ArticleFactory(DjangoModelFactory): - title = Factory.sentence() - slug = Factory.slug() - content = Factory.text() - image = Factory.png_file(storage=STORAGE) - pub_date = Factory.date() - safe_for_work = Factory.pybool() - minutes_to_read = Factory.pyint(min_value=1, max_value=10) - author = SubFactory(UserFactory) - - class Meta: - model = Article - -**Usage example** - -.. code-block:: python - - article = ArticleFactory() # Create one article - articles = ArticleFactory.create_batch(5) # Create 5 articles - -Pydantic example -~~~~~~~~~~~~~~~~ - -.. code-block:: python - - from pathlib import Path - - from fake import Factory, FileSystemStorage, ModelFactory, SubFactory - - from article.models import Article - - BASE_DIR = Path(__file__).resolve().parent.parent - MEDIA_ROOT = BASE_DIR / "media" - STORAGE = FileSystemStorage(root_path=MEDIA_ROOT, rel_path="tmp") + class UserFactory(DjangoModelFactory): - class ArticleFactory(ModelFactory): - id = Factory.pyint() - title = Factory.sentence() - slug = Factory.slug() - content = Factory.text() - image = Factory.png_file(storage=STORAGE) - pub_date = Factory.date() - safe_for_work = Factory.pybool() - minutes_to_read = Factory.pyint(min_value=1, max_value=10) - author = SubFactory(UserFactory) + username = FACTORY.username() + first_name = FACTORY.first_name() + last_name = FACTORY.last_name() + email = FACTORY.email() + last_login = FACTORY.date_time() + is_superuser = False + is_staff = False + is_active = FACTORY.pybool() + date_joined = FACTORY.date_time() class Meta: - model = Article + model = User + get_or_create = ("username",) -*Used just like in previous example.* + @pre_save + def __set_password(instance): + instance.set_password("test") -TortoiseORM example -~~~~~~~~~~~~~~~~~~~ +And this is how you could use it: .. code-block:: python - from pathlib import Path - - from fake import Factory, FileSystemStorage, SubFactory, TortoiseModelFactory - - from article.models import Article, User - - # Build paths inside the project like this: BASE_DIR / 'subdir'. - BASE_DIR = Path(__file__).resolve().parent.parent - MEDIA_ROOT = BASE_DIR / "media" - - STORAGE = FileSystemStorage(root_path=MEDIA_ROOT, rel_path="tmp") - - class ArticleFactory(TortoiseModelFactory): - id = Factory.pyint() - title = Factory.sentence() - slug = Factory.slug() - content = Factory.text() - image = Factory.png_file(storage=STORAGE) - pub_date = Factory.date_time() - safe_for_work = Factory.pybool() - minutes_to_read = Factory.pyint(min_value=1, max_value=10) - author = SubFactory(UserFactory) - - class Meta: - model = Article - -*Used just like in previous example.* + user = UserFactory() + users = UserFactory.create_batch(5) Tests ===== diff --git a/docs/factories.rst b/docs/factories.rst index f626b60..77fb0f1 100644 --- a/docs/factories.rst +++ b/docs/factories.rst @@ -1,2 +1,105 @@ Factories ========= + +Django example +-------------- +**factories.py** + +.. code-block:: python + + from django.conf import settings + from fake import ( + DjangoModelFactory, + Factory, + FileSystemStorage, + SubFactory, + pre_save, + ) + + from article.models import Article + + STORAGE = FileSystemStorage(root_path=settings.MEDIA_ROOT, rel_path="tmp") + + class ArticleFactory(DjangoModelFactory): + title = Factory.sentence() + slug = Factory.slug() + content = Factory.text() + image = Factory.png_file(storage=STORAGE) + pub_date = Factory.date() + safe_for_work = Factory.pybool() + minutes_to_read = Factory.pyint(min_value=1, max_value=10) + author = SubFactory(UserFactory) + + class Meta: + model = Article + +**Usage example** + +.. code-block:: python + + article = ArticleFactory() # Create one article + articles = ArticleFactory.create_batch(5) # Create 5 articles + +Pydantic example +---------------- + +.. code-block:: python + + from pathlib import Path + + from fake import Factory, FileSystemStorage, ModelFactory, SubFactory + + from article.models import Article + + BASE_DIR = Path(__file__).resolve().parent.parent + MEDIA_ROOT = BASE_DIR / "media" + STORAGE = FileSystemStorage(root_path=MEDIA_ROOT, rel_path="tmp") + + class ArticleFactory(ModelFactory): + id = Factory.pyint() + title = Factory.sentence() + slug = Factory.slug() + content = Factory.text() + image = Factory.png_file(storage=STORAGE) + pub_date = Factory.date() + safe_for_work = Factory.pybool() + minutes_to_read = Factory.pyint(min_value=1, max_value=10) + author = SubFactory(UserFactory) + + class Meta: + model = Article + +*Used just like in previous example.* + +TortoiseORM example +------------------- + +.. code-block:: python + + from pathlib import Path + + from fake import Factory, FileSystemStorage, SubFactory, TortoiseModelFactory + + from article.models import Article, User + + # Build paths inside the project like this: BASE_DIR / 'subdir'. + BASE_DIR = Path(__file__).resolve().parent.parent + MEDIA_ROOT = BASE_DIR / "media" + + STORAGE = FileSystemStorage(root_path=MEDIA_ROOT, rel_path="tmp") + + class ArticleFactory(TortoiseModelFactory): + id = Factory.pyint() + title = Factory.sentence() + slug = Factory.slug() + content = Factory.text() + image = Factory.png_file(storage=STORAGE) + pub_date = Factory.date_time() + safe_for_work = Factory.pybool() + minutes_to_read = Factory.pyint(min_value=1, max_value=10) + author = SubFactory(UserFactory) + + class Meta: + model = Article + +*Used just like in previous example.* diff --git a/docs/recipes.rst b/docs/recipes.rst index b5b38f3..7352c9a 100644 --- a/docs/recipes.rst +++ b/docs/recipes.rst @@ -1,2 +1,498 @@ Recipes ======= +**Imports and initialization** + +.. code-block:: python + + from fake import Faker + + FAKER = Faker() + +---- + +**first_name** + +Returns a random first name. + +.. code-block:: python + + FAKER.first_name() + +---- + +**last_name** + +Returns a random last name. + +.. code-block:: python + + FAKER.last_name() + +---- + +**name** + +Returns a random full name. + +.. code-block:: python + + FAKER.name() + +---- + +**word** + +Returns a random word. + +.. code-block:: python + + FAKER.word() + +---- + +**words** + +Returns a list of ``nb`` random words. + +.. code-block:: python + + FAKER.words() + +Arguments: + +- ``nb`` (type: ``int``, default value: ``5``) is an optional argument. + +---- + +**sentence** + +Returns a random sentence with ``nb_words`` number of words. + +.. code-block:: python + + FAKER.sentence() + +Arguments: + +- ``nb_words`` (type: ``int``, default value: ``5``) is an optional argument. + +---- + +**sentences** + +Returns ``nb`` number of random sentences. + +.. code-block:: python + + FAKER.sentences() + +Arguments: + +- ``nb`` (type: ``int``, default value: ``3``) is an optional argument. + +---- + +**paragraph** + +Returns a random paragraph with ``nb_sentences`` number of sentences. + +.. code-block:: python + + FAKER.paragraph() + +Arguments: + +- ``nb_sentences`` (type: ``int``, default value: ``5``) is an optional + argument. + +---- + +**paragraphs** + +Returns ``nb`` number of random paragraphs. + +.. code-block:: python + + FAKER.paragraphs() + +Arguments: + +- ``nb`` (type: ``int``, default value: ``3``) is an optional argument. + +---- + +**text** + +Returns random text with up to ``nb_chars`` characters. + +.. code-block:: python + + FAKER.text() + +Arguments: + +- ``nb_chars`` (type: ``int``, default value: ``200``) is an optional argument. + +---- + +**texts** + +Returns ``nb`` number of random texts. + +.. code-block:: python + + FAKER.texts() + +Arguments: + +- ``nb`` (type: ``int``, default value: ``3``) is an optional argument. + +---- + +**file_name** + +Returns a random file name with the given extension. + +.. code-block:: python + + FAKER.file_name() + +Arguments: + +- ``extension`` (type: ``str``, default value: ``txt``) is an optional + argument. + +---- + +**email** + +Returns a random email with the specified domain. + +.. code-block:: python + + FAKER.email() + +Arguments: + +- ``domain`` (type: ``str``, default value: ``example.com``) is an optional + argument. + +---- + +**url** + +Returns a random URL. + +.. code-block:: python + + FAKER.url() + +Arguments: + +- ``protocols`` (type: ``Optional[Tuple[str]]``, default value: ``None``) is + an optional argument. +- ``tlds`` (type: ``Optional[Tuple[str]]``, default value: ``None``) is + an optional argument. +- ``suffixes`` (type: ``Optional[Tuple[str]]``, default value: ``None``) is + an optional argument. + +---- + +**pyint** + +Returns a random integer between ``min_value`` and ``max_value``. + +.. code-block:: python + + FAKER.pyint() + +Arguments: + +- ``min_value`` (type: ``int``, default value: ``0``) is an optional argument. +- ``max_value`` (type: ``int``, default value: ``9999``) is an optional + argument. + +---- + +**pybool** + +Returns a random boolean value. + +.. code-block:: python + + FAKER.pybool() + +---- + +**pystr** + +Returns a random string of ``nb_chars`` length. + +.. code-block:: python + + FAKER.pystr() + +Arguments: + +- ``nb_chars`` (type: ``int``, default value: ``20``) is an optional argument. + +---- + +**pyfloat** + +Returns a random float between ``min_value`` and ``max_value``. + +.. code-block:: python + + FAKER.pyfloat() + +Arguments: + +- ``min_value`` (type: ``float``, default value: ``0.0``) is an optional + argument. +- ``max_value`` (type: ``float``, default value: ``10.00``) is an optional + argument. + +---- + +**ipv4** + +Returns a random IPv4 address. + +.. code-block:: python + + FAKER.ipv4() + +---- + +**date_between** + +Generates a random date between ``start_date`` and ``end_date``. + +.. code-block:: python + + FAKER.date_between(start_date="-1d", end_date="+1d") + +Arguments: + +- ``start_date`` (type: ``str``) is a required argument. +- ``end_date`` (type: ``str``, default value: ``+0d``) is an optional + argument. + +---- + +**date_time_between** + +Generates a random datetime between ``start_date`` and ``end_date``. + +.. code-block:: python + + FAKER.date_time_between(start_date="-1d", end_date="+1d") + +Arguments: + +- ``start_date`` (type: ``str``) is a required argument. +- ``end_date`` (type: ``str``, default value: ``+0d``) is an optional + argument. + +---- + +**pdf** + +Generates a content (``bytes``) of a PDF document. + +.. code-block:: python + + FAKER.pdf() + +Arguments: + +- ``nb_pages`` (type: ``int``, default value: ``1``) is an optional argument. +- ``texts`` (type: ``List[str]``, default value: ``None``) is an optional + argument. +- ``generator`` + (type: ``Union[Type[TextPdfGenerator], Type[GraphicPdfGenerator]]``, + default value: ``GraphicPdfGenerator``) is an optional argument. + +.. note:: + + ``texts`` is valid only in case ``TextPdfGenerator`` is used. + +.. note:: + + Either ``nb_pages`` or ``texts`` shall be provided. ``nb_pages`` is by + default set to ``1``, but if ``texts`` is given, the value of ``nb_pages`` + is adjusted accordingly. + +---- + +**image** + +Generates a content (``bytes``) of a image of the specified format and colour. + +.. code-block:: python + + FAKER.image() # Supported formats are `png`, `svg`, `bmp` and `gif` + +Arguments: + +- ``image_format`` (type: ``str``, default value: ``png``) is an optional + argument. +- ``size`` (type: ``Tuple[int, int]``, default value: ``(100, 100)``) is an + optional argument. +- ``color`` (type: ``Tuple[int, int, int]``, default value: ``(0, 0, 255)``) + is an optional argument. + +---- + +**docx** + +Generates a content (``bytes``) of a DOCX document. + +.. code-block:: python + + FAKER.docx() + +Arguments: + +- ``nb_pages`` (type: ``int``, default value: ``1``) is an optional argument. +- ``texts`` (type: ``List[str]``, default value: ``None``) is an optional + argument. + +.. note:: + + Either ``nb_pages`` or ``texts`` shall be provided. ``nb_pages`` is by + default set to ``1``, but if ``texts`` is given, the value of ``nb_pages`` + is adjusted accordingly. + +---- + +**pdf_file** + +Generates a ``PDF`` file. + +.. code-block:: python + + FAKER.pdf_file() + +Arguments: + +.. note:: + + Accepts all arguments of ``pdf`` + the following: + +- ``storage`` (type: ``BaseStorage``, default value: ``None``) is an optional + argument. +- ``basename`` (type: ``str``, default value: ``None``) is an optional + argument. +- ``prefix`` (type: ``str``, default value: ``None``) is an optional argument. + +---- + +**png_file** + +Generates a ``PNG`` file. + +.. code-block:: python + + FAKER.png_file() + +Arguments: + +.. note:: + + Accepts all arguments of ``png`` + the following: + +- ``storage`` (type: ``BaseStorage``, default value: ``None``) is an optional + argument. +- ``basename`` (type: ``str``, default value: ``None``) is an optional + argument. +- ``prefix`` (type: ``str``, default value: ``None``) is an optional argument. + +---- + +**svg_file** + +Generates an ``SVG`` file. + +.. code-block:: python + + FAKER.svg_file() + +Arguments: + +.. note:: + + Accepts all arguments of ``svg`` + the following: + +- ``storage`` (type: ``BaseStorage``, default value: ``None``) is an optional + argument. +- ``basename`` (type: ``str``, default value: ``None``) is an optional + argument. +- ``prefix`` (type: ``str``, default value: ``None``) is an optional argument. + +---- + +**bmp_file** + +Generates a ``BMP`` file. + +.. code-block:: python + + FAKER.bmp_file() + +Arguments: + +.. note:: + + Accepts all arguments of ``bmp`` + the following: + +- ``storage`` (type: ``BaseStorage``, default value: ``None``) is an optional + argument. +- ``basename`` (type: ``str``, default value: ``None``) is an optional + argument. +- ``prefix`` (type: ``str``, default value: ``None``) is an optional argument. + +---- + +**gif_file** + +Generates a ``GIF`` file. + +.. code-block:: python + + FAKER.gif_file() + +Arguments: + +.. note:: + + Accepts all arguments of ``gif`` + the following: + +- ``storage`` (type: ``BaseStorage``, default value: ``None``) is an optional + argument. +- ``basename`` (type: ``str``, default value: ``None``) is an optional + argument. +- ``prefix`` (type: ``str``, default value: ``None``) is an optional argument. + +---- + +**txt_file** + +Generates a ``TXT`` file. + +.. code-block:: python + + FAKER.txt_file() + +Arguments: + +.. note:: + + Accepts all arguments of ``text`` + the following: + +- ``storage`` (type: ``BaseStorage``, default value: ``None``) is an optional + argument. +- ``basename`` (type: ``str``, default value: ``None``) is an optional + argument. +- ``prefix`` (type: ``str``, default value: ``None``) is an optional argument.