├── .coveralls.yml ├── .dockerignore ├── .env ├── .github └── workflows │ ├── gh-pages.yml │ └── test.yml ├── .gitignore ├── .matyan.ini ├── .pre-commit-config.yaml ├── .pre-commit-hooks.yaml ├── .readthedocs.yaml ├── .scrutinizer.yml ├── .secrets.baseline ├── CHANGELOG.rst ├── CODE_OF_CONDUCT.md ├── CODE_OF_CONDUCT.rst ├── CONTRIBUTING.rst ├── Dockerfile ├── LICENSE.rst ├── MANIFEST.in ├── Makefile ├── README.rst ├── SECURITY.md ├── SECURITY.rst ├── conftest.py ├── docs ├── Makefile ├── _static │ └── examples │ │ ├── creating_docx │ │ ├── docx_1.py │ │ ├── docx_2.py │ │ ├── docx_3.py │ │ └── docx_4.py │ │ ├── creating_images │ │ ├── augment_1.py │ │ ├── imgkit_1.py │ │ ├── imgkit_2.py │ │ ├── imgkit_3.py │ │ ├── imgkit_4.py │ │ ├── pillow_1.py │ │ ├── pillow_2.py │ │ ├── pillow_3.py │ │ ├── pillow_4.py │ │ ├── pillow_5.py │ │ ├── weasyprint_1.py │ │ └── weasyprint_2.py │ │ ├── creating_odt │ │ ├── odt_1.py │ │ ├── odt_2.py │ │ ├── odt_3.py │ │ └── odt_4.py │ │ ├── creating_pdf │ │ ├── pdfkit_1.py │ │ ├── pdfkit_2.py │ │ ├── pdfkit_3.py │ │ ├── pdfkit_4.py │ │ ├── pillow_1.py │ │ ├── pillow_2.py │ │ ├── pillow_3.py │ │ ├── pillow_4.py │ │ ├── pillow_5.py │ │ ├── reportlab_1.py │ │ └── reportlab_2.py │ │ ├── methodology │ │ ├── clean_up_files_1.py │ │ ├── clean_up_files_2.py │ │ ├── clean_up_files_3.py │ │ ├── create_docx_file_1.py │ │ ├── create_docx_file_2.py │ │ ├── create_docx_file_3.py │ │ ├── file_from_path_provider.py │ │ └── rand_file_from_dir_provider.py │ │ ├── quick_start │ │ ├── factory_import_and_init_1.py │ │ ├── factory_models_1.py │ │ └── import_and_init_1.py │ │ └── recipes │ │ ├── augment_file_from_dir_1.py │ │ ├── augment_file_from_dir_2.py │ │ ├── augment_file_from_dir_3.py │ │ ├── augment_file_from_dir_4.py │ │ ├── aws_s3_storage_1.py │ │ ├── aws_s3_storage_2.py │ │ ├── aws_s3_storage_3.py │ │ ├── aws_s3_storage_4.py │ │ ├── docx_file_1.py │ │ ├── docx_file_mixed_1.py │ │ ├── eml_file_1.py │ │ ├── eml_file_2.py │ │ ├── eml_file_3.py │ │ ├── eml_file_4.py │ │ ├── eml_file_5.py │ │ ├── factory_boy_factory_1.py │ │ ├── factory_boy_factory_2.py │ │ ├── factory_boy_factory_3.py │ │ ├── factory_boy_models_1.py │ │ ├── file_from_path_1.py │ │ ├── file_of_size_bin_1.py │ │ ├── file_of_size_txt_1.py │ │ ├── files_multiprocessing_1.py │ │ ├── files_multiprocessing_2.py │ │ ├── flexible_storage_1.py │ │ ├── generic_file_1.py │ │ ├── google_cloud_storage_1.py │ │ ├── google_cloud_storage_2.py │ │ ├── graphic_ico_file_1.py │ │ ├── graphic_jpeg_file_1.py │ │ ├── graphic_png_file_1.py │ │ ├── graphic_webp_file_1.py │ │ ├── imports_and_init_1.py │ │ ├── imports_and_init_2.py │ │ ├── mp3_file_1.py │ │ ├── mp3_file_custom_1.py │ │ ├── mp3_file_edge_tts_1.py │ │ ├── mp3_file_edge_tts_2.py │ │ ├── mp3_file_gtts_1.py │ │ ├── mp3_file_gtts_2.py │ │ ├── odt_file_mixed_1.py │ │ ├── pdf_file_1.py │ │ ├── pdf_file_pdfkit_1.py │ │ ├── pdf_file_pillow_1.py │ │ ├── pdf_file_pillow_2.py │ │ ├── pdf_file_reportlab_1.py │ │ ├── random_file_from_dir_1.py │ │ ├── raw_1.py │ │ ├── sftp_storage_1.py │ │ ├── txt_file_1.py │ │ ├── zip_file_1.py │ │ ├── zip_file_2.py │ │ ├── zip_file_3.py │ │ ├── zip_file_4.py │ │ ├── zip_file_5.py │ │ └── zip_file_6.py ├── changelog.rst ├── cli.rst ├── code_of_conduct.rst ├── concepts.rst ├── conf.py ├── conf.py.distrib ├── conftest.py ├── contributor_guidelines.rst ├── creating_docx.rst ├── creating_images.rst ├── creating_odt.rst ├── creating_pdf.rst ├── documentation.rst ├── faker_file.cli.rst ├── faker_file.contrib.pdf_file.rst ├── faker_file.contrib.rst ├── faker_file.providers.augment_file_from_dir.augmenters.rst ├── faker_file.providers.augment_file_from_dir.extractors.rst ├── faker_file.providers.augment_file_from_dir.rst ├── faker_file.providers.base.rst ├── faker_file.providers.helpers.rst ├── faker_file.providers.image.rst ├── faker_file.providers.mixins.rst ├── faker_file.providers.mp3_file.generators.rst ├── faker_file.providers.mp3_file.rst ├── faker_file.providers.pdf_file.generators.rst ├── faker_file.providers.pdf_file.rst ├── faker_file.providers.rst ├── faker_file.rst ├── faker_file.storages.rst ├── faker_file.tests.rst ├── index.rst ├── index.rst.distrib ├── llms.rst ├── make.bat ├── marytts.py ├── methodology.rst ├── package.rst ├── quick_start.rst ├── readme.rst ├── recipes.rst ├── security.rst ├── talks │ └── pygrunn_2023.rst └── test_docs.py ├── examples ├── __init__.py ├── customizations │ ├── __init__.py │ └── marytts_mp3_generator │ │ ├── README.rst │ │ └── __init__.py ├── django_example │ ├── README.rst │ ├── __init__.py │ ├── demo.ipynb │ ├── demo_europython_2023.ipynb │ ├── factories │ │ ├── __init__.py │ │ ├── auth_user.py │ │ └── upload_upload.py │ ├── manage.py │ ├── project │ │ ├── __init__.py │ │ ├── settings │ │ │ ├── __init__.py │ │ │ ├── base.py │ │ │ ├── core.py │ │ │ ├── dev.py │ │ │ ├── docs.py │ │ │ ├── local_settings.example │ │ │ └── testing.py │ │ ├── urls.py │ │ └── wsgi.py │ └── upload │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── api │ │ ├── __init__.py │ │ ├── serializers.py │ │ ├── tests.py │ │ ├── urls.py │ │ └── views.py │ │ ├── migrations │ │ ├── 0001_initial.py │ │ └── __init__.py │ │ └── models.py ├── requirements │ ├── common.in │ ├── common.txt │ ├── debug.in │ ├── debug.txt │ ├── deployment.in │ ├── deployment.txt │ ├── dev.in │ ├── dev.txt │ ├── django_4_2.in │ ├── django_4_2.txt │ ├── django_4_2_and_flask.in │ ├── django_4_2_and_flask.txt │ ├── django_5_0.in │ ├── django_5_0.txt │ ├── django_5_0_and_flask.in │ ├── django_5_0_and_flask.txt │ ├── django_5_1.in │ ├── django_5_1.txt │ ├── django_5_1_and_flask.in │ ├── django_5_1_and_flask.txt │ ├── docs.in │ ├── docs.txt │ ├── flask.in │ ├── flask.txt │ ├── ml.in │ ├── ml.txt │ ├── style_checkers.in │ ├── style_checkers.txt │ ├── test.in │ ├── test.txt │ ├── testing.in │ └── testing.txt └── sqlalchemy_example │ ├── README.rst │ ├── faker_file_admin │ ├── __init__.py │ ├── alembic.ini │ ├── alembic │ │ ├── README │ │ ├── __init__.py │ │ ├── env.py │ │ ├── script.py.mako │ │ └── versions │ │ │ ├── 2695cb77cdf2_create_product_table.py │ │ │ └── __init__.py │ ├── config.py │ ├── config_test.py │ ├── data.py │ ├── main.py │ ├── models.py │ ├── static │ │ └── favicon.ico │ └── templates │ │ ├── admin │ │ └── index.html │ │ └── tree_list.html │ ├── run_server.py │ └── sqlalchemy_factories │ ├── __init__.py │ └── faker_file_admin_upload.py ├── pyproject.toml ├── scripts └── generate_project_source_tree.py ├── setup.cfg ├── setup.py ├── src └── faker_file │ ├── __init__.py │ ├── base.py │ ├── cli │ ├── __init__.py │ ├── command.py │ └── helpers.py │ ├── constants.py │ ├── contrib │ ├── __init__.py │ ├── docx_file.py │ ├── image │ │ ├── __init__.py │ │ ├── imgkit_snippets.py │ │ ├── pil_snippets.py │ │ └── weasyprint_snippets.py │ ├── odt_file.py │ └── pdf_file │ │ ├── __init__.py │ │ ├── pdfkit_snippets.py │ │ ├── pil_snippets.py │ │ └── reportlab_snippets.py │ ├── helpers.py │ ├── providers │ ├── __init__.py │ ├── augment_file_from_dir │ │ ├── __init__.py │ │ ├── augmenters │ │ │ ├── __init__.py │ │ │ ├── nlpaug_augmenter.py │ │ │ └── textaugment_augmenter.py │ │ └── extractors │ │ │ ├── __init__.py │ │ │ └── tika_extractor.py │ ├── augment_image_from_path.py │ ├── augment_random_image_from_dir.py │ ├── base │ │ ├── __init__.py │ │ ├── image_generator.py │ │ ├── mp3_generator.py │ │ ├── pdf_generator.py │ │ ├── text_augmenter.py │ │ └── text_extractor.py │ ├── bin_file.py │ ├── bmp_file.py │ ├── csv_file.py │ ├── docx_file.py │ ├── eml_file.py │ ├── epub_file.py │ ├── file_from_path.py │ ├── file_from_url.py │ ├── generic_file.py │ ├── gif_file.py │ ├── helpers │ │ ├── __init__.py │ │ └── inner.py │ ├── ico_file.py │ ├── image │ │ ├── __init__.py │ │ ├── augment.py │ │ ├── imgkit_generator.py │ │ ├── pil_generator.py │ │ └── weasyprint_generator.py │ ├── jpeg_file.py │ ├── json_file.py │ ├── mixins │ │ ├── __init__.py │ │ ├── graphic_image_mixin.py │ │ ├── image_mixin.py │ │ └── tablular_data_mixin.py │ ├── mp3_file │ │ ├── __init__.py │ │ └── generators │ │ │ ├── __init__.py │ │ │ ├── edge_tts_generator.py │ │ │ └── gtts_generator.py │ ├── odp_file.py │ ├── ods_file.py │ ├── odt_file.py │ ├── pdf_file │ │ ├── __init__.py │ │ └── generators │ │ │ ├── __init__.py │ │ │ ├── pdfkit_generator.py │ │ │ ├── pil_generator.py │ │ │ └── reportlab_generator.py │ ├── png_file.py │ ├── pptx_file.py │ ├── random_file_from_dir.py │ ├── rtf_file.py │ ├── svg_file.py │ ├── tar_file.py │ ├── tiff_file.py │ ├── txt_file.py │ ├── webp_file.py │ ├── xlsx_file.py │ ├── xml_file.py │ └── zip_file.py │ ├── registry.py │ ├── storages │ ├── __init__.py │ ├── aws_s3.py │ ├── azure_cloud_storage.py │ ├── base.py │ ├── cloud.py │ ├── filesystem.py │ ├── google_cloud_storage.py │ ├── pathy_based │ │ ├── __init__.py │ │ ├── aws_s3.py │ │ ├── azure_cloud_storage.py │ │ ├── cloud.py │ │ ├── google_cloud_storage.py │ │ └── helpers.py │ └── sftp_storage.py │ └── tests │ ├── __init__.py │ ├── _conftest.py │ ├── data.py │ ├── sftp_server.py │ ├── test_augment.py │ ├── test_augment_file_from_dir_provider.py │ ├── test_base.py │ ├── test_cli.py │ ├── test_data_integrity.py │ ├── test_django_integration.py │ ├── test_helpers.py │ ├── test_providers.py │ ├── test_registry.py │ ├── test_sftp_server.py │ ├── test_sftp_storage.py │ ├── test_sqlalchemy_integration.py │ ├── test_storages.py │ ├── texts.py │ └── utils.py ├── tests.coveragerc └── tox.ini /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: github-actions 2 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | .benchmarks 2 | .pytest_cache 3 | .tox 4 | build 5 | codebin 6 | dist 7 | docs 8 | docs_src 9 | forks 10 | htmlcov 11 | node_modules 12 | releases 13 | vagrant 14 | -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | GITHUB_TOKEN 2 | COVERALLS_REPO_TOKEN 3 | -------------------------------------------------------------------------------- /.github/workflows/gh-pages.yml: -------------------------------------------------------------------------------- 1 | name: Deploy llms.txt 2 | 3 | permissions: 4 | contents: write # Required to push commits 5 | pages: write # If you’re deploying to GitHub Pages 6 | 7 | on: 8 | push: 9 | branches: [ dev ] 10 | 11 | jobs: 12 | deploy: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v4 16 | - name: Set up Python 17 | uses: actions/setup-python@v5 18 | with: { python-version: '3.12' } 19 | - name: Install docs deps 20 | run: pip install -r examples/requirements/docs.txt 21 | - name: Build llms.txt 22 | # run: sphinx-build -n -D master_doc=llms -b text docs build/text llms.rst 23 | run: sphinx-build -n -b text docs build/text 24 | - name: Publish 25 | uses: peaceiris/actions-gh-pages@v4 26 | with: 27 | github_token: ${{ secrets.GITHUB_TOKEN }} 28 | publish_branch: gh-pages 29 | publish_dir: build/text 30 | allow_empty_commit: true 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | .hgignore~ 3 | .gitignore~ 4 | .hg/ 5 | .hgtags 6 | .tox/ 7 | .cache/ 8 | .coverage* 9 | !.coveragerc 10 | /htmlcov/ 11 | *.py,cover 12 | .idea/ 13 | .pytest_cache/ 14 | /coverage.xml 15 | .eggs/ 16 | 17 | MANIFEST.in~ 18 | codebin/ 19 | /tmp/ 20 | .zip 21 | /examples/db/ 22 | /var/ 23 | /examples/django_example/project/media/ 24 | /examples/django_example/project/static/ 25 | /examples/sqlalchemy_example/tmp/ 26 | /examples/tmp/ 27 | /examples/logs/ 28 | /builddocs/ 29 | /docs/_build/ 30 | /builddocs.zip 31 | /build/ 32 | /dist/ 33 | faker_file.egg-info 34 | matyan.log* 35 | db.sqlite3 36 | sample_db.sqlite 37 | local_settings.py 38 | /prof/ 39 | *.cast 40 | .ipynb_checkpoints/ 41 | .scannerwork/ 42 | tika-server.jar 43 | -------------------------------------------------------------------------------- /.matyan.ini: -------------------------------------------------------------------------------- 1 | [BranchTypes] 2 | feature: Feature 3 | bugfix: Bugfix 4 | hotfix: Hotfix 5 | deprecation: Deprecation 6 | 7 | [OtherBranchType] 8 | other: Other 9 | 10 | [Unreleased] 11 | unreleased: Unreleased 12 | 13 | [IgnoreCommits] 14 | exact: more 15 | clean up 16 | code comments 17 | more on docs 18 | repo 19 | working 20 | more on 21 | wip 22 | commit 23 | prefix: more on 24 | continue on 25 | prepare 26 | prpare 27 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | exclude: "^docs/|/migrations/" 2 | default_stages: [ pre-commit, pre-push ] 3 | default_language_version: 4 | python: python3 5 | 6 | repos: 7 | 8 | - repo: local 9 | hooks: 10 | - id: detect-secrets 11 | name: Detect secrets 12 | language: python 13 | entry: detect-secrets-hook 14 | args: ['--baseline', '.secrets.baseline'] 15 | 16 | - id: doc8 17 | name: Doc8 linter 18 | language: python 19 | entry: doc8 20 | args: [] 21 | 22 | - repo: https://github.com/pre-commit/pre-commit-hooks 23 | rev: v5.0.0 24 | hooks: 25 | - id: trailing-whitespace 26 | exclude: "data/" 27 | 28 | - id: end-of-file-fixer 29 | - id: check-yaml 30 | - id: check-toml 31 | - id: check-added-large-files 32 | - id: debug-statements 33 | - id: check-merge-conflict 34 | 35 | # - repo: https://github.com/psf/black 36 | # rev: 24.4.2 37 | # hooks: 38 | # - id: black 39 | # name: black 40 | # files: . 41 | # args: [ "--config", "pyproject.toml" ] 42 | 43 | # - repo: https://github.com/pycqa/isort 44 | # rev: 5.13.2 45 | # hooks: 46 | # - id: isort 47 | # name: isort 48 | # files: . 49 | # args: [ "--settings-path", "pyproject.toml", "--profile=black" ] 50 | 51 | - repo: https://github.com/charliermarsh/ruff-pre-commit 52 | rev: v0.7.3 53 | hooks: 54 | - id: ruff 55 | name: lint 56 | files: . 57 | args: [ "--config", "pyproject.toml", "--fix" ] 58 | 59 | # - repo: https://github.com/asottile/pyupgrade 60 | # rev: v3.2.0 61 | # hooks: 62 | # - id: pyupgrade 63 | # args: [ --py310-plus ] 64 | # 65 | # - repo: https://github.com/adamchainz/django-upgrade 66 | # rev: 1.11.0 67 | # hooks: 68 | # - id: django-upgrade 69 | # args: [ --target-version, "3.2" ] 70 | -------------------------------------------------------------------------------- /.pre-commit-hooks.yaml: -------------------------------------------------------------------------------- 1 | - id: detect-secrets 2 | name: Detect secrets 3 | description: Detects high entropy strings that are likely to be passwords. 4 | entry: detect-secrets-hook 5 | language: python 6 | # for backward compatibility 7 | files: .* 8 | 9 | - id: doc8 10 | name: doc8 11 | description: This hook runs doc8 for linting docs 12 | entry: doc8 13 | language: python 14 | files: \.rst$ 15 | require_serial: true 16 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # Read the Docs configuration file for Sphinx projects 2 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 3 | 4 | # Required 5 | version: 2 6 | 7 | # Optionally build your docs in additional formats such as PDF and ePub 8 | formats: 9 | - pdf 10 | - epub 11 | - htmlzip 12 | 13 | # Build documentation in the "docs/" directory with Sphinx 14 | sphinx: 15 | configuration: docs/conf.py 16 | # You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs 17 | # builder: "dirhtml" 18 | # Fail on all warnings to avoid broken references 19 | # fail_on_warning: true 20 | 21 | # Optional but recommended, declare the Python requirements required 22 | # to build your documentation 23 | # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html 24 | python: 25 | install: 26 | - requirements: examples/requirements/docs.txt 27 | 28 | # Set the OS, Python version and other tools you might need 29 | build: 30 | os: ubuntu-22.04 31 | tools: 32 | python: "3.12" 33 | # You can also specify other tool versions: 34 | # nodejs: "20" 35 | # rust: "1.70" 36 | # golang: "1.20" 37 | jobs: 38 | build: 39 | # The default commands for generating the HTML and pdf formats will still run. 40 | htmlzip: 41 | - echo "Override default build command for htmlzip format" 42 | - mkdir -p $READTHEDOCS_OUTPUT/html/ 43 | - sphinx-build -n -b text docs $READTHEDOCS_OUTPUT/html/ 44 | -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | checks: 2 | python: 3 | code_rating: true 4 | duplicate_code: true 5 | 6 | build: 7 | nodes: 8 | analysis: 9 | tests: 10 | override: 11 | - py-scrutinizer-run 12 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | CODE_OF_CONDUCT.rst -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # To build: 2 | # > docker build -f Dockerfile . 3 | FROM docker.io/ubuntu:18.04 4 | ENV PYTHONUNBUFFERED 1 5 | 6 | RUN apt update && apt install tzdata -y --no-install-recommends 7 | RUN apt install -y git nano mc apt-utils software-properties-common --no-install-recommends 8 | RUN add-apt-repository ppa:deadsnakes/ppa -y 9 | RUN apt update && apt install -y python3.6 python3.7 python3.8 python3.9 python3.10 python3-pip python3-setuptools --no-install-recommends 10 | 11 | ENTRYPOINT ["tail", "-f", "/dev/null"] 12 | -------------------------------------------------------------------------------- /LICENSE.rst: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | *Copyright (c) 2022 Artur Barseghyan* 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.rst 2 | include LICENSE.rst 3 | include CHANGELOG.rst 4 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | SECURITY.rst -------------------------------------------------------------------------------- /SECURITY.rst: -------------------------------------------------------------------------------- 1 | Security Policy 2 | =============== 3 | Reporting a Vulnerability 4 | ------------------------- 5 | **Do not report security issues on GitHub!** 6 | 7 | Please report security issues by emailing Artur Barseghyan 8 | . 9 | 10 | Supported Versions 11 | ------------------ 12 | **Make sure to use the latest version.** 13 | 14 | The two most recent ``faker-file`` release series receive security support. 15 | 16 | For example, during the development cycle leading to the release 17 | of ``faker-file`` 0.17.x, support will be provided for ``faker-file`` 0.16.x. 18 | 19 | Upon the release of ``faker-file`` 0.18.x, security support for ``faker-file`` 20 | 0.16.x will end. 21 | 22 | .. code-block:: text 23 | 24 | ┌─────────────────┬────────────────┐ 25 | │ Version │ Supported │ 26 | ├─────────────────┼────────────────┤ 27 | │ 0.18.x │ Yes │ 28 | ├─────────────────┼────────────────┤ 29 | │ 0.17.x │ Yes │ 30 | ├─────────────────┼────────────────┤ 31 | │ < 0.17 │ No │ 32 | └─────────────────┴────────────────┘ 33 | -------------------------------------------------------------------------------- /conftest.py: -------------------------------------------------------------------------------- 1 | from faker_file.tests._conftest import * # noqa 2 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_docx/docx_1.py: -------------------------------------------------------------------------------- 1 | # Required imports 2 | from faker import Faker 3 | from faker_file.providers.docx_file import DocxFileProvider 4 | 5 | FAKER = Faker() # Initialize Faker 6 | FAKER.add_provider(DocxFileProvider) # Register DocxFileProvider 7 | 8 | # Generate DOCX file 9 | docx_file = FAKER.docx_file() 10 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_docx/docx_2.py: -------------------------------------------------------------------------------- 1 | # Required imports 2 | from faker import Faker 3 | from faker_file.providers.docx_file import DocxFileProvider 4 | 5 | FAKER = Faker() # Initialize Faker 6 | FAKER.add_provider(DocxFileProvider) # Register DocxFileProvider 7 | 8 | # Generate DOCX file of 20,000 characters 9 | docx_file = FAKER.docx_file(max_nb_chars=20_000) 10 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_docx/docx_3.py: -------------------------------------------------------------------------------- 1 | # Required imports 2 | from faker import Faker 3 | from faker_file.providers.docx_file import DocxFileProvider 4 | 5 | FAKER = Faker() # Initialize Faker 6 | FAKER.add_provider(DocxFileProvider) # Register DocxFileProvider 7 | 8 | # Generate DOCX file, wrapping each line after 80 characters 9 | docx_file = FAKER.docx_file(wrap_chars_after=80) 10 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_docx/docx_4.py: -------------------------------------------------------------------------------- 1 | # Required imports 2 | from faker import Faker 3 | from faker_file.base import DynamicTemplate 4 | from faker_file.contrib.docx_file import ( 5 | add_page_break, 6 | add_paragraph, 7 | add_picture, 8 | add_table, 9 | ) 10 | from faker_file.providers.docx_file import DocxFileProvider 11 | 12 | FAKER = Faker() # Initialize Faker 13 | FAKER.add_provider(DocxFileProvider) # Register DocxFileProvider 14 | 15 | # Create a DOCX file with paragraph, picture, table and manual page breaks 16 | # in between the mentioned elements. The ``DynamicTemplate`` simply 17 | # accepts a list of callables (such as ``add_paragraph``, 18 | # ``add_page_break``) and dictionary to be later on fed to the callables 19 | # as keyword arguments for customising the default values. 20 | docx_file = FAKER.docx_file( 21 | content=DynamicTemplate( 22 | [ 23 | (add_paragraph, {}), # Add paragraph 24 | (add_page_break, {}), # Add page break 25 | (add_picture, {}), # Add picture 26 | (add_page_break, {}), # Add page break 27 | (add_table, {}), # Add table 28 | (add_page_break, {}), # Add page break 29 | ] 30 | ) 31 | ) 32 | 33 | # You could make the list as long as you like or simply multiply for 34 | # easier repetition as follows: 35 | docx_file = FAKER.docx_file( 36 | content=DynamicTemplate( 37 | [ 38 | (add_paragraph, {}), # Add paragraph 39 | (add_page_break, {}), # Add page break 40 | (add_picture, {}), # Add picture 41 | (add_page_break, {}), # Add page break 42 | (add_table, {}), # Add table 43 | (add_page_break, {}), # Add page break 44 | ] 45 | * 5 # Will repeat your config 5 times 46 | ) 47 | ) 48 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_images/augment_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.augment_image_from_path import ( 3 | AugmentImageFromPathProvider, 4 | ) 5 | from faker_file.providers.augment_random_image_from_dir import ( 6 | AugmentRandomImageFromDirProvider, 7 | ) 8 | from faker_file.providers.image.augment import ( 9 | add_brightness, 10 | decrease_contrast, 11 | flip_horizontal, 12 | flip_vertical, 13 | resize_height, 14 | resize_width, 15 | ) 16 | from faker_file.providers.png_file import GraphicPngFileProvider 17 | 18 | FAKER = Faker() 19 | FAKER.add_provider(AugmentImageFromPathProvider) 20 | FAKER.add_provider(AugmentRandomImageFromDirProvider) 21 | FAKER.add_provider(GraphicPngFileProvider) 22 | 23 | # Create a couple of graphic images to augment later on. 24 | FAKER.graphic_png_file(basename="01") # One named 01.png 25 | # And 5 more with random names. 26 | for __ in range(5): 27 | FAKER.graphic_png_file() 28 | 29 | # We assumed that directory "/tmp/tmp/" exists and contains 30 | # image files, among which "01.png". Augmentations will be applied 31 | # sequentially, one by one until all fulfilled. If you wish to apply only 32 | # a random number of augmentations, but not all, pass the `num_steps` 33 | # argument, with value less than the number of `augmentations` provided. 34 | augmented_image_file = FAKER.augment_image_from_path( 35 | path="/tmp/tmp/01.png", 36 | augmentations=[ 37 | (flip_horizontal, {}), 38 | (flip_vertical, {}), 39 | (decrease_contrast, {}), 40 | (add_brightness, {}), 41 | (resize_width, {"lower": 0.9, "upper": 1.1}), 42 | (resize_height, {"lower": 0.9, "upper": 1.1}), 43 | ], 44 | prefix="augmented_image_01_", 45 | # num_steps=3, 46 | ) 47 | 48 | augmented_random_image_file = FAKER.augment_random_image_from_dir( 49 | source_dir_path="/tmp/tmp/", 50 | augmentations=[ 51 | (flip_horizontal, {}), 52 | (flip_vertical, {}), 53 | (decrease_contrast, {}), 54 | (add_brightness, {}), 55 | (resize_width, {"lower": 0.9, "upper": 1.1}), 56 | (resize_height, {"lower": 0.9, "upper": 1.1}), 57 | ], 58 | prefix="augmented_random_image_", 59 | # num_steps=3, 60 | ) 61 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_images/imgkit_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.image.imgkit_generator import ImgkitImageGenerator 3 | from faker_file.providers.png_file import PngFileProvider 4 | 5 | FAKER = Faker() # Initialize Faker 6 | FAKER.add_provider(PngFileProvider) # Register PngFileProvider 7 | 8 | # Generate PNG file using `imgkit` 9 | pdf_file = FAKER.png_file(image_generator_cls=ImgkitImageGenerator) 10 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_images/imgkit_2.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.image.imgkit_generator import ImgkitImageGenerator 3 | from faker_file.providers.png_file import PngFileProvider 4 | 5 | FAKER = Faker() # Initialize Faker 6 | FAKER.add_provider(PngFileProvider) # Register PngFileProvider 7 | 8 | # Generate an image file, wrapping each line after 80 characters 9 | png_file = FAKER.png_file( 10 | image_generator_cls=ImgkitImageGenerator, wrap_chars_after=80 11 | ) 12 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_images/imgkit_3.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.image.imgkit_generator import ImgkitImageGenerator 3 | from faker_file.providers.png_file import PngFileProvider 4 | 5 | FAKER = Faker() # Initialize Faker 6 | FAKER.add_provider(PngFileProvider) # Register PngFileProvider 7 | 8 | # Generate an image file of 20,000 characters 9 | png_file = FAKER.png_file( 10 | image_generator_cls=ImgkitImageGenerator, max_nb_chars=20_000 11 | ) 12 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_images/imgkit_4.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.base import DynamicTemplate 3 | from faker_file.contrib.image.imgkit_snippets import ( 4 | add_paragraph, 5 | add_picture, 6 | add_table, 7 | ) 8 | from faker_file.providers.image.imgkit_generator import ImgkitImageGenerator 9 | from faker_file.providers.png_file import PngFileProvider 10 | 11 | FAKER = Faker() # Initialize Faker 12 | FAKER.add_provider(PngFileProvider) # Register PngFileProvider 13 | 14 | # Create an image file with a paragraph, a picture and a table. 15 | # The ``DynamicTemplate`` simply accepts a list of callables (such 16 | # as ``add_paragraph``, ``add_picture``) and dictionary to be later on 17 | # fed to the callables as keyword arguments for customising the default 18 | # values. 19 | png_file = FAKER.png_file( 20 | image_generator_cls=ImgkitImageGenerator, 21 | content=DynamicTemplate( 22 | [ 23 | (add_paragraph, {}), # Add paragraph 24 | (add_picture, {}), # Add picture 25 | (add_table, {}), # Add table 26 | ] 27 | ), 28 | ) 29 | 30 | # You could make the list as long as you like or simply multiply for 31 | # easier repetition as follows: 32 | png_file = FAKER.png_file( 33 | image_generator_cls=ImgkitImageGenerator, 34 | content=DynamicTemplate( 35 | [ 36 | (add_paragraph, {}), # Add paragraph 37 | (add_picture, {}), # Add picture 38 | (add_table, {}), # Add table 39 | ] 40 | * 5 # Will repeat your config 5 times 41 | ), 42 | ) 43 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_images/pillow_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.image.pil_generator import PilImageGenerator 3 | from faker_file.providers.png_file import PngFileProvider 4 | 5 | FAKER = Faker() 6 | FAKER.add_provider(PngFileProvider) 7 | 8 | png_file = FAKER.png_file(image_generator_cls=PilImageGenerator) 9 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_images/pillow_2.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.image.pil_generator import PilImageGenerator 3 | from faker_file.providers.png_file import PngFileProvider 4 | 5 | FAKER = Faker() 6 | FAKER.add_provider(PngFileProvider) 7 | 8 | png_file = FAKER.png_file( 9 | image_generator_cls=PilImageGenerator, 10 | image_generator_kwargs={ 11 | "encoding": "utf8", 12 | "font_size": 14, 13 | "page_width": 800, 14 | "page_height": 1200, 15 | "line_height": 16, 16 | "spacing": 5, 17 | }, 18 | wrap_chars_after=100, 19 | ) 20 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_images/pillow_3.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.base import DynamicTemplate 3 | from faker_file.contrib.image.pil_snippets import ( 4 | add_paragraph, 5 | add_picture, 6 | add_table, 7 | ) 8 | from faker_file.providers.image.pil_generator import PilImageGenerator 9 | from faker_file.providers.png_file import PngFileProvider 10 | 11 | FAKER = Faker() 12 | FAKER.add_provider(PngFileProvider) 13 | 14 | # Create an image file with paragraph, picture and table. 15 | # The ``DynamicTemplate`` simply accepts a list of callables (such as 16 | # ``add_paragraph``, ``add_picture``) and dictionary to be later on fed 17 | # to the callables as keyword arguments for customising the default 18 | # values. 19 | png_file = FAKER.png_file( 20 | image_generator_cls=PilImageGenerator, 21 | content=DynamicTemplate( 22 | [ 23 | (add_paragraph, {}), # Add paragraph 24 | (add_picture, {}), # Add picture 25 | (add_table, {}), # Add table 26 | ] 27 | ), 28 | ) 29 | 30 | # You could make the list as long as you like or simply multiply for 31 | # easier repetition as follows: 32 | png_file = FAKER.png_file( 33 | image_generator_cls=PilImageGenerator, 34 | content=DynamicTemplate( 35 | [ 36 | (add_paragraph, {}), # Add paragraph 37 | (add_picture, {}), # Add picture 38 | (add_table, {}), # Add table 39 | ] 40 | * 5 # Will repeat your config 5 times 41 | ), 42 | ) 43 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_images/pillow_4.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.png_file import GraphicPngFileProvider 3 | 4 | FAKER = Faker() # Initialize Faker 5 | FAKER.add_provider(GraphicPngFileProvider) # Register provider 6 | 7 | png_file = FAKER.graphic_png_file() 8 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_images/pillow_5.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.png_file import GraphicPngFileProvider 3 | 4 | FAKER = Faker() # Initialize Faker 5 | FAKER.add_provider(GraphicPngFileProvider) # Register provider 6 | 7 | png_file = FAKER.graphic_png_file(size=(800, 800)) 8 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_images/weasyprint_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.image.weasyprint_generator import ( 3 | WeasyPrintImageGenerator, 4 | ) 5 | from faker_file.providers.png_file import PngFileProvider 6 | 7 | FAKER = Faker() # Initialize Faker 8 | FAKER.add_provider(PngFileProvider) # Register provider 9 | 10 | # Generate image file using `WeasyPrint` 11 | png_file = FAKER.png_file(image_generator_cls=WeasyPrintImageGenerator) 12 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_images/weasyprint_2.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.base import DynamicTemplate 3 | from faker_file.contrib.image.weasyprint_snippets import ( 4 | add_paragraph, 5 | add_picture, 6 | add_table, 7 | ) 8 | from faker_file.providers.image.weasyprint_generator import ( 9 | WeasyPrintImageGenerator, 10 | ) 11 | from faker_file.providers.png_file import PngFileProvider 12 | 13 | FAKER = Faker() # Initialize Faker 14 | FAKER.add_provider(PngFileProvider) # Register provider 15 | 16 | # Create an image file with paragraph, picture and table. 17 | # The ``DynamicTemplate`` simply accepts a list of callables (such 18 | # as ``add_paragraph``, ``add_picture``) and dictionary to be later on 19 | # fed to the callables as keyword arguments for customising the default 20 | # values. 21 | png_file = FAKER.png_file( 22 | image_generator_cls=WeasyPrintImageGenerator, 23 | content=DynamicTemplate( 24 | [ 25 | (add_paragraph, {}), # Add paragraph 26 | (add_picture, {}), # Add picture 27 | (add_table, {}), # Add table 28 | ] 29 | ), 30 | ) 31 | 32 | # You could make the list as long as you like or simply multiply for 33 | # easier repetition as follows: 34 | png_file = FAKER.png_file( 35 | image_generator_cls=WeasyPrintImageGenerator, 36 | content=DynamicTemplate( 37 | [ 38 | (add_paragraph, {}), # Add paragraph 39 | (add_picture, {}), # Add picture 40 | (add_table, {}), # Add table 41 | ] 42 | * 5 # Will repeat your config 5 times 43 | ), 44 | ) 45 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_odt/odt_1.py: -------------------------------------------------------------------------------- 1 | # Required imports 2 | from faker import Faker 3 | from faker_file.providers.odt_file import OdtFileProvider 4 | 5 | FAKER = Faker() # Initialize Faker 6 | FAKER.add_provider(OdtFileProvider) # Register OdtFileProvider 7 | 8 | # Generate ODT file 9 | odt_file = FAKER.odt_file() 10 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_odt/odt_2.py: -------------------------------------------------------------------------------- 1 | # Required imports 2 | from faker import Faker 3 | from faker_file.providers.odt_file import OdtFileProvider 4 | 5 | FAKER = Faker() # Initialize Faker 6 | FAKER.add_provider(OdtFileProvider) # Register OdtFileProvider 7 | 8 | # Generate ODT file of 20,000 characters 9 | odt_file = FAKER.odt_file(max_nb_chars=20_000) 10 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_odt/odt_3.py: -------------------------------------------------------------------------------- 1 | # Required imports 2 | from faker import Faker 3 | from faker_file.providers.odt_file import OdtFileProvider 4 | 5 | FAKER = Faker() # Initialize Faker 6 | FAKER.add_provider(OdtFileProvider) # Register OdtFileProvider 7 | 8 | # Generate ODT file, wrapping each line after 80 characters 9 | odt_file = FAKER.odt_file(wrap_chars_after=80) 10 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_odt/odt_4.py: -------------------------------------------------------------------------------- 1 | # Required imports 2 | from faker import Faker 3 | from faker_file.base import DynamicTemplate 4 | from faker_file.contrib.odt_file import ( 5 | add_page_break, 6 | add_paragraph, 7 | add_picture, 8 | add_table, 9 | ) 10 | from faker_file.providers.odt_file import OdtFileProvider 11 | 12 | FAKER = Faker() # Initialize Faker 13 | FAKER.add_provider(OdtFileProvider) # Register OdtFileProvider 14 | 15 | # Create a ODT file with paragraph, picture, table and manual page breaks 16 | # in between the mentioned elements. The ``DynamicTemplate`` simply 17 | # accepts a list of callables (such as ``add_paragraph``, 18 | # ``add_page_break``) and dictionary to be later on fed to the callables 19 | # as keyword arguments for customising the default values. 20 | odt_file = FAKER.odt_file( 21 | content=DynamicTemplate( 22 | [ 23 | (add_paragraph, {}), # Add paragraph 24 | (add_page_break, {}), # Add page break 25 | (add_picture, {}), # Add picture 26 | (add_page_break, {}), # Add page break 27 | (add_table, {}), # Add table 28 | (add_page_break, {}), # Add page break 29 | ] 30 | ) 31 | ) 32 | 33 | # You could make the list as long as you like or simply multiply for 34 | # easier repetition as follows: 35 | odt_file = FAKER.odt_file( 36 | content=DynamicTemplate( 37 | [ 38 | (add_paragraph, {}), # Add paragraph 39 | (add_page_break, {}), # Add page break 40 | (add_picture, {}), # Add picture 41 | (add_page_break, {}), # Add page break 42 | (add_table, {}), # Add table 43 | (add_page_break, {}), # Add page break 44 | ] 45 | * 5 # Will repeat your config 5 times 46 | ) 47 | ) 48 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_pdf/pdfkit_1.py: -------------------------------------------------------------------------------- 1 | # Required imports 2 | from faker import Faker 3 | from faker_file.providers.pdf_file import PdfFileProvider 4 | from faker_file.providers.pdf_file.generators.pdfkit_generator import ( 5 | PdfkitPdfGenerator, 6 | ) 7 | 8 | FAKER = Faker() # Initialize Faker 9 | FAKER.add_provider(PdfFileProvider) # Register PdfFileProvider 10 | 11 | # Generate PDF file using `pdfkit` 12 | pdf_file = FAKER.pdf_file(pdf_generator_cls=PdfkitPdfGenerator) 13 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_pdf/pdfkit_2.py: -------------------------------------------------------------------------------- 1 | # Required imports 2 | from faker import Faker 3 | from faker_file.providers.pdf_file import PdfFileProvider 4 | from faker_file.providers.pdf_file.generators.pdfkit_generator import ( 5 | PdfkitPdfGenerator, 6 | ) 7 | 8 | FAKER = Faker() # Initialize Faker 9 | FAKER.add_provider(PdfFileProvider) # Register PdfFileProvider 10 | 11 | # Generate PDF file of 20,000 characters, using `pdfkit` 12 | pdf_file = FAKER.pdf_file( 13 | pdf_generator_cls=PdfkitPdfGenerator, max_nb_chars=20_000 14 | ) 15 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_pdf/pdfkit_3.py: -------------------------------------------------------------------------------- 1 | # Required imports 2 | from faker import Faker 3 | from faker_file.providers.pdf_file import PdfFileProvider 4 | from faker_file.providers.pdf_file.generators.pdfkit_generator import ( 5 | PdfkitPdfGenerator, 6 | ) 7 | 8 | FAKER = Faker() # Initialize Faker 9 | FAKER.add_provider(PdfFileProvider) # Register PdfFileProvider 10 | 11 | # Generate PDF file, wrapping each line after 80 characters, using `pdfkit` 12 | pdf_file = FAKER.pdf_file( 13 | pdf_generator_cls=PdfkitPdfGenerator, wrap_chars_after=80 14 | ) 15 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_pdf/pdfkit_4.py: -------------------------------------------------------------------------------- 1 | # Required imports 2 | from faker import Faker 3 | from faker_file.base import DynamicTemplate 4 | from faker_file.contrib.pdf_file.pdfkit_snippets import ( 5 | add_page_break, 6 | add_paragraph, 7 | add_picture, 8 | add_table, 9 | ) 10 | from faker_file.providers.pdf_file import PdfFileProvider 11 | from faker_file.providers.pdf_file.generators.pdfkit_generator import ( 12 | PdfkitPdfGenerator, 13 | ) 14 | 15 | FAKER = Faker() # Initialize Faker 16 | FAKER.add_provider(PdfFileProvider) # Register PdfFileProvider 17 | 18 | # Create a PDF file with paragraph, picture, table and manual page breaks 19 | # in between the mentioned elements. The ``DynamicTemplate`` simply 20 | # accepts a list of callables (such as ``add_paragraph``, 21 | # ``add_page_break``) and dictionary to be later on fed to the callables 22 | # as keyword arguments for customising the default values. 23 | pdf_file = FAKER.pdf_file( 24 | pdf_generator_cls=PdfkitPdfGenerator, 25 | content=DynamicTemplate( 26 | [ 27 | (add_paragraph, {}), # Add paragraph 28 | (add_page_break, {}), # Add page break 29 | (add_picture, {}), # Add picture 30 | (add_page_break, {}), # Add page break 31 | (add_table, {}), # Add table 32 | (add_page_break, {}), # Add page break 33 | ] 34 | ), 35 | ) 36 | 37 | # You could make the list as long as you like or simply multiply for 38 | # easier repetition as follows: 39 | pdf_file = FAKER.pdf_file( 40 | pdf_generator_cls=PdfkitPdfGenerator, 41 | content=DynamicTemplate( 42 | [ 43 | (add_paragraph, {}), # Add paragraph 44 | (add_page_break, {}), # Add page break 45 | (add_picture, {}), # Add picture 46 | (add_page_break, {}), # Add page break 47 | (add_table, {}), # Add table 48 | (add_page_break, {}), # Add page break 49 | ] 50 | * 5 # Will repeat your config 5 times 51 | ), 52 | ) 53 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_pdf/pillow_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.pdf_file import PdfFileProvider 3 | from faker_file.providers.pdf_file.generators.pil_generator import ( 4 | PilPdfGenerator, 5 | ) 6 | 7 | FAKER = Faker() 8 | FAKER.add_provider(PdfFileProvider) 9 | 10 | pdf_file = FAKER.pdf_file(pdf_generator_cls=PilPdfGenerator) 11 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_pdf/pillow_2.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.pdf_file import PdfFileProvider 3 | from faker_file.providers.pdf_file.generators.pil_generator import ( 4 | PilPdfGenerator, 5 | ) 6 | 7 | FAKER = Faker() 8 | FAKER.add_provider(PdfFileProvider) 9 | 10 | pdf_file = FAKER.pdf_file( 11 | pdf_generator_cls=PilPdfGenerator, 12 | pdf_generator_kwargs={ 13 | "encoding": "utf8", 14 | "font_size": 14, 15 | "page_width": 800, 16 | "page_height": 1200, 17 | "line_height": 16, 18 | "spacing": 5, 19 | }, 20 | wrap_chars_after=100, 21 | ) 22 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_pdf/pillow_3.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.base import DynamicTemplate 3 | from faker_file.contrib.pdf_file.pil_snippets import ( 4 | add_page_break, 5 | add_paragraph, 6 | add_picture, 7 | add_table, 8 | ) 9 | from faker_file.providers.pdf_file import PdfFileProvider 10 | from faker_file.providers.pdf_file.generators.pil_generator import ( 11 | PilPdfGenerator, 12 | ) 13 | 14 | FAKER = Faker() 15 | FAKER.add_provider(PdfFileProvider) 16 | 17 | # Create a PDF file with paragraph, picture, table and manual page breaks 18 | # in between the mentioned elements. The ``DynamicTemplate`` simply 19 | # accepts a list of callables (such as ``add_paragraph``, 20 | # ``add_page_break``) and dictionary to be later on fed to the callables 21 | # as keyword arguments for customising the default values. 22 | pdf_file = FAKER.pdf_file( 23 | pdf_generator_cls=PilPdfGenerator, 24 | content=DynamicTemplate( 25 | [ 26 | (add_paragraph, {}), # Add paragraph 27 | (add_page_break, {}), # Add page break 28 | (add_picture, {}), # Add picture 29 | (add_page_break, {}), # Add page break 30 | (add_table, {}), # Add table 31 | (add_page_break, {}), # Add page break 32 | ] 33 | ), 34 | ) 35 | 36 | # You could make the list as long as you like or simply multiply for 37 | # easier repetition as follows: 38 | pdf_file = FAKER.pdf_file( 39 | pdf_generator_cls=PilPdfGenerator, 40 | content=DynamicTemplate( 41 | [ 42 | (add_paragraph, {}), # Add paragraph 43 | (add_page_break, {}), # Add page break 44 | (add_picture, {}), # Add picture 45 | (add_page_break, {}), # Add page break 46 | (add_table, {}), # Add table 47 | (add_page_break, {}), # Add page break 48 | ] 49 | * 5 # Will repeat your config 5 times 50 | ), 51 | ) 52 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_pdf/pillow_4.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.pdf_file import GraphicPdfFileProvider 3 | 4 | FAKER = Faker() # Initialize Faker 5 | FAKER.add_provider(GraphicPdfFileProvider) # Register provider 6 | 7 | pdf_file = FAKER.graphic_pdf_file() 8 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_pdf/pillow_5.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.pdf_file import GraphicPdfFileProvider 3 | 4 | FAKER = Faker() # Initialize Faker 5 | FAKER.add_provider(GraphicPdfFileProvider) # Register provider 6 | 7 | pdf_file = FAKER.graphic_pdf_file(size=(800, 800)) 8 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_pdf/reportlab_1.py: -------------------------------------------------------------------------------- 1 | # Required imports 2 | from faker import Faker 3 | from faker_file.providers.pdf_file import PdfFileProvider 4 | from faker_file.providers.pdf_file.generators.reportlab_generator import ( 5 | ReportlabPdfGenerator, 6 | ) 7 | 8 | FAKER = Faker() # Initialize Faker 9 | FAKER.add_provider(PdfFileProvider) # Register provider 10 | 11 | # Generate PDF file using `reportlab` 12 | pdf_file = FAKER.pdf_file(pdf_generator_cls=ReportlabPdfGenerator) 13 | -------------------------------------------------------------------------------- /docs/_static/examples/creating_pdf/reportlab_2.py: -------------------------------------------------------------------------------- 1 | # Required imports 2 | from faker import Faker 3 | from faker_file.base import DynamicTemplate 4 | from faker_file.contrib.pdf_file.reportlab_snippets import ( 5 | add_page_break, 6 | add_paragraph, 7 | add_picture, 8 | add_table, 9 | ) 10 | from faker_file.providers.pdf_file import PdfFileProvider 11 | from faker_file.providers.pdf_file.generators.reportlab_generator import ( 12 | ReportlabPdfGenerator, 13 | ) 14 | 15 | FAKER = Faker() # Initialize Faker 16 | FAKER.add_provider(PdfFileProvider) # Register provider 17 | 18 | # Create a PDF file with paragraph, picture, table and manual page breaks 19 | # in between the mentioned elements. The ``DynamicTemplate`` simply 20 | # accepts a list of callables (such as ``add_paragraph``, 21 | # ``add_page_break``) and dictionary to be later on fed to the callables 22 | # as keyword arguments for customising the default values. 23 | pdf_file = FAKER.pdf_file( 24 | pdf_generator_cls=ReportlabPdfGenerator, 25 | content=DynamicTemplate( 26 | [ 27 | (add_paragraph, {}), # Add paragraph 28 | (add_page_break, {}), # Add page break 29 | (add_picture, {}), # Add picture 30 | (add_page_break, {}), # Add page break 31 | (add_table, {}), # Add table 32 | (add_page_break, {}), # Add page break 33 | ] 34 | ), 35 | ) 36 | 37 | # You could make the list as long as you like or simply multiply for 38 | # easier repetition as follows: 39 | pdf_file = FAKER.pdf_file( 40 | pdf_generator_cls=ReportlabPdfGenerator, 41 | content=DynamicTemplate( 42 | [ 43 | (add_paragraph, {}), # Add paragraph 44 | (add_page_break, {}), # Add page break 45 | (add_picture, {}), # Add picture 46 | (add_page_break, {}), # Add page break 47 | (add_table, {}), # Add table 48 | (add_page_break, {}), # Add page break 49 | ] 50 | * 5 # Will repeat your config 5 times 51 | ), 52 | ) 53 | -------------------------------------------------------------------------------- /docs/_static/examples/methodology/clean_up_files_1.py: -------------------------------------------------------------------------------- 1 | # Import instance at once 2 | from faker_file.registry import FILE_REGISTRY 3 | 4 | # Trigger the clean-up 5 | FILE_REGISTRY.clean_up() 6 | -------------------------------------------------------------------------------- /docs/_static/examples/methodology/clean_up_files_2.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.txt_file import TxtFileProvider 3 | from faker_file.registry import FILE_REGISTRY # Import instance at once 4 | 5 | FAKER = Faker() 6 | FAKER.add_provider(TxtFileProvider) 7 | 8 | # Create a file to remove 9 | txt_file = FAKER.txt_file() 10 | 11 | # We assume that there's an initialized `txt_file` instance to remove. 12 | FILE_REGISTRY.remove(txt_file) # Where file is an instance of ``StringValue`` 13 | -------------------------------------------------------------------------------- /docs/_static/examples/methodology/clean_up_files_3.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.txt_file import TxtFileProvider 3 | from faker_file.registry import FILE_REGISTRY # Import instance at once 4 | 5 | FAKER = Faker() 6 | FAKER.add_provider(TxtFileProvider) 7 | 8 | # Create a file to remove 9 | filename = str(FAKER.txt_file()) 10 | 11 | # We assume that there's an initialized `filename` (str) to remove. 12 | txt_file = FILE_REGISTRY.search(filename) 13 | if txt_file: 14 | FILE_REGISTRY.remove(txt_file) 15 | -------------------------------------------------------------------------------- /docs/_static/examples/methodology/create_docx_file_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.docx_file import DocxFileProvider 3 | 4 | FAKER = Faker() 5 | FAKER.add_provider(DocxFileProvider) 6 | 7 | docx_file = FAKER.docx_file(max_nb_chars=50) 8 | print(docx_file) # Sample value: 'tmp/tmpgdctmfbp.docx' 9 | print(docx_file.data["content"]) # Sample value: 'Learn where receive social.' 10 | print(docx_file.data["filename"]) # Sample value: '/tmp/tmp/tmpgdctmfbp.docx' 11 | -------------------------------------------------------------------------------- /docs/_static/examples/methodology/create_docx_file_2.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.docx_file import DocxFileProvider 3 | 4 | FAKER = Faker() 5 | FAKER.add_provider(DocxFileProvider) 6 | 7 | TEMPLATE = """ 8 | {{date}} {{city}}, {{country}} 9 | 10 | Hello {{name}}, 11 | 12 | {{text}} 13 | 14 | Address: {{address}} 15 | 16 | Best regards, 17 | 18 | {{name}} 19 | {{address}} 20 | {{phone_number}} 21 | """ 22 | 23 | docx_file = FAKER.docx_file(content=TEMPLATE) 24 | 25 | print(docx_file) # Sample value: 'tmp/tmpgdctmfbp.docx' 26 | print(docx_file.data["content"]) 27 | # Sample value below: 28 | # 2009-05-14 Pettyberg, Puerto Rico 29 | # Hello Lauren Williams, 30 | # 31 | # Everyone bill I information. Put particularly note language support 32 | # green. Game free family probably case day vote. 33 | # Commercial especially game heart. 34 | # 35 | # Address: 19017 Jennifer Drives 36 | # Jamesbury, MI 39121 37 | # 38 | # Best regards, 39 | # 40 | # Robin Jones 41 | # 4650 Paul Extensions 42 | # Port Johnside, VI 78151 43 | # 001-704-255-3093 44 | -------------------------------------------------------------------------------- /docs/_static/examples/methodology/create_docx_file_3.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.base import DynamicTemplate 3 | from faker_file.contrib.docx_file import ( 4 | add_page_break, 5 | add_paragraph, 6 | add_picture, 7 | add_table, 8 | ) 9 | from faker_file.providers.docx_file import DocxFileProvider 10 | 11 | FAKER = Faker() 12 | FAKER.add_provider(DocxFileProvider) 13 | 14 | # Create a DOCX file with paragraph, picture, table and manual page breaks 15 | # in between the mentioned elements. The ``DynamicTemplate`` simply 16 | # accepts a list of callables (such as ``add_paragraph``, 17 | # ``add_page_break``) and dictionary to be later on fed to the callables 18 | # as keyword arguments for customising the default values. 19 | docx_file = FAKER.docx_file( 20 | content=DynamicTemplate( 21 | [ 22 | (add_paragraph, {}), # Add paragraph 23 | (add_page_break, {}), # Add page break 24 | (add_picture, {}), # Add picture 25 | (add_page_break, {}), # Add page break 26 | (add_table, {}), # Add table 27 | (add_page_break, {}), # Add page break 28 | ] 29 | ) 30 | ) 31 | -------------------------------------------------------------------------------- /docs/_static/examples/methodology/file_from_path_provider.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.docx_file import DocxFileProvider 3 | from faker_file.providers.file_from_path import FileFromPathProvider 4 | 5 | FAKER = Faker() 6 | FAKER.add_provider(FileFromPathProvider) 7 | FAKER.add_provider(DocxFileProvider) 8 | 9 | # Create a file to use 10 | docx_file = FAKER.docx_file(basename="file") 11 | 12 | # We assume that directory "/tmp/tmp/" exists and contains a file named 13 | # "file.docx". 14 | docx_file_copy = FAKER.file_from_path( 15 | path="/tmp/tmp/file.docx", 16 | prefix="zzz", 17 | ) 18 | -------------------------------------------------------------------------------- /docs/_static/examples/methodology/rand_file_from_dir_provider.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.docx_file import DocxFileProvider 3 | from faker_file.providers.random_file_from_dir import RandomFileFromDirProvider 4 | 5 | FAKER = Faker() 6 | FAKER.add_provider(RandomFileFromDirProvider) 7 | FAKER.add_provider(DocxFileProvider) 8 | 9 | # Create files to use 10 | for __i in range(10): 11 | FAKER.docx_file(basename="file") 12 | 13 | # We assume that directory "/tmp/tmp/" exists and contains files with".docx" 14 | # extension. 15 | docx_file_copy = FAKER.random_file_from_dir( 16 | source_dir_path="/tmp/tmp/", 17 | prefix="zzz", 18 | ) 19 | -------------------------------------------------------------------------------- /docs/_static/examples/quick_start/factory_models_1.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | 4 | class Upload(models.Model): 5 | """Upload model.""" 6 | 7 | name = models.CharField(max_length=255, unique=True) 8 | description = models.TextField(null=True, blank=True) 9 | 10 | # File 11 | file = models.FileField(null=True) 12 | 13 | class Meta: 14 | app_label = "uploads" # Ignore this line when copying 15 | verbose_name = "Upload" 16 | verbose_name_plural = "Upload" 17 | 18 | def __str__(self): 19 | return self.name 20 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/augment_file_from_dir_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.augment_file_from_dir import ( 3 | AugmentFileFromDirProvider, 4 | ) 5 | from faker_file.providers.docx_file import DocxFileProvider 6 | from faker_file.providers.eml_file import EmlFileProvider 7 | from faker_file.providers.odt_file import OdtFileProvider 8 | from faker_file.providers.txt_file import TxtFileProvider 9 | 10 | FAKER = Faker() 11 | FAKER.add_provider(DocxFileProvider) 12 | FAKER.add_provider(TxtFileProvider) 13 | FAKER.add_provider(EmlFileProvider) 14 | FAKER.add_provider(OdtFileProvider) 15 | FAKER.add_provider(AugmentFileFromDirProvider) 16 | 17 | # Create files to test `augment_file_from_dir` with 18 | FAKER.docx_file() 19 | FAKER.eml_file() 20 | FAKER.odt_file() 21 | FAKER.txt_file() 22 | 23 | # We assume that directory "/tmp/tmp/" exists and contains 24 | # files of `DOCX`, `EML`, `EPUB`, `ODT`, `PDF`, `RTF` or `TXT` 25 | # formats. 26 | augmented_file = FAKER.augment_file_from_dir( 27 | source_dir_path="/tmp/tmp/", 28 | ) 29 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/augment_file_from_dir_2.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.augment_file_from_dir import ( 3 | AugmentFileFromDirProvider, 4 | ) 5 | from faker_file.providers.docx_file import DocxFileProvider 6 | from faker_file.providers.eml_file import EmlFileProvider 7 | from faker_file.providers.odt_file import OdtFileProvider 8 | from faker_file.providers.txt_file import TxtFileProvider 9 | 10 | FAKER = Faker() 11 | FAKER.add_provider(DocxFileProvider) 12 | FAKER.add_provider(TxtFileProvider) 13 | FAKER.add_provider(EmlFileProvider) 14 | FAKER.add_provider(OdtFileProvider) 15 | FAKER.add_provider(AugmentFileFromDirProvider) 16 | 17 | # Create files to test `augment_file_from_dir` with 18 | FAKER.docx_file() 19 | FAKER.eml_file() 20 | FAKER.odt_file() 21 | FAKER.txt_file() 22 | 23 | # We assume that directory "/tmp/tmp/" exists and contains 24 | # files of `DOCX` and `ODT` formats. 25 | augmented_file = FAKER.augment_file_from_dir( 26 | source_dir_path="/tmp/tmp/", 27 | extensions={"docx", "odt"}, # Pick only DOCX or ODT 28 | ) 29 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/augment_file_from_dir_3.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.augment_file_from_dir import ( 3 | AugmentFileFromDirProvider, 4 | ) 5 | from faker_file.providers.augment_file_from_dir.augmenters import ( 6 | nlpaug_augmenter, 7 | ) 8 | from faker_file.providers.docx_file import DocxFileProvider 9 | from faker_file.providers.eml_file import EmlFileProvider 10 | from faker_file.providers.odt_file import OdtFileProvider 11 | from faker_file.providers.txt_file import TxtFileProvider 12 | 13 | FAKER = Faker() 14 | FAKER.add_provider(DocxFileProvider) 15 | FAKER.add_provider(TxtFileProvider) 16 | FAKER.add_provider(EmlFileProvider) 17 | FAKER.add_provider(OdtFileProvider) 18 | FAKER.add_provider(AugmentFileFromDirProvider) 19 | 20 | # Create files to test `augment_file_from_dir` with 21 | FAKER.docx_file() 22 | FAKER.eml_file() 23 | FAKER.odt_file() 24 | FAKER.txt_file() 25 | 26 | # We assume that directory "/tmp/tmp/" exists and contains 27 | # files of `DOCX`, `EML`, `EPUB`, `ODT`, `PDF`, `RTF` or `TXT` 28 | # formats. 29 | augmented_file = FAKER.augment_file_from_dir( 30 | source_dir_path="/tmp/tmp/", 31 | text_augmenter_cls=nlpaug_augmenter.ContextualWordEmbeddingsAugmenter, 32 | text_augmenter_kwargs={ 33 | "model_path": "bert-base-cased", 34 | "action": "substitute", # or "insert" 35 | }, 36 | ) 37 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/augment_file_from_dir_4.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.augment_file_from_dir import ( 3 | AugmentFileFromDirProvider, 4 | ) 5 | from faker_file.providers.augment_file_from_dir.augmenters import ( 6 | textaugment_augmenter, 7 | ) 8 | from faker_file.providers.docx_file import DocxFileProvider 9 | from faker_file.providers.eml_file import EmlFileProvider 10 | from faker_file.providers.odt_file import OdtFileProvider 11 | from faker_file.providers.txt_file import TxtFileProvider 12 | 13 | FAKER = Faker() 14 | FAKER.add_provider(DocxFileProvider) 15 | FAKER.add_provider(TxtFileProvider) 16 | FAKER.add_provider(EmlFileProvider) 17 | FAKER.add_provider(OdtFileProvider) 18 | FAKER.add_provider(AugmentFileFromDirProvider) 19 | 20 | # Create files to test `augment_file_from_dir` with 21 | FAKER.docx_file() 22 | FAKER.eml_file() 23 | FAKER.odt_file() 24 | FAKER.txt_file() 25 | 26 | # We assume that directory "/tmp/tmp/" exists and contains 27 | # files of `DOCX`, `EML`, `EPUB`, `ODT`, `PDF`, `RTF` or `TXT` 28 | # formats. Valid values for `action` are: "random_deletion", 29 | # "random_insertion", "random_swap" and "synonym_replacement" (default). 30 | augmented_file = FAKER.augment_file_from_dir( 31 | source_dir_path="/tmp/tmp/", 32 | text_augmenter_cls=textaugment_augmenter.EDATextaugmentAugmenter, 33 | text_augmenter_kwargs={ 34 | "action": "synonym_replacement", 35 | }, 36 | ) 37 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/aws_s3_storage_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.txt_file import TxtFileProvider 3 | from faker_file.storages.aws_s3 import AWSS3Storage 4 | 5 | FAKER = Faker() 6 | FAKER.add_provider(TxtFileProvider) 7 | 8 | AWS_S3_STORAGE = AWSS3Storage( 9 | bucket_name="your-bucket-name", 10 | root_path="", 11 | rel_path="", 12 | ) 13 | 14 | txt_file = FAKER.txt_file(storage=AWS_S3_STORAGE) 15 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/aws_s3_storage_2.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.txt_file import TxtFileProvider 3 | from faker_file.storages.aws_s3 import AWSS3Storage 4 | 5 | FAKER = Faker() 6 | FAKER.add_provider(TxtFileProvider) 7 | 8 | AWS_S3_STORAGE = AWSS3Storage( 9 | bucket_name="your-bucket-name", 10 | root_path="", 11 | rel_path="user/uploads", 12 | ) 13 | 14 | txt_file = FAKER.txt_file(storage=AWS_S3_STORAGE) 15 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/aws_s3_storage_3.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | from faker import Faker 3 | from faker_file.providers.pdf_file import PdfFileProvider 4 | from faker_file.storages.aws_s3 import AWSS3Storage 5 | 6 | STORAGE = AWSS3Storage( 7 | bucket_name=settings.AWS_STORAGE_BUCKET_NAME, 8 | root_path="", 9 | rel_path="", 10 | ) 11 | 12 | FAKER = Faker() 13 | FAKER.add_provider(PdfFileProvider) 14 | 15 | pdf_file = FAKER.pdf_file(storage=STORAGE) 16 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/aws_s3_storage_4.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | from factory import Faker 3 | from factory.django import DjangoModelFactory 4 | from faker_file.providers.pdf_file import PdfFileProvider 5 | from faker_file.storages.aws_s3 import AWSS3Storage 6 | 7 | from upload.models import Upload 8 | 9 | STORAGE = AWSS3Storage( 10 | bucket_name=settings.AWS_STORAGE_BUCKET_NAME, 11 | root_path="", 12 | rel_path="", 13 | ) 14 | 15 | Faker.add_provider(PdfFileProvider) 16 | 17 | 18 | class UploadFactory(DjangoModelFactory): 19 | name = Faker("word") 20 | description = Faker("text") 21 | file = Faker("pdf_file", storage=STORAGE) 22 | 23 | class Meta: 24 | model = Upload 25 | 26 | 27 | # Usage example 28 | upload = UploadFactory() 29 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/docx_file_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.docx_file import DocxFileProvider 3 | 4 | FAKER = Faker() 5 | FAKER.add_provider(DocxFileProvider) 6 | 7 | docx_file = FAKER.docx_file( 8 | prefix="zzz", 9 | max_nb_chars=1_024, 10 | wrap_chars_after=80, 11 | ) 12 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/docx_file_mixed_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.base import DynamicTemplate 3 | from faker_file.contrib.docx_file import ( 4 | add_page_break, 5 | add_paragraph, 6 | add_picture, 7 | add_table, 8 | ) 9 | from faker_file.providers.docx_file import DocxFileProvider 10 | 11 | FAKER = Faker() # Initialize Faker 12 | FAKER.add_provider(DocxFileProvider) # Register DocxFileProvider 13 | 14 | # Create a DOCX file with paragraph, picture, table and manual page breaks 15 | # in between the mentioned elements. The ``DynamicTemplate`` simply 16 | # accepts a list of callables (such as ``add_paragraph``, 17 | # ``add_page_break``) and dictionary to be later on fed to the callables 18 | # as keyword arguments for customising the default values. 19 | docx_file = FAKER.docx_file( 20 | content=DynamicTemplate( 21 | [ 22 | (add_paragraph, {}), # Add paragraph 23 | (add_page_break, {}), # Add page break 24 | (add_picture, {}), # Add picture 25 | (add_page_break, {}), # Add page break 26 | (add_table, {}), # Add table 27 | (add_page_break, {}), # Add page break 28 | ] 29 | ) 30 | ) 31 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/eml_file_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.eml_file import EmlFileProvider 3 | 4 | FAKER = Faker() 5 | FAKER.add_provider(EmlFileProvider) 6 | 7 | eml_file = FAKER.eml_file( 8 | options={"create_inner_file_args": {"content": "Lorem ipsum"}} 9 | ) 10 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/eml_file_2.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.eml_file import EmlFileProvider 3 | from faker_file.providers.helpers.inner import create_inner_docx_file 4 | 5 | FAKER = Faker() 6 | FAKER.add_provider(EmlFileProvider) 7 | 8 | eml_file = FAKER.eml_file( 9 | prefix="zzz", 10 | options={ 11 | "count": 3, 12 | "create_inner_file_func": create_inner_docx_file, 13 | "create_inner_file_args": { 14 | "prefix": "xxx_", 15 | "max_nb_chars": 1_024, 16 | }, 17 | }, 18 | ) 19 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/eml_file_3.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.eml_file import EmlFileProvider 3 | from faker_file.providers.helpers.inner import ( 4 | create_inner_docx_file, 5 | create_inner_eml_file, 6 | ) 7 | 8 | FAKER = Faker() 9 | FAKER.add_provider(EmlFileProvider) 10 | 11 | eml_file = FAKER.eml_file( 12 | prefix="nested_level_0_", 13 | options={ 14 | "create_inner_file_func": create_inner_eml_file, 15 | "create_inner_file_args": { 16 | "prefix": "nested_level_1_", 17 | "options": { 18 | "create_inner_file_func": create_inner_eml_file, 19 | "create_inner_file_args": { 20 | "prefix": "nested_level_2_", 21 | "options": { 22 | "create_inner_file_func": create_inner_docx_file, 23 | }, 24 | }, 25 | }, 26 | }, 27 | }, 28 | ) 29 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/eml_file_4.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.eml_file import EmlFileProvider 3 | from faker_file.providers.helpers.inner import ( 4 | create_inner_docx_file, 5 | create_inner_epub_file, 6 | create_inner_txt_file, 7 | fuzzy_choice_create_inner_file, 8 | ) 9 | from faker_file.storages.filesystem import FileSystemStorage 10 | 11 | FAKER = Faker() 12 | FAKER.add_provider(EmlFileProvider) 13 | 14 | STORAGE = FileSystemStorage() 15 | 16 | kwargs = {"storage": STORAGE, "generator": FAKER} 17 | 18 | eml_file = FAKER.eml_file( 19 | prefix="zzz", 20 | options={ 21 | "count": 10, 22 | "create_inner_file_func": fuzzy_choice_create_inner_file, 23 | "create_inner_file_args": { 24 | "func_choices": [ 25 | (create_inner_docx_file, kwargs), 26 | (create_inner_epub_file, kwargs), 27 | (create_inner_txt_file, kwargs), 28 | ], 29 | }, 30 | }, 31 | ) 32 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/eml_file_5.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.eml_file import EmlFileProvider 3 | from faker_file.providers.helpers.inner import ( 4 | create_inner_docx_file, 5 | create_inner_epub_file, 6 | create_inner_txt_file, 7 | fuzzy_choice_create_inner_file, 8 | ) 9 | from faker_file.storages.filesystem import FileSystemStorage 10 | 11 | FAKER = Faker() 12 | FAKER.add_provider(EmlFileProvider) 13 | 14 | STORAGE = FileSystemStorage() 15 | 16 | kwargs = {"storage": STORAGE, "generator": FAKER} 17 | 18 | eml_file = FAKER.eml_file( 19 | cte_type="7bit", 20 | options={ 21 | "count": 10, 22 | "create_inner_file_func": fuzzy_choice_create_inner_file, 23 | "create_inner_file_args": { 24 | "func_choices": [ 25 | (create_inner_docx_file, kwargs), 26 | (create_inner_epub_file, kwargs), 27 | (create_inner_txt_file, kwargs), 28 | ], 29 | }, 30 | }, 31 | ) 32 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/factory_boy_factory_3.py: -------------------------------------------------------------------------------- 1 | from factory import Faker 2 | from factory.django import DjangoModelFactory 3 | from faker_file.providers.odt_file import OdtFileProvider 4 | 5 | from upload.models import Upload 6 | 7 | 8 | class UploadFactory(DjangoModelFactory): 9 | """Base Upload factory.""" 10 | 11 | name = Faker("text", max_nb_chars=100) 12 | description = Faker("text", max_nb_chars=1000) 13 | file = Faker("odt_file") 14 | 15 | class Meta: 16 | """Meta class.""" 17 | 18 | model = Upload 19 | 20 | 21 | # Example usage 22 | with Faker.override_default_locale("hy_AM"): # Set locale to Armenian 23 | Faker.add_provider(OdtFileProvider) 24 | upload = UploadFactory() 25 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/factory_boy_models_1.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | 4 | class Upload(models.Model): 5 | """Upload model.""" 6 | 7 | name = models.CharField(max_length=255, unique=True) 8 | description = models.TextField(null=True, blank=True) 9 | 10 | # File 11 | file = models.FileField(null=True) 12 | 13 | class Meta: 14 | app_label = "uploads" # Ignore this line when copying 15 | verbose_name = "Upload" 16 | verbose_name_plural = "Upload" 17 | 18 | def __str__(self): 19 | return self.name 20 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/file_from_path_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.docx_file import DocxFileProvider 3 | from faker_file.providers.file_from_path import FileFromPathProvider 4 | 5 | FAKER = Faker() 6 | FAKER.add_provider(DocxFileProvider) 7 | FAKER.add_provider(FileFromPathProvider) 8 | 9 | # Create a file to test `file_from_path` with. 10 | FAKER.docx_file(basename="file") 11 | 12 | # We assume that the file "/tmp/tmp/file.docx" exists. 13 | docx_file = FAKER.file_from_path( 14 | path="/tmp/tmp/file.docx", 15 | prefix="zzz", 16 | ) 17 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/file_of_size_bin_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.bin_file import BinFileProvider 3 | 4 | FAKER = Faker() 5 | FAKER.add_provider(BinFileProvider) 6 | 7 | bin_file = FAKER.bin_file(length=1024**2) # 1 Mb 8 | bin_file = FAKER.bin_file(length=3 * 1024**2) # 3 Mb 9 | bin_file = FAKER.bin_file(length=10 * 1024**2) # 10 Mb 10 | 11 | bin_file = FAKER.bin_file(length=1024) # 1 Kb 12 | bin_file = FAKER.bin_file(length=3 * 1024) # 3 Kb 13 | bin_file = FAKER.bin_file(length=10 * 1024) # 10 Kb 14 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/file_of_size_txt_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.txt_file import TxtFileProvider 3 | 4 | FAKER = Faker() 5 | FAKER.add_provider(TxtFileProvider) 6 | 7 | txt_file = FAKER.txt_file(max_nb_chars=1024**2) # 1 Mb 8 | txt_file = FAKER.txt_file(max_nb_chars=3 * 1024**2) # 3 Mb 9 | txt_file = FAKER.txt_file(max_nb_chars=10 * 1024**2) # 10 Mb 10 | 11 | txt_file = FAKER.txt_file(max_nb_chars=1024) # 1 Kb 12 | txt_file = FAKER.txt_file(max_nb_chars=3 * 1024) # 3 Kb 13 | txt_file = FAKER.txt_file(max_nb_chars=10 * 1024) # 10 Kb 14 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/files_multiprocessing_1.py: -------------------------------------------------------------------------------- 1 | from multiprocessing import Pool 2 | 3 | from faker import Faker 4 | from faker_file.providers.helpers.inner import create_inner_docx_file 5 | from faker_file.storages.filesystem import FileSystemStorage 6 | 7 | FAKER = Faker() 8 | STORAGE = FileSystemStorage() 9 | 10 | # Document template 11 | TEMPLATE = "Hey {{name}},\n{{text}},\nBest regards\n{{name}}" 12 | 13 | with Pool(processes=2) as pool: 14 | for _ in range(10): # Number of times we want to run our function 15 | pool.apply_async( 16 | create_inner_docx_file, 17 | # Apply async doesn't support kwargs. We have to pass all 18 | # arguments. 19 | [STORAGE, "mp", FAKER, None, None, TEMPLATE], 20 | ) 21 | pool.close() 22 | pool.join() 23 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/files_multiprocessing_2.py: -------------------------------------------------------------------------------- 1 | from multiprocessing import Pool 2 | 3 | from faker import Faker 4 | from faker_file.providers.helpers.inner import ( 5 | create_inner_docx_file, 6 | create_inner_epub_file, 7 | create_inner_pdf_file, 8 | create_inner_txt_file, 9 | fuzzy_choice_create_inner_file, 10 | ) 11 | from faker_file.storages.filesystem import FileSystemStorage 12 | 13 | FAKER = Faker() 14 | STORAGE = FileSystemStorage() 15 | 16 | # Document template 17 | TEMPLATE = """ 18 | {{date}} {{city}}, {{country}} 19 | 20 | Hello {{name}}, 21 | 22 | {{text}} {{text}} {{text}} 23 | 24 | {{text}} {{text}} {{text}} 25 | 26 | {{text}} {{text}} {{text}} 27 | 28 | Address: {{address}} 29 | 30 | Best regards, 31 | 32 | {{name}} 33 | {{address}} 34 | {{phone_number}} 35 | """ 36 | 37 | kwargs = {"storage": STORAGE, "generator": FAKER, "content": TEMPLATE} 38 | 39 | with Pool(processes=2) as pool: 40 | for _ in range(10): # Number of times we want to run our function 41 | pool.apply_async( 42 | fuzzy_choice_create_inner_file, 43 | [ 44 | [ 45 | (create_inner_docx_file, kwargs), 46 | (create_inner_epub_file, kwargs), 47 | (create_inner_pdf_file, kwargs), 48 | (create_inner_txt_file, kwargs), 49 | ] 50 | ], 51 | ) 52 | pool.close() 53 | pool.join() 54 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/flexible_storage_1.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | from django.core.files.storage import default_storage 3 | from faker_file.storages.aws_s3 import AWSS3Storage 4 | from faker_file.storages.filesystem import FileSystemStorage 5 | from storages.backends.s3boto3 import S3Boto3Storage 6 | 7 | # Faker doesn't know anything about Django. That's why, if we want to 8 | # support remote storages, we need to manually check which file storage 9 | # backend is used. If `Boto3` storage backend (of the `django-storages` 10 | # package) is used we use the correspondent `AWSS3Storage` class of the 11 | # `faker-file`. 12 | # Otherwise, fall back to native file system storage (`FileSystemStorage`) 13 | # of the `faker-file`. 14 | if isinstance(default_storage, S3Boto3Storage): 15 | STORAGE = AWSS3Storage( 16 | bucket_name=settings.AWS_STORAGE_BUCKET_NAME, 17 | credentials={ 18 | "key_id": settings.AWS_ACCESS_KEY_ID, 19 | "key_secret": settings.AWS_SECRET_ACCESS_KEY, 20 | }, 21 | root_path="", 22 | rel_path="tmp", 23 | ) 24 | else: 25 | STORAGE = FileSystemStorage( 26 | root_path=settings.MEDIA_ROOT, 27 | rel_path="tmp", 28 | ) 29 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/generic_file_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.generic_file import GenericFileProvider 3 | 4 | FAKER = Faker() 5 | FAKER.add_provider(GenericFileProvider) 6 | 7 | generic_file = FAKER.generic_file( 8 | content="

{{text}}

", 9 | extension="html", 10 | ) 11 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/google_cloud_storage_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.txt_file import TxtFileProvider 3 | from faker_file.storages.google_cloud_storage import GoogleCloudStorage 4 | 5 | FAKER = Faker() 6 | FAKER.add_provider(TxtFileProvider) 7 | 8 | GC_STORAGE = GoogleCloudStorage( 9 | bucket_name="your-bucket-name", 10 | root_path="", 11 | rel_path="", 12 | ) 13 | 14 | # txt_file = FAKER.txt_file(storage=GC_STORAGE) 15 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/google_cloud_storage_2.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.txt_file import TxtFileProvider 3 | from faker_file.storages.google_cloud_storage import GoogleCloudStorage 4 | 5 | FAKER = Faker() 6 | FAKER.add_provider(TxtFileProvider) 7 | 8 | GC_STORAGE = GoogleCloudStorage( 9 | bucket_name="your-bucket-name", 10 | root_path="", 11 | rel_path="user/uploads", 12 | ) 13 | 14 | # txt_file = FAKER.txt_file(storage=GC_STORAGE) 15 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/graphic_ico_file_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.ico_file import GraphicIcoFileProvider 3 | 4 | FAKER = Faker() 5 | FAKER.add_provider(GraphicIcoFileProvider) 6 | 7 | ico_file = FAKER.graphic_ico_file(size=(800, 800)) 8 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/graphic_jpeg_file_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.jpeg_file import GraphicJpegFileProvider 3 | 4 | FAKER = Faker() 5 | FAKER.add_provider(GraphicJpegFileProvider) 6 | 7 | jpeg_file = FAKER.graphic_jpeg_file(size=(800, 800)) 8 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/graphic_png_file_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.png_file import GraphicPngFileProvider 3 | 4 | FAKER = Faker() 5 | FAKER.add_provider(GraphicPngFileProvider) 6 | 7 | png_file = FAKER.graphic_png_file(size=(800, 800)) 8 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/graphic_webp_file_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.webp_file import GraphicWebpFileProvider 3 | 4 | FAKER = Faker() 5 | FAKER.add_provider(GraphicWebpFileProvider) 6 | 7 | webp_file = FAKER.graphic_webp_file(size=(800, 800)) 8 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/imports_and_init_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.txt_file import TxtFileProvider 3 | 4 | FAKER = Faker() 5 | FAKER.add_provider(TxtFileProvider) 6 | 7 | # Usage example 8 | txt_file = FAKER.txt_file(content="Lorem ipsum") 9 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/imports_and_init_2.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.txt_file import TxtFileProvider 3 | 4 | FAKER = Faker() 5 | 6 | # Usage example 7 | txt_file = TxtFileProvider(FAKER).txt_file(content="Lorem ipsum") 8 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/mp3_file_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.mp3_file import Mp3FileProvider 3 | 4 | FAKER = Faker() 5 | FAKER.add_provider(Mp3FileProvider) 6 | 7 | mp3_file = FAKER.mp3_file() 8 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/mp3_file_custom_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.base.mp3_generator import BaseMp3Generator 3 | from faker_file.providers.mp3_file import Mp3FileProvider 4 | from marytts import MaryTTS # Imaginary `marytts` Python library 5 | 6 | FAKER = Faker() 7 | FAKER.add_provider(Mp3FileProvider) 8 | 9 | 10 | # Define custom MP3 generator 11 | class MaryTtsMp3Generator(BaseMp3Generator): 12 | locale: str = "cmu-rms-hsmm" 13 | voice: str = "en_US" 14 | 15 | def handle_kwargs(self, **kwargs) -> None: 16 | # Since it's impossible to unify all TTS systems it's allowed 17 | # to pass arbitrary arguments to the `BaseMp3Generator` 18 | # constructor. Each implementation class contains its own 19 | # additional tuning arguments. Check the source code of the 20 | # implemented MP3 generators as an example. 21 | if "locale" in kwargs: 22 | self.locale = kwargs["locale"] 23 | if "voice" in kwargs: 24 | self.voice = kwargs["voice"] 25 | 26 | def generate(self) -> bytes: 27 | # Your implementation here. Note, that `self.content` 28 | # in this context is the text to make MP3 from. 29 | # `self.generator` would be the `Faker` or `Generator` 30 | # instance from which you could extract information on 31 | # active locale. 32 | # What comes below is pseudo implementation. 33 | mary_tts = MaryTTS(locale=self.locale, voice=self.voice) 34 | return mary_tts.synth_mp3(self.content) 35 | 36 | 37 | # Generate MP3 file from random text 38 | mp3_file = FAKER.mp3_file( 39 | mp3_generator_cls=MaryTtsMp3Generator, 40 | ) 41 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/mp3_file_edge_tts_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.mp3_file import Mp3FileProvider 3 | from faker_file.providers.mp3_file.generators.edge_tts_generator import ( 4 | EdgeTtsMp3Generator, 5 | ) 6 | 7 | FAKER = Faker() 8 | FAKER.add_provider(Mp3FileProvider) 9 | 10 | mp3_file = FAKER.mp3_file(mp3_generator_cls=EdgeTtsMp3Generator) 11 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/mp3_file_edge_tts_2.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.mp3_file import Mp3FileProvider 3 | from faker_file.providers.mp3_file.generators.edge_tts_generator import ( 4 | EdgeTtsMp3Generator, 5 | ) 6 | 7 | FAKER = Faker() 8 | FAKER.add_provider(Mp3FileProvider) 9 | 10 | mp3_file = FAKER.mp3_file( 11 | mp3_generator_cls=EdgeTtsMp3Generator, 12 | mp3_generator_kwargs={ 13 | "voice": "en-GB-LibbyNeural", 14 | }, 15 | ) 16 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/mp3_file_gtts_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.mp3_file import Mp3FileProvider 3 | from faker_file.providers.mp3_file.generators.gtts_generator import ( 4 | GttsMp3Generator, 5 | ) 6 | 7 | FAKER = Faker() 8 | FAKER.add_provider(Mp3FileProvider) 9 | 10 | mp3_file = FAKER.mp3_file(mp3_generator_cls=GttsMp3Generator) 11 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/mp3_file_gtts_2.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.mp3_file import Mp3FileProvider 3 | from faker_file.providers.mp3_file.generators.gtts_generator import ( 4 | GttsMp3Generator, 5 | ) 6 | 7 | FAKER = Faker() 8 | FAKER.add_provider(Mp3FileProvider) 9 | 10 | mp3_file = FAKER.mp3_file( 11 | mp3_generator_cls=GttsMp3Generator, 12 | mp3_generator_kwargs={ 13 | "lang": "en", 14 | "tld": "co.uk", 15 | }, 16 | ) 17 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/odt_file_mixed_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.base import DynamicTemplate 3 | from faker_file.contrib.odt_file import ( 4 | add_page_break, 5 | add_paragraph, 6 | add_picture, 7 | add_table, 8 | ) 9 | from faker_file.providers.odt_file import OdtFileProvider 10 | 11 | FAKER = Faker() # Initialize Faker 12 | FAKER.add_provider(OdtFileProvider) # Register OdtFileProvider 13 | 14 | # Create a ODT file with paragraph, picture, table and manual page breaks 15 | # in between the mentioned elements. The ``DynamicTemplate`` simply 16 | # accepts a list of callables (such as ``add_paragraph``, 17 | # ``add_page_break``) and dictionary to be later on fed to the callables 18 | # as keyword arguments for customising the default values. 19 | odt_file = FAKER.odt_file( 20 | content=DynamicTemplate( 21 | [ 22 | (add_paragraph, {}), # Add paragraph 23 | (add_page_break, {}), # Add page break 24 | (add_picture, {}), # Add picture 25 | (add_page_break, {}), # Add page break 26 | (add_table, {}), # Add table 27 | (add_page_break, {}), # Add page break 28 | ] 29 | ) 30 | ) 31 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/pdf_file_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.pdf_file import PdfFileProvider 3 | 4 | FAKER = Faker() 5 | FAKER.add_provider(PdfFileProvider) 6 | 7 | TEMPLATE = """ 8 | {{date}} {{city}}, {{country}} 9 | 10 | Hello {{name}}, 11 | 12 | {{text}} {{text}} {{text}} 13 | 14 | {{text}} {{text}} {{text}} 15 | 16 | {{text}} {{text}} {{text}} 17 | 18 | Address: {{address}} 19 | 20 | Best regards, 21 | 22 | {{name}} 23 | {{address}} 24 | {{phone_number}} 25 | """ 26 | 27 | pdf_file = FAKER.pdf_file(content=TEMPLATE, wrap_chars_after=80) 28 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/pdf_file_pdfkit_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.pdf_file import PdfFileProvider 3 | from faker_file.providers.pdf_file.generators.pdfkit_generator import ( 4 | PdfkitPdfGenerator, 5 | ) 6 | 7 | FAKER = Faker() 8 | FAKER.add_provider(PdfFileProvider) 9 | 10 | pdf_file = FAKER.pdf_file(pdf_generator_cls=PdfkitPdfGenerator) 11 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/pdf_file_pillow_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.pdf_file import GraphicPdfFileProvider 3 | 4 | FAKER = Faker() 5 | FAKER.add_provider(GraphicPdfFileProvider) 6 | 7 | pdf_file = FAKER.graphic_pdf_file() 8 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/pdf_file_pillow_2.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.pdf_file import GraphicPdfFileProvider 3 | 4 | FAKER = Faker() 5 | FAKER.add_provider(GraphicPdfFileProvider) 6 | 7 | pdf_file = FAKER.graphic_pdf_file(size=(800, 800)) 8 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/pdf_file_reportlab_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.pdf_file import PdfFileProvider 3 | from faker_file.providers.pdf_file.generators.reportlab_generator import ( 4 | ReportlabPdfGenerator, 5 | ) 6 | 7 | FAKER = Faker() 8 | FAKER.add_provider(PdfFileProvider) 9 | 10 | pdf_file = FAKER.pdf_file(pdf_generator_cls=ReportlabPdfGenerator) 11 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/random_file_from_dir_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.random_file_from_dir import RandomFileFromDirProvider 3 | from faker_file.providers.txt_file import TxtFileProvider 4 | 5 | FAKER = Faker() 6 | FAKER.add_provider(TxtFileProvider) 7 | FAKER.add_provider(RandomFileFromDirProvider) 8 | 9 | # Create files to test `random_file_from_dir` with 10 | for __i in range(5): 11 | FAKER.txt_file() 12 | 13 | # We assume that directory "/tmp/tmp/" exists and contains files. 14 | random_file = FAKER.random_file_from_dir( 15 | source_dir_path="/tmp/tmp/", 16 | prefix="zzz", 17 | ) 18 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/raw_1.py: -------------------------------------------------------------------------------- 1 | import os 2 | from io import BytesIO 3 | 4 | from django.test import TestCase 5 | from django.urls import reverse 6 | from faker import Faker 7 | from faker_file.providers.docx_file import DocxFileProvider 8 | from rest_framework.status import HTTP_201_CREATED 9 | 10 | from upload.models import Upload 11 | 12 | FAKER = Faker() 13 | FAKER.add_provider(DocxFileProvider) 14 | 15 | 16 | class UploadTestCase(TestCase): 17 | """Upload test case.""" 18 | 19 | def test_create_docx_upload(self) -> None: 20 | """Test create an Upload.""" 21 | url = reverse("api:upload-list") 22 | 23 | raw = FAKER.docx_file(raw=True) 24 | test_file = BytesIO(raw) 25 | test_file.name = os.path.basename(raw.data["filename"]) 26 | 27 | payload = { 28 | "name": FAKER.word(), 29 | "description": FAKER.paragraph(), 30 | "file": test_file, 31 | } 32 | 33 | response = self.client.post(url, payload, format="json") 34 | 35 | # Test if request is handled properly (HTTP 201) 36 | self.assertEqual(response.status_code, HTTP_201_CREATED) 37 | 38 | test_upload = Upload.objects.get(id=response.data["id"]) 39 | 40 | # Test if the name is properly recorded 41 | self.assertEqual(str(test_upload.name), payload["name"]) 42 | 43 | # Test if file name recorded properly 44 | self.assertEqual(str(test_upload.file.name), test_file.name) 45 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/sftp_storage_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.txt_file import TxtFileProvider 3 | from faker_file.storages.sftp_storage import SFTPStorage 4 | 5 | FAKER = Faker() 6 | FAKER.add_provider(TxtFileProvider) 7 | 8 | SFTP_STORAGE = SFTPStorage( 9 | host="your-sftp-host.domain", 10 | port=22, 11 | username="your-sftp-username", 12 | password="your-sftp-password", 13 | root_path="/dir-name", 14 | ) 15 | 16 | # txt_file = FAKER.txt_file(storage=SFTP_STORAGE) 17 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/txt_file_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.txt_file import TxtFileProvider 3 | 4 | FAKER = Faker() 5 | FAKER.add_provider(TxtFileProvider) 6 | 7 | txt_file = FAKER.txt_file(content="Lorem ipsum") 8 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/zip_file_1.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.zip_file import ZipFileProvider 3 | 4 | FAKER = Faker() 5 | FAKER.add_provider(ZipFileProvider) 6 | 7 | zip_file = FAKER.zip_file( 8 | options={"create_inner_file_args": {"content": "Lorem ipsum"}} 9 | ) 10 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/zip_file_2.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.helpers.inner import create_inner_docx_file 3 | from faker_file.providers.zip_file import ZipFileProvider 4 | 5 | FAKER = Faker() 6 | FAKER.add_provider(ZipFileProvider) 7 | 8 | zip_file = FAKER.zip_file( 9 | prefix="zzz", 10 | options={ 11 | "count": 3, 12 | "create_inner_file_func": create_inner_docx_file, 13 | "create_inner_file_args": { 14 | "prefix": "xxx_", 15 | "max_nb_chars": 1_024, 16 | }, 17 | "directory": "yyy", 18 | }, 19 | ) 20 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/zip_file_3.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.helpers.inner import create_inner_docx_file 3 | from faker_file.providers.zip_file import ZipFileProvider 4 | 5 | FAKER = Faker() 6 | FAKER.add_provider(ZipFileProvider) 7 | 8 | TEMPLATE = "Hey {{name}},\n{{text}},\nBest regards\n{{name}}" 9 | 10 | zip_file = FAKER.zip_file( 11 | options={ 12 | "count": 9, 13 | "create_inner_file_func": create_inner_docx_file, 14 | "create_inner_file_args": { 15 | "content": TEMPLATE, 16 | }, 17 | } 18 | ) 19 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/zip_file_4.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.helpers.inner import ( 3 | create_inner_docx_file, 4 | create_inner_zip_file, 5 | ) 6 | from faker_file.providers.zip_file import ZipFileProvider 7 | 8 | FAKER = Faker() 9 | FAKER.add_provider(ZipFileProvider) 10 | 11 | zip_file = FAKER.zip_file( 12 | prefix="nested_level_0_", 13 | options={ 14 | "create_inner_file_func": create_inner_zip_file, 15 | "create_inner_file_args": { 16 | "prefix": "nested_level_1_", 17 | "options": { 18 | "create_inner_file_func": create_inner_zip_file, 19 | "create_inner_file_args": { 20 | "prefix": "nested_level_2_", 21 | "options": { 22 | "create_inner_file_func": create_inner_docx_file, 23 | }, 24 | }, 25 | }, 26 | }, 27 | }, 28 | ) 29 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/zip_file_5.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.helpers.inner import ( 3 | create_inner_docx_file, 4 | create_inner_epub_file, 5 | create_inner_txt_file, 6 | fuzzy_choice_create_inner_file, 7 | ) 8 | from faker_file.providers.zip_file import ZipFileProvider 9 | from faker_file.storages.filesystem import FileSystemStorage 10 | 11 | FAKER = Faker() 12 | FAKER.add_provider(ZipFileProvider) 13 | 14 | STORAGE = FileSystemStorage() 15 | 16 | kwargs = {"storage": STORAGE, "generator": FAKER} 17 | 18 | zip_file = FAKER.zip_file( 19 | prefix="zzz_archive_", 20 | options={ 21 | "count": 50, 22 | "create_inner_file_func": fuzzy_choice_create_inner_file, 23 | "create_inner_file_args": { 24 | "func_choices": [ 25 | (create_inner_docx_file, kwargs), 26 | (create_inner_epub_file, kwargs), 27 | (create_inner_txt_file, kwargs), 28 | ], 29 | }, 30 | "directory": "zzz", 31 | }, 32 | ) 33 | -------------------------------------------------------------------------------- /docs/_static/examples/recipes/zip_file_6.py: -------------------------------------------------------------------------------- 1 | from faker import Faker 2 | from faker_file.providers.helpers.inner import ( 3 | create_inner_docx_file, 4 | create_inner_xml_file, 5 | list_create_inner_file, 6 | ) 7 | from faker_file.providers.zip_file import ZipFileProvider 8 | 9 | FAKER = Faker() 10 | FAKER.add_provider(ZipFileProvider) 11 | 12 | zip_file = FAKER.zip_file( 13 | basename="alice-looking-through-the-glass", 14 | options={ 15 | "create_inner_file_func": list_create_inner_file, 16 | "create_inner_file_args": { 17 | "func_list": [ 18 | (create_inner_docx_file, {"basename": "doc"}), 19 | (create_inner_xml_file, {"basename": "doc_metadata"}), 20 | (create_inner_xml_file, {"basename": "doc_isbn"}), 21 | ], 22 | }, 23 | }, 24 | ) 25 | -------------------------------------------------------------------------------- /docs/changelog.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../CHANGELOG.rst 2 | -------------------------------------------------------------------------------- /docs/code_of_conduct.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../CODE_OF_CONDUCT.rst 2 | -------------------------------------------------------------------------------- /docs/concepts.rst: -------------------------------------------------------------------------------- 1 | Concepts 2 | ======== 3 | `faker-file` is designed to generate files with synthetic data. It can work 4 | with a variety of file types, such as TXT, DOCX, PDF, PPTX, EML, and ZIP files. 5 | 6 | It uses the `Faker` library to generate synthetic (fake) data. This data can 7 | be used as the content of the generated files, allowing for files with 8 | realistic, but synthetic, content. 9 | 10 | Providers 11 | --------- 12 | `faker-file` includes different file providers for each file type. They are 13 | responsible for the creation of the files, each having a method to create a 14 | specific file type: 15 | 16 | - ``DocxFileProvider`` 17 | - ``PdfFileProvider`` 18 | - ``PptxFileProvider`` 19 | - ``TxtFileProvider`` 20 | - ``ZipFileProvider`` 21 | - ``EmlFileProvider`` 22 | 23 | Inner functions 24 | --------------- 25 | `faker-file` includes a module named ``faker_file.providers.helpers.inner`` that 26 | contains helper functions, referred to as "inner functions". These functions are 27 | used to create files that are nested within other files (e.g., creating DOCX 28 | files within a ZIP file). 29 | 30 | List of inner functions: 31 | 32 | - ``create_inner_docx_file`` 33 | - ``create_inner_zip_file`` 34 | - ``create_inner_eml_file`` 35 | - ``create_inner_epub_file`` 36 | - ``create_inner_txt_file`` 37 | - ``fuzzy_choice_create_inner_file`` 38 | - ``list_create_inner_file`` 39 | 40 | These inner functions are used to create a variety of files and structure them 41 | in various ways, such as creating DOCX files in ZIP files, or creating nested 42 | ZIP files. They also allow for the creation of files with dynamic content or 43 | content based on templates, as well as control over the naming and directory 44 | structure of the files. 45 | 46 | File customization 47 | ------------------ 48 | ``faker-file`` allows for various customization options for file generation. 49 | Examples include static or dynamic content generation, character limits, line 50 | wrapping, filename prefixing, and more. 51 | 52 | Storage 53 | ------- 54 | `faker-file` uses pluggable storages, which are responsible for managing how 55 | and where files are stored in the (remote) file system. 56 | 57 | DynamicTemplate 58 | --------------- 59 | ``DynamicTemplate`` is a wrapper used for creating DOCX and ODT files with 60 | tables and images. This feature allows for full control over the content 61 | creation process. It requires a list of tuples as input, where each tuple 62 | contains a callable function and a dictionary of keyword arguments. The 63 | callable function should accept arguments including a Faker generator or 64 | instance, a document instance, a dictionary for data, a counter, and an 65 | optional dictionary for additional arguments. This feature demonstrates 66 | how to create a DOCX or ODT file with a table and an image. 67 | 68 | GenericFileProvider 69 | ------------------- 70 | ``GenericFileProvider`` allows you to create files in any format from a 71 | predefined template. This is particularly useful when you want to generate 72 | a file in a format that is not directly supported by the library. 73 | -------------------------------------------------------------------------------- /docs/conftest.py: -------------------------------------------------------------------------------- 1 | from faker_file.tests._conftest import * # noqa 2 | -------------------------------------------------------------------------------- /docs/contributor_guidelines.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../CONTRIBUTING.rst 2 | -------------------------------------------------------------------------------- /docs/creating_docx.rst: -------------------------------------------------------------------------------- 1 | Creating DOCX 2 | ============= 3 | 4 | See the following full functional snippet for generating DOCX. 5 | 6 | .. container:: jsphinx-download 7 | 8 | .. literalinclude:: _static/examples/creating_docx/docx_1.py 9 | :language: python 10 | 11 | *See the full example* 12 | :download:`here <_static/examples/creating_docx/docx_1.py>` 13 | 14 | The generated DOCX will have 10,000 characters of text, which is about 5 pages. 15 | 16 | If you want DOCX with more pages, you could either: 17 | 18 | - Increase the value of ``max_nb_chars`` accordingly. 19 | - Set value of ``wrap_chars_after`` to 80 characters to force longer pages. 20 | - Insert manual page breaks and other content. 21 | 22 | ---- 23 | 24 | See the example below for ``max_nb_chars`` tweak: 25 | 26 | .. container:: jsphinx-download 27 | 28 | .. literalinclude:: _static/examples/creating_docx/docx_2.py 29 | :language: python 30 | :lines: 8- 31 | 32 | *See the full example* 33 | :download:`here <_static/examples/creating_docx/docx_2.py>` 34 | 35 | ---- 36 | 37 | See the example below for ``wrap_chars_after`` tweak: 38 | 39 | .. container:: jsphinx-download 40 | 41 | .. literalinclude:: _static/examples/creating_docx/docx_3.py 42 | :language: python 43 | :lines: 8- 44 | 45 | *See the full example* 46 | :download:`here <_static/examples/creating_docx/docx_3.py>` 47 | 48 | ---- 49 | 50 | As mentioned above, it's possible to diversify the generated context with 51 | images, paragraphs, tables, manual text break and pretty much everything that 52 | is supported by DOCX format specification, although currently only images, 53 | paragraphs, tables and manual text breaks are supported out of the box. In 54 | order to customise the blocks DOCX file is built from, the ``DynamicTemplate`` 55 | class is used. See the example below for usage examples: 56 | 57 | .. container:: jsphinx-download 58 | 59 | .. literalinclude:: _static/examples/creating_docx/docx_4.py 60 | :language: python 61 | :lines: 3-9, 14- 62 | 63 | *See the full example* 64 | :download:`here <_static/examples/creating_docx/docx_4.py>` 65 | -------------------------------------------------------------------------------- /docs/creating_odt.rst: -------------------------------------------------------------------------------- 1 | Creating ODT 2 | ============ 3 | 4 | See the following full functional snippet for generating ODT. 5 | 6 | .. container:: jsphinx-download 7 | 8 | .. literalinclude:: _static/examples/creating_odt/odt_1.py 9 | :language: python 10 | 11 | *See the full example* 12 | :download:`here <_static/examples/creating_odt/odt_1.py>` 13 | 14 | The generated ODT will have 10,000 characters of text, which is about 5 pages. 15 | 16 | If you want ODT with more pages, you could either: 17 | 18 | - Increase the value of ``max_nb_chars`` accordingly. 19 | - Set value of ``wrap_chars_after`` to 80 characters to force longer pages. 20 | - Insert manual page breaks and other content. 21 | 22 | ---- 23 | 24 | See the example below for ``max_nb_chars`` tweak: 25 | 26 | .. container:: jsphinx-download 27 | 28 | .. literalinclude:: _static/examples/creating_odt/odt_2.py 29 | :language: python 30 | :lines: 8- 31 | 32 | *See the full example* 33 | :download:`here <_static/examples/creating_odt/odt_2.py>` 34 | 35 | ---- 36 | 37 | See the example below for ``wrap_chars_after`` tweak: 38 | 39 | .. container:: jsphinx-download 40 | 41 | .. literalinclude:: _static/examples/creating_odt/odt_3.py 42 | :language: python 43 | :lines: 8- 44 | 45 | *See the full example* 46 | :download:`here <_static/examples/creating_odt/odt_3.py>` 47 | 48 | ---- 49 | 50 | As mentioned above, it's possible to diversify the generated context with 51 | images, paragraphs, tables, manual text break and pretty much everything that 52 | is supported by ODT format specification, although currently only images, 53 | paragraphs, tables and manual text breaks are supported out of the box. In 54 | order to customise the blocks ODT file is built from, the ``DynamicTemplate`` 55 | class is used. See the example below for usage examples: 56 | 57 | .. container:: jsphinx-download 58 | 59 | .. literalinclude:: _static/examples/creating_odt/odt_4.py 60 | :language: python 61 | :lines: 3-9, 14- 62 | 63 | *See the full example* 64 | :download:`here <_static/examples/creating_odt/odt_4.py>` 65 | -------------------------------------------------------------------------------- /docs/documentation.rst: -------------------------------------------------------------------------------- 1 | 2 | Project documentation 3 | ===================== 4 | Contents: 5 | 6 | .. contents:: Table of Contents 7 | 8 | .. toctree:: 9 | :maxdepth: 20 10 | 11 | readme 12 | quick_start 13 | recipes 14 | creating_images 15 | creating_pdf 16 | creating_docx 17 | creating_odt 18 | cli 19 | methodology 20 | talks/pygrunn_2023 21 | security 22 | code_of_conduct 23 | contributor_guidelines 24 | changelog 25 | package 26 | -------------------------------------------------------------------------------- /docs/faker_file.cli.rst: -------------------------------------------------------------------------------- 1 | faker\_file.cli package 2 | ======================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | faker\_file.cli.command module 8 | ------------------------------ 9 | 10 | .. automodule:: faker_file.cli.command 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | faker\_file.cli.helpers module 16 | ------------------------------ 17 | 18 | .. automodule:: faker_file.cli.helpers 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: faker_file.cli 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/faker_file.contrib.pdf_file.rst: -------------------------------------------------------------------------------- 1 | faker\_file.contrib.pdf\_file package 2 | ===================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | faker\_file.contrib.pdf\_file.pdfkit\_snippets module 8 | ----------------------------------------------------- 9 | 10 | .. automodule:: faker_file.contrib.pdf_file.pdfkit_snippets 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | faker\_file.contrib.pdf\_file.reportlab\_snippets module 16 | -------------------------------------------------------- 17 | 18 | .. automodule:: faker_file.contrib.pdf_file.reportlab_snippets 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: faker_file.contrib.pdf_file 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/faker_file.contrib.rst: -------------------------------------------------------------------------------- 1 | faker\_file.contrib package 2 | =========================== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 20 9 | 10 | faker_file.contrib.pdf_file 11 | 12 | Submodules 13 | ---------- 14 | 15 | faker\_file.contrib.docx\_file module 16 | ------------------------------------- 17 | 18 | .. automodule:: faker_file.contrib.docx_file 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | faker\_file.contrib.odt\_file module 24 | ------------------------------------ 25 | 26 | .. automodule:: faker_file.contrib.odt_file 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | Module contents 32 | --------------- 33 | 34 | .. automodule:: faker_file.contrib 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | -------------------------------------------------------------------------------- /docs/faker_file.providers.augment_file_from_dir.augmenters.rst: -------------------------------------------------------------------------------- 1 | faker\_file.providers.augment\_file\_from\_dir.augmenters package 2 | ================================================================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | faker\_file.providers.augment\_file\_from\_dir.augmenters.nlpaug\_augmenter module 8 | ---------------------------------------------------------------------------------- 9 | 10 | .. automodule:: faker_file.providers.augment_file_from_dir.augmenters.nlpaug_augmenter 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Module contents 16 | --------------- 17 | 18 | .. automodule:: faker_file.providers.augment_file_from_dir.augmenters 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | -------------------------------------------------------------------------------- /docs/faker_file.providers.augment_file_from_dir.extractors.rst: -------------------------------------------------------------------------------- 1 | faker\_file.providers.augment\_file\_from\_dir.extractors package 2 | ================================================================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | faker\_file.providers.augment\_file\_from\_dir.extractors.tika\_extractor module 8 | -------------------------------------------------------------------------------- 9 | 10 | .. automodule:: faker_file.providers.augment_file_from_dir.extractors.tika_extractor 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Module contents 16 | --------------- 17 | 18 | .. automodule:: faker_file.providers.augment_file_from_dir.extractors 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | -------------------------------------------------------------------------------- /docs/faker_file.providers.augment_file_from_dir.rst: -------------------------------------------------------------------------------- 1 | faker\_file.providers.augment\_file\_from\_dir package 2 | ====================================================== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 20 9 | 10 | faker_file.providers.augment_file_from_dir.augmenters 11 | faker_file.providers.augment_file_from_dir.extractors 12 | 13 | Module contents 14 | --------------- 15 | 16 | .. automodule:: faker_file.providers.augment_file_from_dir 17 | :members: 18 | :undoc-members: 19 | :show-inheritance: 20 | -------------------------------------------------------------------------------- /docs/faker_file.providers.base.rst: -------------------------------------------------------------------------------- 1 | faker\_file.providers.base package 2 | ================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | faker\_file.providers.base.image\_generator module 8 | -------------------------------------------------- 9 | 10 | .. automodule:: faker_file.providers.base.image_generator 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | faker\_file.providers.base.mp3\_generator module 16 | ------------------------------------------------ 17 | 18 | .. automodule:: faker_file.providers.base.mp3_generator 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | faker\_file.providers.base.pdf\_generator module 24 | ------------------------------------------------ 25 | 26 | .. automodule:: faker_file.providers.base.pdf_generator 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | faker\_file.providers.base.text\_augmenter module 32 | ------------------------------------------------- 33 | 34 | .. automodule:: faker_file.providers.base.text_augmenter 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | faker\_file.providers.base.text\_extractor module 40 | ------------------------------------------------- 41 | 42 | .. automodule:: faker_file.providers.base.text_extractor 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | Module contents 48 | --------------- 49 | 50 | .. automodule:: faker_file.providers.base 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | -------------------------------------------------------------------------------- /docs/faker_file.providers.helpers.rst: -------------------------------------------------------------------------------- 1 | faker\_file.providers.helpers package 2 | ===================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | faker\_file.providers.helpers.inner module 8 | ------------------------------------------ 9 | 10 | .. automodule:: faker_file.providers.helpers.inner 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Module contents 16 | --------------- 17 | 18 | .. automodule:: faker_file.providers.helpers 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | -------------------------------------------------------------------------------- /docs/faker_file.providers.image.rst: -------------------------------------------------------------------------------- 1 | faker\_file.providers.image package 2 | =================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | faker\_file.providers.image.augment module 8 | ------------------------------------------ 9 | 10 | .. automodule:: faker_file.providers.image.augment 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | faker\_file.providers.image.imgkit\_generator module 16 | ---------------------------------------------------- 17 | 18 | .. automodule:: faker_file.providers.image.imgkit_generator 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | faker\_file.providers.image.pil\_generator module 24 | ------------------------------------------------- 25 | 26 | .. automodule:: faker_file.providers.image.pil_generator 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | faker\_file.providers.image.weasyprint\_generator module 32 | -------------------------------------------------------- 33 | 34 | .. automodule:: faker_file.providers.image.weasyprint_generator 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | Module contents 40 | --------------- 41 | 42 | .. automodule:: faker_file.providers.image 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | -------------------------------------------------------------------------------- /docs/faker_file.providers.mixins.rst: -------------------------------------------------------------------------------- 1 | faker\_file.providers.mixins package 2 | ==================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | faker\_file.providers.mixins.graphic\_image\_mixin module 8 | --------------------------------------------------------- 9 | 10 | .. automodule:: faker_file.providers.mixins.graphic_image_mixin 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | faker\_file.providers.mixins.image\_mixin module 16 | ------------------------------------------------ 17 | 18 | .. automodule:: faker_file.providers.mixins.image_mixin 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | faker\_file.providers.mixins.tablular\_data\_mixin module 24 | --------------------------------------------------------- 25 | 26 | .. automodule:: faker_file.providers.mixins.tablular_data_mixin 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | Module contents 32 | --------------- 33 | 34 | .. automodule:: faker_file.providers.mixins 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | -------------------------------------------------------------------------------- /docs/faker_file.providers.mp3_file.generators.rst: -------------------------------------------------------------------------------- 1 | faker\_file.providers.mp3\_file.generators package 2 | ================================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | faker\_file.providers.mp3\_file.generators.edge\_tts\_generator module 8 | ---------------------------------------------------------------------- 9 | 10 | .. automodule:: faker_file.providers.mp3_file.generators.edge_tts_generator 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | faker\_file.providers.mp3\_file.generators.gtts\_generator module 16 | ----------------------------------------------------------------- 17 | 18 | .. automodule:: faker_file.providers.mp3_file.generators.gtts_generator 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: faker_file.providers.mp3_file.generators 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/faker_file.providers.mp3_file.rst: -------------------------------------------------------------------------------- 1 | faker\_file.providers.mp3\_file package 2 | ======================================= 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 20 9 | 10 | faker_file.providers.mp3_file.generators 11 | 12 | Module contents 13 | --------------- 14 | 15 | .. automodule:: faker_file.providers.mp3_file 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | -------------------------------------------------------------------------------- /docs/faker_file.providers.pdf_file.generators.rst: -------------------------------------------------------------------------------- 1 | faker\_file.providers.pdf\_file.generators package 2 | ================================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | faker\_file.providers.pdf\_file.generators.pdfkit\_generator module 8 | ------------------------------------------------------------------- 9 | 10 | .. automodule:: faker_file.providers.pdf_file.generators.pdfkit_generator 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | faker\_file.providers.pdf\_file.generators.reportlab\_generator module 16 | ---------------------------------------------------------------------- 17 | 18 | .. automodule:: faker_file.providers.pdf_file.generators.reportlab_generator 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: faker_file.providers.pdf_file.generators 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/faker_file.providers.pdf_file.rst: -------------------------------------------------------------------------------- 1 | faker\_file.providers.pdf\_file package 2 | ======================================= 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 20 9 | 10 | faker_file.providers.pdf_file.generators 11 | 12 | Module contents 13 | --------------- 14 | 15 | .. automodule:: faker_file.providers.pdf_file 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | -------------------------------------------------------------------------------- /docs/faker_file.rst: -------------------------------------------------------------------------------- 1 | faker\_file package 2 | =================== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 20 9 | 10 | faker_file.cli 11 | faker_file.contrib 12 | faker_file.providers 13 | faker_file.storages 14 | faker_file.tests 15 | 16 | Submodules 17 | ---------- 18 | 19 | faker\_file.base module 20 | ----------------------- 21 | 22 | .. automodule:: faker_file.base 23 | :members: 24 | :undoc-members: 25 | :show-inheritance: 26 | 27 | faker\_file.constants module 28 | ---------------------------- 29 | 30 | .. automodule:: faker_file.constants 31 | :members: 32 | :undoc-members: 33 | :show-inheritance: 34 | 35 | faker\_file.helpers module 36 | -------------------------- 37 | 38 | .. automodule:: faker_file.helpers 39 | :members: 40 | :undoc-members: 41 | :show-inheritance: 42 | 43 | faker\_file.registry module 44 | --------------------------- 45 | 46 | .. automodule:: faker_file.registry 47 | :members: 48 | :undoc-members: 49 | :show-inheritance: 50 | 51 | Module contents 52 | --------------- 53 | 54 | .. automodule:: faker_file 55 | :members: 56 | :undoc-members: 57 | :show-inheritance: 58 | -------------------------------------------------------------------------------- /docs/faker_file.storages.rst: -------------------------------------------------------------------------------- 1 | faker\_file.storages package 2 | ============================ 3 | 4 | Submodules 5 | ---------- 6 | 7 | faker\_file.storages.aws\_s3 module 8 | ----------------------------------- 9 | 10 | .. automodule:: faker_file.storages.aws_s3 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | faker\_file.storages.azure\_cloud\_storage module 16 | ------------------------------------------------- 17 | 18 | .. automodule:: faker_file.storages.azure_cloud_storage 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | faker\_file.storages.base module 24 | -------------------------------- 25 | 26 | .. automodule:: faker_file.storages.base 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | faker\_file.storages.cloud module 32 | --------------------------------- 33 | 34 | .. automodule:: faker_file.storages.cloud 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | faker\_file.storages.filesystem module 40 | -------------------------------------- 41 | 42 | .. automodule:: faker_file.storages.filesystem 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | faker\_file.storages.google\_cloud\_storage module 48 | -------------------------------------------------- 49 | 50 | .. automodule:: faker_file.storages.google_cloud_storage 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | 55 | faker\_file.storages.sftp\_storage module 56 | ----------------------------------------- 57 | 58 | .. automodule:: faker_file.storages.sftp_storage 59 | :members: 60 | :undoc-members: 61 | :show-inheritance: 62 | 63 | Module contents 64 | --------------- 65 | 66 | .. automodule:: faker_file.storages 67 | :members: 68 | :undoc-members: 69 | :show-inheritance: 70 | -------------------------------------------------------------------------------- /docs/faker_file.tests.rst: -------------------------------------------------------------------------------- 1 | faker\_file.tests package 2 | ========================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | faker\_file.tests.data module 8 | ----------------------------- 9 | 10 | .. automodule:: faker_file.tests.data 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | faker\_file.tests.sftp\_server module 16 | ------------------------------------- 17 | 18 | .. automodule:: faker_file.tests.sftp_server 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | faker\_file.tests.test\_augment module 24 | -------------------------------------- 25 | 26 | 27 | faker\_file.tests.test\_augment\_file\_from\_dir\_provider module 28 | ----------------------------------------------------------------- 29 | 30 | 31 | faker\_file.tests.test\_base module 32 | ----------------------------------- 33 | 34 | .. automodule:: faker_file.tests.test_base 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | faker\_file.tests.test\_cli module 40 | ---------------------------------- 41 | 42 | 43 | faker\_file.tests.test\_data\_integrity module 44 | ---------------------------------------------- 45 | 46 | 47 | faker\_file.tests.test\_django\_integration module 48 | -------------------------------------------------- 49 | 50 | 51 | faker\_file.tests.test\_helpers module 52 | -------------------------------------- 53 | 54 | 55 | faker\_file.tests.test\_providers module 56 | ---------------------------------------- 57 | 58 | 59 | faker\_file.tests.test\_registry module 60 | --------------------------------------- 61 | 62 | 63 | faker\_file.tests.test\_sftp\_server module 64 | ------------------------------------------- 65 | 66 | 67 | faker\_file.tests.test\_sftp\_storage module 68 | -------------------------------------------- 69 | 70 | 71 | faker\_file.tests.test\_sqlalchemy\_integration module 72 | ------------------------------------------------------ 73 | 74 | 75 | faker\_file.tests.test\_storages module 76 | --------------------------------------- 77 | 78 | 79 | faker\_file.tests.texts module 80 | ------------------------------ 81 | 82 | .. automodule:: faker_file.tests.texts 83 | :members: 84 | :undoc-members: 85 | :show-inheritance: 86 | 87 | faker\_file.tests.utils module 88 | ------------------------------ 89 | 90 | .. automodule:: faker_file.tests.utils 91 | :members: 92 | :undoc-members: 93 | :show-inheritance: 94 | 95 | Module contents 96 | --------------- 97 | 98 | .. automodule:: faker_file.tests 99 | :members: 100 | :undoc-members: 101 | :show-inheritance: 102 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | .. include:: documentation.rst 3 | -------------------------------------------------------------------------------- /docs/index.rst.distrib: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | .. include:: documentation.rst 3 | -------------------------------------------------------------------------------- /docs/llms.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | 3 | ---- 4 | 5 | .. include:: recipes.rst 6 | 7 | ---- 8 | 9 | .. include:: cheatsheet.rst 10 | 11 | ---- 12 | 13 | .. include:: creating_files.rst 14 | 15 | ---- 16 | 17 | .. include:: creating_images.rst 18 | 19 | ---- 20 | 21 | .. include:: creating_pdf.rst 22 | 23 | ---- 24 | 25 | .. include:: creating_docx.rst 26 | 27 | ---- 28 | 29 | .. include:: creating_odt.rst 30 | 31 | ---- 32 | 33 | .. include:: concepts.rst 34 | 35 | ---- 36 | 37 | .. include:: methodology.rst 38 | 39 | ---- 40 | 41 | .. include:: quick_start.rst 42 | 43 | ---- 44 | 45 | .. include:: recipes.rst 46 | 47 | ---- 48 | 49 | .. include:: cli.rst 50 | 51 | ---- 52 | 53 | .. include:: security.rst 54 | 55 | ---- 56 | 57 | .. include:: contributor_guidelines.rst 58 | 59 | ---- 60 | 61 | .. include:: changelog.rst 62 | 63 | ---- 64 | 65 | .. include:: package.rst 66 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | 13 | %SPHINXBUILD% >NUL 2>NUL 14 | if errorlevel 9009 ( 15 | echo. 16 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 17 | echo.installed, then set the SPHINXBUILD environment variable to point 18 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 19 | echo.may add the Sphinx directory to PATH. 20 | echo. 21 | echo.If you don't have Sphinx installed, grab it from 22 | echo.https://www.sphinx-doc.org/ 23 | exit /b 1 24 | ) 25 | 26 | if "%1" == "" goto help 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/marytts.py: -------------------------------------------------------------------------------- 1 | """ 2 | Created for testing purposes to mock out imaginary MaryTTS module 3 | that is referenced in documentation examples. 4 | """ 5 | 6 | 7 | class MaryTTS: 8 | def __init__(self, locale: str, voice: str) -> None: 9 | self.locale = locale 10 | self.voice = voice 11 | 12 | def synth_mp3(self, content: str) -> bytes: 13 | return bytes() 14 | -------------------------------------------------------------------------------- /docs/package.rst: -------------------------------------------------------------------------------- 1 | 2 | Package 3 | ======= 4 | 5 | .. toctree:: 6 | :maxdepth: 20 7 | 8 | faker_file 9 | 10 | Indices and tables 11 | ================== 12 | 13 | * :ref:`genindex` 14 | * :ref:`modindex` 15 | * :ref:`search` 16 | -------------------------------------------------------------------------------- /docs/quick_start.rst: -------------------------------------------------------------------------------- 1 | Quick start 2 | =========== 3 | 4 | Installation 5 | ------------ 6 | .. code-block:: sh 7 | 8 | pip install faker-file[all] 9 | 10 | Usage 11 | ----- 12 | With ``Faker`` 13 | ~~~~~~~~~~~~~~ 14 | **Imports and initialization** 15 | 16 | .. literalinclude:: _static/examples/quick_start/import_and_init_1.py 17 | :language: python 18 | :lines: 2-78 19 | 20 | **Usage examples** 21 | 22 | .. literalinclude:: _static/examples/quick_start/import_and_init_1.py 23 | :language: python 24 | :lines: 87-121 25 | 26 | If you just need bytes back (instead of creating the file), provide 27 | the ``raw=True`` argument (works with all provider classes and inner 28 | functions): 29 | 30 | .. container:: jsphinx-download 31 | 32 | .. literalinclude:: _static/examples/quick_start/import_and_init_1.py 33 | :language: python 34 | :lines: 124- 35 | 36 | *See the full example* 37 | :download:`here <_static/examples/quick_start/import_and_init_1.py>` 38 | 39 | ---- 40 | 41 | With ``factory_boy`` 42 | ~~~~~~~~~~~~~~~~~~~~ 43 | **Imports and initialization** 44 | 45 | .. literalinclude:: _static/examples/quick_start/factory_import_and_init_1.py 46 | :language: python 47 | :lines: 3, 5-45, 49-78 48 | 49 | **upload/models.py** 50 | 51 | .. container:: jsphinx-download 52 | 53 | .. literalinclude:: _static/examples/quick_start/factory_models_1.py 54 | :language: python 55 | :lines: 1, 3-11 56 | 57 | *See the full example* 58 | :download:`here <_static/examples/quick_start/factory_models_1.py>` 59 | 60 | **upload/factories.py** 61 | 62 | .. literalinclude:: _static/examples/quick_start/factory_import_and_init_1.py 63 | :language: python 64 | :lines: 2-4, 46-49, 80-118 65 | 66 | **Usage example** 67 | 68 | .. container:: jsphinx-download 69 | 70 | .. literalinclude:: _static/examples/quick_start/factory_import_and_init_1.py 71 | :language: python 72 | :lines: 122- 73 | 74 | *See the full example* 75 | :download:`here <_static/examples/quick_start/factory_import_and_init_1.py>` 76 | -------------------------------------------------------------------------------- /docs/readme.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | -------------------------------------------------------------------------------- /docs/security.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../SECURITY.rst 2 | -------------------------------------------------------------------------------- /docs/test_docs.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from pathlib import Path 3 | from unittest import mock 4 | from unittest.mock import create_autospec 5 | 6 | import paramiko 7 | import pytest 8 | import tika 9 | from django.test import override_settings 10 | from faker_file.registry import FILE_REGISTRY 11 | from moto import mock_aws 12 | 13 | # Walk through the directory and all subdirectories for .py files 14 | example_dir = Path("docs/_static/examples") 15 | py_files = sorted([str(p) for p in example_dir.rglob("*.py")]) 16 | 17 | 18 | @pytest.fixture(scope="module") 19 | def setup_module(): 20 | # Perform setup actions here 21 | print("Setup actions for the module") 22 | tika.initVM() 23 | yield 24 | # Perform teardown actions here (optional) 25 | print("Teardown actions for the module") 26 | 27 | 28 | @pytest.fixture 29 | def mock_gcs(): 30 | """Mock Google Cloud Storage.""" 31 | with mock.patch("google.cloud.storage.Client") as mock_client: 32 | yield mock_client 33 | 34 | 35 | @pytest.fixture 36 | def mock_paramiko(): 37 | """Mock paramiko.""" 38 | mock_transport = create_autospec(paramiko.Transport) 39 | mock_transport.return_value.send = mock.Mock(return_value=42) 40 | 41 | mock_sftp_client = create_autospec(paramiko.SFTPClient) 42 | mock_sftp_client.from_transport.return_value = mock_sftp_client 43 | 44 | with mock.patch("paramiko.Transport", mock_transport), mock.patch( 45 | "paramiko.SFTPClient", mock_sftp_client 46 | ): 47 | yield 48 | 49 | 50 | # We have to apply `moto` mocking to all test functions, because in some 51 | # we have boto dependant code. 52 | @mock_aws 53 | def execute_file(file_path, caplog): 54 | """Dynamic test function.""" 55 | global_vars = {} 56 | # Set the log level to WARNING for this block 57 | with caplog.at_level(logging.WARNING): 58 | with open(file_path, "r") as f: 59 | code = f.read() 60 | exec(code, global_vars) 61 | 62 | 63 | @pytest.mark.flaky(retries=3, delay=1) 64 | @pytest.mark.django_db 65 | @pytest.mark.parametrize("file_path", py_files) 66 | @override_settings(AWS_STORAGE_BUCKET_NAME="testing") 67 | def test_dynamic_files(file_path, caplog, mock_gcs, mock_paramiko): 68 | execute_file(file_path, caplog) 69 | FILE_REGISTRY.clean_up() 70 | -------------------------------------------------------------------------------- /examples/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/examples/__init__.py -------------------------------------------------------------------------------- /examples/customizations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/examples/customizations/__init__.py -------------------------------------------------------------------------------- /examples/customizations/marytts_mp3_generator/README.rst: -------------------------------------------------------------------------------- 1 | ============================ 2 | Custom MP3 generator example 3 | ============================ 4 | Generate MP3 file from random text using custom MP3 generator based on 5 | ``MaryTts``. 6 | 7 | Prerequisites 8 | ============= 9 | Install ``speak2mary`` (``Apache 2``) and ``ffmpeg-python`` 10 | (``Apache 2``): 11 | 12 | .. code-block:: shell 13 | 14 | pip install speak2mary ffmpeg-python 15 | 16 | Run ``marytts`` in docker: 17 | 18 | https://github.com/synesthesiam/docker-marytts 19 | 20 | .. code-block:: shell 21 | 22 | docker run -it -p 59125:59125 synesthesiam/marytts:5.2 23 | 24 | Usage example 25 | ============= 26 | Generate MP3 from random text using custom MP3 generator: 27 | 28 | .. code-block:: python 29 | 30 | import os 31 | import sys 32 | sys.path.insert( 33 | 0, os.path.abspath(os.path.join("examples", "customizations")) 34 | ) 35 | 36 | from faker import Faker 37 | from faker_file.providers.mp3_file import Mp3FileProvider 38 | from marytts_mp3_generator import MaryTtsMp3Generator 39 | 40 | FAKER = Faker() 41 | 42 | file = Mp3FileProvider(FAKER).mp3_file( 43 | mp3_generator_cls=MaryTtsMp3Generator, 44 | mp3_generator_kwargs={}, 45 | ) 46 | -------------------------------------------------------------------------------- /examples/customizations/marytts_mp3_generator/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | import tempfile 3 | 4 | import ffmpeg 5 | from faker_file.providers.base.mp3_generator import BaseMp3Generator 6 | from speak2mary import MaryTTS 7 | 8 | __author__ = "Artur Barseghyan " 9 | __copyright__ = "2022-2025 Artur Barseghyan" 10 | __license__ = "MIT" 11 | __all__ = ("MaryTtsMp3Generator",) 12 | 13 | 14 | DEFAULT_LOCALE = "en_GB" 15 | DEFAULT_VOICE = "dfki-spike-hsmm" 16 | 17 | 18 | class MaryTtsMp3Generator(BaseMp3Generator): 19 | """MaryTTS Text-to-Speech generator. 20 | 21 | Usage example: 22 | 23 | from faker import Faker 24 | from faker_file.providers.mp3_file import Mp3FileProvider 25 | from marytts_mp3_generator import ( 26 | MaryTtsMp3Generator, 27 | ) 28 | 29 | FAKER = Faker() 30 | 31 | file = Mp3FileProvider(FAKER).mp3_file( 32 | mp3_generator_cls=MaryTtsMp3Generator, 33 | mp3_generator_kwargs={}, 34 | ) 35 | """ 36 | 37 | locale: str = DEFAULT_LOCALE 38 | voice: str = DEFAULT_VOICE 39 | 40 | def handle_kwargs(self: "MaryTtsMp3Generator", **kwargs) -> None: 41 | if "locale" in kwargs: 42 | self.locale = kwargs["locale"] 43 | if "voice" in kwargs: 44 | self.voice = kwargs["voice"] 45 | 46 | def generate(self: "MaryTtsMp3Generator") -> bytes: 47 | """Generate MP3.""" 48 | # Initialize with args 49 | mary_tts = MaryTTS(locale=self.locale, voice=self.voice) 50 | 51 | # Create temporary WAV file in memory 52 | with tempfile.NamedTemporaryFile( 53 | delete=False, 54 | suffix=".wav", 55 | ) as temp_wav: 56 | temp_wav.write(mary_tts.speak(self.content)) 57 | temp_wav_path = temp_wav.name 58 | 59 | # Convert WAV to MP3 and store in memory 60 | with tempfile.NamedTemporaryFile( 61 | delete=False, 62 | suffix=".mp3", 63 | ) as temp_mp3: 64 | ffmpeg.input(temp_wav_path).output(temp_mp3.name).run() 65 | 66 | # Read the MP3 file content into memory 67 | with open(temp_mp3.name, "rb") as mp3_file: 68 | mp3_content = mp3_file.read() 69 | 70 | # Clean up temporary files 71 | os.remove(temp_wav.name) 72 | os.remove(temp_mp3.name) 73 | 74 | return mp3_content 75 | 76 | # # Generate temporary filename for WAV file 77 | # filename = tempfile.NamedTemporaryFile( 78 | # prefix="_merytts_", suffix=".wav" 79 | # ).name 80 | # 81 | # # Write WAV file 82 | # with open(filename, "wb") as file: 83 | # file.write(mary_tts.speak(self.content)) 84 | # 85 | # # Convert WAV to MP3 86 | # ffmpeg.input(filename).output(filename + ".mp3").run() 87 | # 88 | # with open(filename + ".mp3", "rb") as _fake_file: 89 | # return_value = _fake_file.read() 90 | # 91 | # # Clean up temporary files 92 | # os.remove(filename) 93 | # os.remove(filename + ".mp3") 94 | # 95 | # return return_value 96 | -------------------------------------------------------------------------------- /examples/django_example/README.rst: -------------------------------------------------------------------------------- 1 | ========================================= 2 | Django example project for ``faker-file`` 3 | ========================================= 4 | *Used for testing.* 5 | -------------------------------------------------------------------------------- /examples/django_example/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/examples/django_example/__init__.py -------------------------------------------------------------------------------- /examples/django_example/factories/__init__.py: -------------------------------------------------------------------------------- 1 | from .auth_user import * # noqa 2 | from .upload_upload import * # noqa 3 | -------------------------------------------------------------------------------- /examples/django_example/factories/auth_user.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/examples/django_example/factories/auth_user.py -------------------------------------------------------------------------------- /examples/django_example/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings") 7 | 8 | from django.core.management import execute_from_command_line 9 | 10 | execute_from_command_line(sys.argv) 11 | -------------------------------------------------------------------------------- /examples/django_example/project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/examples/django_example/project/__init__.py -------------------------------------------------------------------------------- /examples/django_example/project/settings/__init__.py: -------------------------------------------------------------------------------- 1 | from .dev import * # noqa 2 | -------------------------------------------------------------------------------- /examples/django_example/project/settings/core.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | __all__ = ( 4 | "project_dir", 5 | "gettext", 6 | "PROJECT_DIR", 7 | ) 8 | 9 | 10 | def project_dir(base: str) -> str: 11 | return os.path.abspath( 12 | os.path.join(os.path.dirname(__file__), base).replace("\\", "/") 13 | ) 14 | 15 | 16 | def gettext(s: str) -> str: 17 | return s 18 | 19 | 20 | PROJECT_DIR = project_dir 21 | -------------------------------------------------------------------------------- /examples/django_example/project/settings/dev.py: -------------------------------------------------------------------------------- 1 | from .base import * # noqa 2 | -------------------------------------------------------------------------------- /examples/django_example/project/settings/docs.py: -------------------------------------------------------------------------------- 1 | from .dev import * # noqa 2 | -------------------------------------------------------------------------------- /examples/django_example/project/settings/local_settings.example: -------------------------------------------------------------------------------- 1 | DEV = True 2 | -------------------------------------------------------------------------------- /examples/django_example/project/settings/testing.py: -------------------------------------------------------------------------------- 1 | from .base import * # noqa 2 | -------------------------------------------------------------------------------- /examples/django_example/project/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | from django.conf.urls.static import static 3 | from django.contrib import admin 4 | from django.contrib.staticfiles.urls import staticfiles_urlpatterns 5 | from django.urls import include, re_path 6 | from drf_spectacular.views import ( 7 | SpectacularAPIView, 8 | SpectacularRedocView, 9 | SpectacularSwaggerView, 10 | ) 11 | 12 | __all__ = ("urlpatterns",) 13 | 14 | urlpatterns = [ 15 | re_path(r"^admin/", admin.site.urls), 16 | # API schema 17 | re_path("^api/schema/", SpectacularAPIView.as_view(), name="api-schema"), 18 | re_path( 19 | "^api/docs/", 20 | SpectacularSwaggerView.as_view(url_name="api-schema"), 21 | name="api-docs", 22 | ), 23 | re_path( 24 | "^api/redoc/", 25 | SpectacularRedocView.as_view(url_name="api-schema"), 26 | name="api-redoc", 27 | ), 28 | # Upload API 29 | re_path(r"^api/", include("upload.api.urls", namespace="api")), 30 | ] 31 | 32 | # Serving media and static in debug/developer mode. 33 | if settings.DEBUG: 34 | urlpatterns += staticfiles_urlpatterns() 35 | urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 36 | -------------------------------------------------------------------------------- /examples/django_example/project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for simple project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings") 13 | 14 | from django.core.wsgi import get_wsgi_application 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /examples/django_example/upload/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/examples/django_example/upload/__init__.py -------------------------------------------------------------------------------- /examples/django_example/upload/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from .models import Upload 4 | 5 | __all__ = ("UploadAdmin",) 6 | 7 | 8 | @admin.register(Upload) 9 | class UploadAdmin(admin.ModelAdmin): 10 | """Upload admin.""" 11 | 12 | list_display = ( 13 | "name", 14 | "description", 15 | "file", 16 | ) 17 | -------------------------------------------------------------------------------- /examples/django_example/upload/api/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/examples/django_example/upload/api/__init__.py -------------------------------------------------------------------------------- /examples/django_example/upload/api/serializers.py: -------------------------------------------------------------------------------- 1 | from rest_framework import serializers 2 | 3 | from ..models import Upload 4 | 5 | __all__ = ( 6 | "UploadInSerializer", 7 | "UploadOutSerializer", 8 | ) 9 | 10 | 11 | class UploadInSerializer(serializers.ModelSerializer): 12 | class Meta: 13 | model = Upload 14 | fields = ["id", "name", "description", "file"] 15 | read_only_fields = ["id"] 16 | 17 | 18 | class UploadOutSerializer(serializers.ModelSerializer): 19 | class Meta: 20 | model = Upload 21 | fields = ["id", "name", "description", "file"] 22 | -------------------------------------------------------------------------------- /examples/django_example/upload/api/tests.py: -------------------------------------------------------------------------------- 1 | from io import BytesIO 2 | from uuid import uuid4 3 | 4 | from django.test import TestCase 5 | from django.urls import reverse 6 | from faker import Faker 7 | from faker_file.providers.docx_file import DocxFileProvider 8 | from faker_file.registry import FILE_REGISTRY 9 | from rest_framework.status import HTTP_201_CREATED 10 | 11 | from upload.models import Upload 12 | 13 | FAKER = Faker() 14 | FAKER.add_provider(DocxFileProvider) 15 | 16 | __all__ = ("UploadTestCase",) 17 | 18 | 19 | class UploadTestCase(TestCase): 20 | """Upload test case.""" 21 | 22 | def tearDown(self, *args, **kwargs) -> None: 23 | super().tearDown(*args, **kwargs) 24 | FILE_REGISTRY.clean_up() 25 | 26 | def test_create_docx_upload(self) -> None: 27 | """Test create an Upload.""" 28 | url = reverse("api:upload-list") 29 | 30 | raw = FAKER.docx_file(raw=True) 31 | test_file = BytesIO(raw) 32 | test_file.name = f"test{uuid4()}.docx" 33 | 34 | payload = { 35 | "name": FAKER.word(), 36 | "description": FAKER.paragraph(), 37 | "file": test_file, 38 | } 39 | 40 | response = self.client.post(url, payload, format="json") 41 | 42 | # Test if request is handled properly (HTTP 201) 43 | self.assertEqual(response.status_code, HTTP_201_CREATED) 44 | 45 | test_upload = Upload.objects.get(id=response.data["id"]) 46 | 47 | # Test if the name is properly recorded 48 | self.assertEqual(str(test_upload.name), payload["name"]) 49 | 50 | # Test if file name recorded properly 51 | self.assertEqual(str(test_upload.file.name), test_file.name) 52 | -------------------------------------------------------------------------------- /examples/django_example/upload/api/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import include, re_path 2 | from rest_framework import routers 3 | 4 | from .views import UploadViewSet 5 | 6 | __all__ = ("urlpatterns",) 7 | 8 | app_name = "api" 9 | router = routers.DefaultRouter() 10 | router.register(r"upload", UploadViewSet) 11 | 12 | urlpatterns = [ 13 | re_path("^upload/", include(router.urls)), 14 | ] 15 | -------------------------------------------------------------------------------- /examples/django_example/upload/api/views.py: -------------------------------------------------------------------------------- 1 | from django.utils.translation import gettext_lazy as _ 2 | from drf_spectacular.utils import extend_schema, extend_schema_view 3 | from rest_framework import viewsets 4 | from rest_framework.permissions import AllowAny 5 | 6 | from ..models import Upload 7 | from .serializers import UploadInSerializer, UploadOutSerializer 8 | 9 | __all__ = ("UploadViewSet",) 10 | 11 | 12 | @extend_schema(tags=[_("Upload")]) 13 | @extend_schema_view( 14 | create=extend_schema( 15 | tags=[_("Upload")], 16 | request={ 17 | "multipart/form-data": { 18 | "type": "object", 19 | "properties": { 20 | "name": { 21 | "type": "string", 22 | "format": "string", 23 | }, 24 | "description": { 25 | "type": "string", 26 | "format": "string", 27 | }, 28 | "file": { 29 | "type": "string", 30 | "format": "binary", 31 | }, 32 | }, 33 | } 34 | }, 35 | ), 36 | ) 37 | class UploadViewSet(viewsets.ModelViewSet): 38 | queryset = Upload.objects.all() 39 | serializer_class = default_serializer_class = UploadInSerializer 40 | serializer_classes = { 41 | "list": UploadOutSerializer, 42 | "create": UploadInSerializer, 43 | "retrieve": UploadOutSerializer, 44 | "update": UploadOutSerializer, 45 | "partial_update": UploadOutSerializer, 46 | "destroy": UploadOutSerializer, 47 | } 48 | permission_classes = (AllowAny,) 49 | 50 | def get_serializer_class(self): 51 | return self.serializer_classes.get( 52 | self.action, self.default_serializer_class 53 | ) 54 | -------------------------------------------------------------------------------- /examples/django_example/upload/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.1.3 on 2022-12-04 21:22 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | initial = True 9 | 10 | dependencies = [] 11 | 12 | operations = [ 13 | migrations.CreateModel( 14 | name="Upload", 15 | fields=[ 16 | ( 17 | "id", 18 | models.AutoField( 19 | auto_created=True, 20 | primary_key=True, 21 | serialize=False, 22 | verbose_name="ID", 23 | ), 24 | ), 25 | ("name", models.CharField(max_length=255, unique=True)), 26 | ("description", models.TextField(blank=True, null=True)), 27 | ("file", models.FileField(upload_to="")), 28 | ], 29 | options={ 30 | "verbose_name": "Upload", 31 | "verbose_name_plural": "Upload", 32 | }, 33 | ), 34 | ] 35 | -------------------------------------------------------------------------------- /examples/django_example/upload/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/examples/django_example/upload/migrations/__init__.py -------------------------------------------------------------------------------- /examples/django_example/upload/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | __all__ = ("Upload",) 4 | 5 | 6 | class Upload(models.Model): 7 | """Upload model.""" 8 | 9 | name = models.CharField(max_length=255, unique=True) 10 | description = models.TextField(null=True, blank=True) 11 | file = models.FileField() 12 | 13 | class Meta: 14 | verbose_name = "Upload" 15 | verbose_name_plural = "Upload" 16 | 17 | def __str__(self: "Upload") -> str: 18 | return self.name # noqa 19 | -------------------------------------------------------------------------------- /examples/requirements/common.in: -------------------------------------------------------------------------------- 1 | edge-tts 2 | imgkit 3 | gTTS 4 | odfpy 5 | openpyxl 6 | pathy[all]>=0.10.0,<0.11.0 7 | pdfkit 8 | python-docx 9 | python-pptx 10 | pytz 11 | reportlab 12 | tablib 13 | xml2epub 14 | paramiko 15 | pdf2image 16 | weasyprint 17 | -------------------------------------------------------------------------------- /examples/requirements/debug.in: -------------------------------------------------------------------------------- 1 | ipdb 2 | ipython 3 | ipython-genutils 4 | -------------------------------------------------------------------------------- /examples/requirements/debug.txt: -------------------------------------------------------------------------------- 1 | # This file was autogenerated by uv via the following command: 2 | # uv pip compile --no-strip-extras examples/requirements/debug.in -o examples/requirements/debug.txt 3 | asttokens==3.0.0 4 | # via stack-data 5 | decorator==5.2.1 6 | # via 7 | # ipdb 8 | # ipython 9 | exceptiongroup==1.2.2 10 | # via ipython 11 | executing==2.2.0 12 | # via stack-data 13 | ipdb==0.13.13 14 | # via -r examples/requirements/debug.in 15 | ipython==8.36.0 16 | # via 17 | # -r examples/requirements/debug.in 18 | # ipdb 19 | ipython-genutils==0.2.0 20 | # via -r examples/requirements/debug.in 21 | jedi==0.19.2 22 | # via ipython 23 | matplotlib-inline==0.1.7 24 | # via ipython 25 | parso==0.8.4 26 | # via jedi 27 | pexpect==4.9.0 28 | # via ipython 29 | prompt-toolkit==3.0.51 30 | # via ipython 31 | ptyprocess==0.7.0 32 | # via pexpect 33 | pure-eval==0.2.3 34 | # via stack-data 35 | pygments==2.19.1 36 | # via ipython 37 | stack-data==0.6.3 38 | # via ipython 39 | tomli==2.2.1 40 | # via ipdb 41 | traitlets==5.14.3 42 | # via 43 | # ipython 44 | # matplotlib-inline 45 | typing-extensions==4.13.2 46 | # via ipython 47 | wcwidth==0.2.13 48 | # via prompt-toolkit 49 | -------------------------------------------------------------------------------- /examples/requirements/deployment.in: -------------------------------------------------------------------------------- 1 | twine 2 | -------------------------------------------------------------------------------- /examples/requirements/deployment.txt: -------------------------------------------------------------------------------- 1 | # This file was autogenerated by uv via the following command: 2 | # uv pip compile --no-strip-extras examples/requirements/deployment.in -o examples/requirements/deployment.txt 3 | backports-tarfile==1.2.0 4 | # via jaraco-context 5 | certifi==2025.4.26 6 | # via requests 7 | cffi==1.17.1 8 | # via cryptography 9 | charset-normalizer==3.4.2 10 | # via requests 11 | cryptography==44.0.3 12 | # via secretstorage 13 | docutils==0.21.2 14 | # via readme-renderer 15 | id==1.5.0 16 | # via twine 17 | idna==3.10 18 | # via requests 19 | importlib-metadata==8.7.0 20 | # via keyring 21 | jaraco-classes==3.4.0 22 | # via keyring 23 | jaraco-context==6.0.1 24 | # via keyring 25 | jaraco-functools==4.1.0 26 | # via keyring 27 | jeepney==0.9.0 28 | # via 29 | # keyring 30 | # secretstorage 31 | keyring==25.6.0 32 | # via twine 33 | markdown-it-py==3.0.0 34 | # via rich 35 | mdurl==0.1.2 36 | # via markdown-it-py 37 | more-itertools==10.7.0 38 | # via 39 | # jaraco-classes 40 | # jaraco-functools 41 | nh3==0.2.21 42 | # via readme-renderer 43 | packaging==25.0 44 | # via twine 45 | pycparser==2.22 46 | # via cffi 47 | pygments==2.19.1 48 | # via 49 | # readme-renderer 50 | # rich 51 | readme-renderer==44.0 52 | # via twine 53 | requests==2.32.3 54 | # via 55 | # id 56 | # requests-toolbelt 57 | # twine 58 | requests-toolbelt==1.0.0 59 | # via twine 60 | rfc3986==2.0.0 61 | # via twine 62 | rich==14.0.0 63 | # via twine 64 | secretstorage==3.3.3 65 | # via keyring 66 | twine==6.1.0 67 | # via -r examples/requirements/deployment.in 68 | typing-extensions==4.13.2 69 | # via rich 70 | urllib3==2.4.0 71 | # via 72 | # requests 73 | # twine 74 | zipp==3.21.0 75 | # via importlib-metadata 76 | -------------------------------------------------------------------------------- /examples/requirements/dev.in: -------------------------------------------------------------------------------- 1 | -r django_4_2_and_flask.in 2 | -r deployment.in 3 | -------------------------------------------------------------------------------- /examples/requirements/django_4_2.in: -------------------------------------------------------------------------------- 1 | -r common.in 2 | -r test.in 3 | 4 | Django>=4.2,<4.3 5 | django-debug-toolbar>=3.5.0 6 | django-extensions 7 | djangorestframework>=3.15.0,<3.16 8 | django-storages>=1.13 9 | drf_spectacular 10 | -------------------------------------------------------------------------------- /examples/requirements/django_4_2_and_flask.in: -------------------------------------------------------------------------------- 1 | -r django_4_2.in 2 | -r flask.in 3 | -------------------------------------------------------------------------------- /examples/requirements/django_5_0.in: -------------------------------------------------------------------------------- 1 | -r common.in 2 | -r test.in 3 | 4 | Django>=5.0,<5.1 5 | django-debug-toolbar>=3.5.0 6 | django-extensions 7 | djangorestframework>=3.15.0,<3.16 8 | django-storages>=1.13 9 | drf_spectacular 10 | -------------------------------------------------------------------------------- /examples/requirements/django_5_0_and_flask.in: -------------------------------------------------------------------------------- 1 | -r django_5_0.in 2 | -r flask.in 3 | -------------------------------------------------------------------------------- /examples/requirements/django_5_1.in: -------------------------------------------------------------------------------- 1 | -r common.in 2 | -r test.in 3 | 4 | Django>=5.1,<5.2 5 | django-debug-toolbar>=3.5.0 6 | django-extensions 7 | djangorestframework>=3.15.0,<3.16 8 | django-storages>=1.13 9 | drf_spectacular 10 | -------------------------------------------------------------------------------- /examples/requirements/django_5_1_and_flask.in: -------------------------------------------------------------------------------- 1 | -r django_5_1.in 2 | -r flask.in 3 | -------------------------------------------------------------------------------- /examples/requirements/docs.in: -------------------------------------------------------------------------------- 1 | -r common.in 2 | -r django_4_2.in 3 | 4 | reportlab 5 | rst2pdf 6 | sphinx 7 | sphinx-autobuild 8 | sphinx-rtd-theme>=3.0.0 9 | -------------------------------------------------------------------------------- /examples/requirements/flask.in: -------------------------------------------------------------------------------- 1 | -r common.in 2 | -r test.in 3 | 4 | alembic 5 | Flask>=2.0,<3.0 6 | #Flask<=2.1.0; python_version < '3.10' # For Python 3.7, 3.8 and 3.9 7 | #Flask; python_version >= '3.10' # For Python 3.10 and 3.11 8 | Flask-Admin 9 | Flask-BabelEx 10 | Flask-SQLAlchemy 11 | #Flask-SQLAlchemy<3.0.0; ; python_version < '3.8' # For Python 3.7 12 | #Flask-SQLAlchemy>3.0.0; ; python_version >= '3.8' # For Python 3.8, 3.9, 3.10 and 3.11 13 | Flask-Testing 14 | SQLAlchemy>=1.0,<2.0 15 | sqlalchemy_utils 16 | -------------------------------------------------------------------------------- /examples/requirements/ml.in: -------------------------------------------------------------------------------- 1 | -r common.in 2 | -r test.in 3 | 4 | # Text extraction 5 | tika 6 | 7 | # Data augmentation 8 | nlpaug 9 | nltk 10 | scipy<=1.12.0 11 | textaugment 12 | textblob>=0.17,<0.18 13 | torch 14 | transformers 15 | -------------------------------------------------------------------------------- /examples/requirements/style_checkers.in: -------------------------------------------------------------------------------- 1 | # Style checkers 2 | #black 3 | ruff 4 | #isort>=5.11.5 5 | doc8 6 | pre-commit 7 | pydoclint 8 | pydocstyle 9 | pyflakes 10 | pylint 11 | -------------------------------------------------------------------------------- /examples/requirements/style_checkers.txt: -------------------------------------------------------------------------------- 1 | # This file was autogenerated by uv via the following command: 2 | # uv pip compile --no-strip-extras examples/requirements/style_checkers.in -o examples/requirements/style_checkers.txt 3 | astroid==3.3.9 4 | # via pylint 5 | cfgv==3.4.0 6 | # via pre-commit 7 | click==8.1.8 8 | # via pydoclint 9 | dill==0.4.0 10 | # via pylint 11 | distlib==0.3.9 12 | # via virtualenv 13 | doc8==1.1.2 14 | # via -r examples/requirements/style_checkers.in 15 | docstring-parser-fork==0.0.12 16 | # via pydoclint 17 | docutils==0.21.2 18 | # via 19 | # doc8 20 | # restructuredtext-lint 21 | filelock==3.18.0 22 | # via virtualenv 23 | identify==2.6.10 24 | # via pre-commit 25 | isort==6.0.1 26 | # via pylint 27 | mccabe==0.7.0 28 | # via pylint 29 | nodeenv==1.9.1 30 | # via pre-commit 31 | pbr==6.1.1 32 | # via stevedore 33 | platformdirs==4.3.7 34 | # via 35 | # pylint 36 | # virtualenv 37 | pre-commit==4.2.0 38 | # via -r examples/requirements/style_checkers.in 39 | pydoclint==0.6.6 40 | # via -r examples/requirements/style_checkers.in 41 | pydocstyle==6.3.0 42 | # via -r examples/requirements/style_checkers.in 43 | pyflakes==3.3.2 44 | # via -r examples/requirements/style_checkers.in 45 | pygments==2.19.1 46 | # via doc8 47 | pylint==3.3.6 48 | # via -r examples/requirements/style_checkers.in 49 | pyyaml==6.0.2 50 | # via pre-commit 51 | restructuredtext-lint==1.4.0 52 | # via doc8 53 | ruff==0.11.8 54 | # via -r examples/requirements/style_checkers.in 55 | setuptools==80.1.0 56 | # via pbr 57 | snowballstemmer==2.2.0 58 | # via pydocstyle 59 | stevedore==5.4.1 60 | # via doc8 61 | tomli==2.2.1 62 | # via 63 | # doc8 64 | # pydoclint 65 | # pylint 66 | tomlkit==0.13.2 67 | # via pylint 68 | typing-extensions==4.13.2 69 | # via astroid 70 | virtualenv==20.30.0 71 | # via pre-commit 72 | -------------------------------------------------------------------------------- /examples/requirements/test.in: -------------------------------------------------------------------------------- 1 | Faker 2 | asyncssh 3 | coverage 4 | factory_boy 5 | fuzzywuzzy[speedup] 6 | moto>=5.0.0 7 | parametrize 8 | py 9 | pytest-codeblock 10 | pytest-cov 11 | pytest-django 12 | pytest-ordering 13 | pytest-parallel 14 | pytest-rerunfailures 15 | pytest>=7.0.1 16 | tox 17 | -------------------------------------------------------------------------------- /examples/requirements/testing.in: -------------------------------------------------------------------------------- 1 | -r django_4_2.in 2 | -r test.in 3 | -------------------------------------------------------------------------------- /examples/sqlalchemy_example/README.rst: -------------------------------------------------------------------------------- 1 | ============================================= 2 | SQLAlchemy example project for ``faker-file`` 3 | ============================================= 4 | *Used mainly for SQLAlchemy/Flask-Admin integration show-off.* 5 | 6 | Migrate 7 | ======= 8 | .. code-block:: shell 9 | 10 | cd faker_file_admin 11 | alembic upgrade head 12 | 13 | Run server 14 | ========== 15 | .. code-block:: shell 16 | 17 | python examples/sqlalchemy_example/run_server.py 18 | 19 | Testing 20 | ======= 21 | .. code-block:: shell 22 | 23 | pytest -c pytest_sqlalchemy.ini src/faker_file/ 24 | -------------------------------------------------------------------------------- /examples/sqlalchemy_example/faker_file_admin/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | import os.path as op 3 | 4 | from flask import Flask, request, session 5 | from flask_babelex import Babel 6 | from flask_sqlalchemy import SQLAlchemy 7 | 8 | from .data import build_sample_db 9 | 10 | app: Flask 11 | db: SQLAlchemy 12 | 13 | 14 | def create_app(config_filename: str) -> Flask: 15 | global app 16 | app = Flask(__name__) 17 | app.config.from_pyfile(config_filename) 18 | 19 | global db 20 | db = SQLAlchemy(app) 21 | 22 | with app.app_context(): 23 | # Build a sample db on the fly, if one does not exist yet. 24 | app_dir = op.join( 25 | op.realpath(os.path.dirname(__file__)), "faker_file_admin" 26 | ) 27 | database_path = op.join(app_dir, app.config["DATABASE_FILE"]) 28 | if not os.path.exists(database_path): 29 | build_sample_db(db) 30 | 31 | return app 32 | 33 | 34 | create_app("config.py") 35 | 36 | 37 | # Initialize babel 38 | babel = Babel(app) 39 | 40 | 41 | @babel.localeselector 42 | def get_locale(): 43 | override = request.args.get("lang") 44 | 45 | if override: 46 | session["lang"] = override 47 | 48 | return session.get("lang", "en") 49 | 50 | 51 | import faker_file_admin.main # noqa 52 | -------------------------------------------------------------------------------- /examples/sqlalchemy_example/faker_file_admin/alembic.ini: -------------------------------------------------------------------------------- 1 | # A generic, single database configuration. 2 | 3 | [alembic] 4 | # path to migration scripts 5 | script_location = alembic 6 | 7 | # template used to generate migration files 8 | # file_template = %%(rev)s_%%(slug)s 9 | 10 | # sys.path path, will be prepended to sys.path if present. 11 | # defaults to the current working directory. 12 | prepend_sys_path = . 13 | 14 | # timezone to use when rendering the date 15 | # within the migration file as well as the filename. 16 | # string value is passed to dateutil.tz.gettz() 17 | # leave blank for localtime 18 | # timezone = 19 | 20 | # max length of characters to apply to the 21 | # "slug" field 22 | # truncate_slug_length = 40 23 | 24 | # set to 'true' to run the environment during 25 | # the 'revision' command, regardless of autogenerate 26 | # revision_environment = false 27 | 28 | # set to 'true' to allow .pyc and .pyo files without 29 | # a source .py file to be detected as revisions in the 30 | # versions/ directory 31 | # sourceless = false 32 | 33 | # version location specification; this defaults 34 | # to alembic/versions. When using multiple version 35 | # directories, initial revisions must be specified with --version-path 36 | # version_locations = %(here)s/bar %(here)s/bat alembic/versions 37 | 38 | # the output encoding used when revision files 39 | # are written from script.py.mako 40 | # output_encoding = utf-8 41 | 42 | sqlalchemy.url = sqlite:///../instance/sample_db.sqlite 43 | 44 | 45 | [post_write_hooks] 46 | # post_write_hooks defines scripts or Python functions that are run 47 | # on newly generated revision scripts. See the documentation for further 48 | # detail and examples 49 | 50 | # format using "black" - use the console_scripts runner, against the "black" entrypoint 51 | # hooks = black 52 | # black.type = console_scripts 53 | # black.entrypoint = black 54 | # black.options = -l 79 REVISION_SCRIPT_FILENAME 55 | 56 | # Logging configuration 57 | [loggers] 58 | keys = root,sqlalchemy,alembic 59 | 60 | [handlers] 61 | keys = console 62 | 63 | [formatters] 64 | keys = generic 65 | 66 | [logger_root] 67 | level = WARN 68 | handlers = console 69 | qualname = 70 | 71 | [logger_sqlalchemy] 72 | level = WARN 73 | handlers = 74 | qualname = sqlalchemy.engine 75 | 76 | [logger_alembic] 77 | level = INFO 78 | handlers = 79 | qualname = alembic 80 | 81 | [handler_console] 82 | class = StreamHandler 83 | args = (sys.stderr,) 84 | level = NOTSET 85 | formatter = generic 86 | 87 | [formatter_generic] 88 | format = %(levelname)-5.5s [%(name)s] %(message)s 89 | datefmt = %H:%M:%S 90 | -------------------------------------------------------------------------------- /examples/sqlalchemy_example/faker_file_admin/alembic/README: -------------------------------------------------------------------------------- 1 | Generic single-database configuration. 2 | -------------------------------------------------------------------------------- /examples/sqlalchemy_example/faker_file_admin/alembic/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/examples/sqlalchemy_example/faker_file_admin/alembic/__init__.py -------------------------------------------------------------------------------- /examples/sqlalchemy_example/faker_file_admin/alembic/env.py: -------------------------------------------------------------------------------- 1 | from logging.config import fileConfig 2 | 3 | from alembic import context 4 | from sqlalchemy import engine_from_config, pool 5 | 6 | # this is the Alembic Config object, which provides 7 | # access to the values within the .ini file in use. 8 | config = context.config 9 | 10 | # Interpret the config file for Python logging. 11 | # This line sets up loggers basically. 12 | fileConfig(config.config_file_name) 13 | 14 | # add your model's MetaData object here 15 | # for 'autogenerate' support 16 | # from myapp import mymodel 17 | # target_metadata = mymodel.Base.metadata 18 | target_metadata = None 19 | 20 | # other values from the config, defined by the needs of env.py, 21 | # can be acquired: 22 | # my_important_option = config.get_main_option("my_important_option") 23 | # ... etc. 24 | 25 | 26 | def run_migrations_offline(): 27 | """Run migrations in 'offline' mode. 28 | 29 | This configures the context with just a URL 30 | and not an Engine, though an Engine is acceptable 31 | here as well. By skipping the Engine creation 32 | we don't even need a DBAPI to be available. 33 | 34 | Calls to context.execute() here emit the given string to the 35 | script output. 36 | 37 | """ 38 | url = config.get_main_option("sqlalchemy.url") 39 | context.configure( 40 | url=url, 41 | target_metadata=target_metadata, 42 | literal_binds=True, 43 | dialect_opts={"paramstyle": "named"}, 44 | ) 45 | 46 | with context.begin_transaction(): 47 | context.run_migrations() 48 | 49 | 50 | def run_migrations_online(): 51 | """Run migrations in 'online' mode. 52 | 53 | In this scenario we need to create an Engine 54 | and associate a connection with the context. 55 | 56 | """ 57 | connectable = engine_from_config( 58 | config.get_section(config.config_ini_section), 59 | prefix="sqlalchemy.", 60 | poolclass=pool.NullPool, 61 | ) 62 | 63 | with connectable.connect() as connection: 64 | context.configure( 65 | connection=connection, target_metadata=target_metadata 66 | ) 67 | 68 | with context.begin_transaction(): 69 | context.run_migrations() 70 | 71 | 72 | if context.is_offline_mode(): 73 | run_migrations_offline() 74 | else: 75 | run_migrations_online() 76 | -------------------------------------------------------------------------------- /examples/sqlalchemy_example/faker_file_admin/alembic/script.py.mako: -------------------------------------------------------------------------------- 1 | """${message} 2 | 3 | Revision ID: ${up_revision} 4 | Revises: ${down_revision | comma,n} 5 | Create Date: ${create_date} 6 | 7 | """ 8 | from alembic import op 9 | import sqlalchemy as sa 10 | ${imports if imports else ""} 11 | 12 | # revision identifiers, used by Alembic. 13 | revision = ${repr(up_revision)} 14 | down_revision = ${repr(down_revision)} 15 | branch_labels = ${repr(branch_labels)} 16 | depends_on = ${repr(depends_on)} 17 | 18 | 19 | def upgrade(): 20 | ${upgrades if upgrades else "pass"} 21 | 22 | 23 | def downgrade(): 24 | ${downgrades if downgrades else "pass"} 25 | -------------------------------------------------------------------------------- /examples/sqlalchemy_example/faker_file_admin/alembic/versions/2695cb77cdf2_create_product_table.py: -------------------------------------------------------------------------------- 1 | """create upload table 2 | 3 | Revision ID: 2695cb77cdf2 4 | Revises: 5 | Create Date: 2022-12-06 23:46:09.000000 6 | 7 | """ 8 | 9 | import sqlalchemy as sa 10 | from alembic import op 11 | 12 | # revision identifiers, used by Alembic. 13 | revision = "2695cb77cdf2" 14 | down_revision = None 15 | branch_labels = None 16 | depends_on = None 17 | 18 | 19 | def upgrade(): 20 | op.create_table( 21 | "upload", 22 | sa.Column("id", sa.Integer, primary_key=True), 23 | sa.Column("name", sa.String(64), nullable=False), 24 | sa.Column("description", sa.Text(), nullable=True), 25 | sa.Column("file", sa.String(255), nullable=False), 26 | ) 27 | 28 | 29 | def downgrade(): 30 | op.drop_table("upload") 31 | -------------------------------------------------------------------------------- /examples/sqlalchemy_example/faker_file_admin/alembic/versions/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/examples/sqlalchemy_example/faker_file_admin/alembic/versions/__init__.py -------------------------------------------------------------------------------- /examples/sqlalchemy_example/faker_file_admin/config.py: -------------------------------------------------------------------------------- 1 | # set optional bootswatch theme 2 | # see http://bootswatch.com/3/ for available swatches 3 | FLASK_ADMIN_SWATCH = "cerulean" 4 | 5 | # Create dummy secrey key so we can use sessions 6 | SECRET_KEY = "123456790" 7 | 8 | # Create in-memory database 9 | DATABASE_FILE = "../instance/sample_db.sqlite" 10 | SQLALCHEMY_DATABASE_URI = "sqlite:///" + DATABASE_FILE 11 | SQLALCHEMY_ECHO = True 12 | SQLALCHEMY_TRACK_MODIFICATIONS = False 13 | -------------------------------------------------------------------------------- /examples/sqlalchemy_example/faker_file_admin/config_test.py: -------------------------------------------------------------------------------- 1 | # set optional bootswatch theme 2 | # see http://bootswatch.com/3/ for available swatches 3 | FLASK_ADMIN_SWATCH = "cerulean" 4 | 5 | # Create dummy secrey key so we can use sessions 6 | SECRET_KEY = "123456790" 7 | 8 | # Create in-memory database 9 | DATABASE_FILE = "sample_db_test.sqlite" 10 | SQLALCHEMY_DATABASE_URI = "sqlite://" 11 | SQLALCHEMY_ECHO = True 12 | SQLALCHEMY_TRACK_MODIFICATIONS = False 13 | -------------------------------------------------------------------------------- /examples/sqlalchemy_example/faker_file_admin/data.py: -------------------------------------------------------------------------------- 1 | def build_sample_db(db): 2 | """Populate a small db with some example entries.""" 3 | 4 | db.drop_all() 5 | db.create_all() 6 | db.session.commit() 7 | return 8 | -------------------------------------------------------------------------------- /examples/sqlalchemy_example/faker_file_admin/main.py: -------------------------------------------------------------------------------- 1 | import flask_admin as admin 2 | from flask import send_file 3 | from flask_admin.contrib import sqla 4 | 5 | from . import app, db 6 | from .models import Upload 7 | 8 | 9 | # Flask views 10 | @app.route("/") 11 | def index(): 12 | tmp = """ 13 |

Click me to get to Admin! (English)

14 |

Click me to get to Admin! (Czech)

15 |

Click me to get to Admin! (German)

16 |

Click me to get to Admin! (Spanish)

17 |

Click me to get to Admin! (Farsi)

18 |

Click me to get to Admin! (French)

19 |

Click me to get to Admin! (Portuguese)

20 |

Click me to get to Admin! (Russian)

21 |

Click me to get to Admin! (Punjabi)

22 |

23 | Click me to get to Admin! (Chinese - Simplified)

24 |

25 | Click me to get to Admin! (Chinese - Traditional)

26 | """ 27 | return tmp 28 | 29 | 30 | @app.route("/favicon.ico") 31 | def favicon(): 32 | return send_file("static/favicon.ico") 33 | 34 | 35 | # Create admin 36 | admin = admin.Admin(app, name="Example: SQLAlchemy", template_mode="bootstrap4") 37 | 38 | # Add views 39 | admin.add_view(sqla.ModelView(Upload, db.session)) 40 | -------------------------------------------------------------------------------- /examples/sqlalchemy_example/faker_file_admin/models.py: -------------------------------------------------------------------------------- 1 | from . import db 2 | 3 | __all__ = ("Upload",) 4 | 5 | 6 | class Upload(db.Model): 7 | """Upload model.""" 8 | 9 | __tablename__ = "upload" 10 | __table_args__ = {"extend_existing": True} 11 | 12 | id = db.Column(db.Integer, primary_key=True) 13 | name = db.Column(db.Unicode(64), unique=True) 14 | description = db.Column(db.Integer(), nullable=True) 15 | file = db.Column(db.Unicode(255)) 16 | 17 | def __str__(self) -> str: 18 | return f"{self.name}" 19 | -------------------------------------------------------------------------------- /examples/sqlalchemy_example/faker_file_admin/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/examples/sqlalchemy_example/faker_file_admin/static/favicon.ico -------------------------------------------------------------------------------- /examples/sqlalchemy_example/faker_file_admin/templates/admin/index.html: -------------------------------------------------------------------------------- 1 | {% extends 'admin/master.html' %} 2 | {% block body %} 3 | {{ super() }} 4 |
5 |
6 |
7 |

Flask-Admin {{ _gettext('example') }}

8 |

9 | Basic SQLAlchemy model views. 10 |

11 |

12 | This example shows how to add basic CRUD-views for your SQLAlchemy models. 13 |

14 |

15 | The views are generated automatically, but it is perfectly possible to customize them to suit your needs. 16 |

17 | {{ _gettext('Back') }} 18 |
19 |
20 |
21 | {% endblock body %} 22 | -------------------------------------------------------------------------------- /examples/sqlalchemy_example/faker_file_admin/templates/tree_list.html: -------------------------------------------------------------------------------- 1 | {% extends 'admin/model/list.html' %} 2 | 3 | {% block body %} 4 |

5 | This view demonstrated a tree structure, where there's a recursive relationship 6 | between records on the same table. 7 |

8 |

9 | It also demonstrates how to extend the builtin list.html template, and 10 | pass your own parameters to the template. E.g. the parameter: foo, which 11 | has the value {{ foo }}, passed in dynamically from the {{ h.get_current_view().name }} view. 12 |

13 | {{ super() }} 14 | {% endblock %} 15 | -------------------------------------------------------------------------------- /examples/sqlalchemy_example/run_server.py: -------------------------------------------------------------------------------- 1 | from faker_file_admin import app 2 | 3 | if __name__ == "__main__": 4 | # Start app 5 | app.run(debug=True) 6 | -------------------------------------------------------------------------------- /examples/sqlalchemy_example/sqlalchemy_factories/__init__.py: -------------------------------------------------------------------------------- 1 | from .faker_file_admin_upload import * # noqa 2 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal = 1 3 | 4 | [wheel] 5 | universal = 1 6 | 7 | [metadata] 8 | license-file = LICENSE.rst 9 | 10 | [doc8] 11 | # doc8 configuration: https://pypi.org/project/doc8/ 12 | ignore-path = 13 | docs/_build, 14 | builddocs/, 15 | examples/requirements/*.in, 16 | examples/requirements/*.txt, 17 | examples/django_example/project/static/*, 18 | examples/django_example/project/media/tmp/*, 19 | src/faker_file.egg-info, 20 | tmp/, 21 | max-line-length = 80 22 | sphinx = true 23 | -------------------------------------------------------------------------------- /src/faker_file/__init__.py: -------------------------------------------------------------------------------- 1 | __title__ = "faker_file" 2 | __version__ = "0.18.4" 3 | __author__ = "Artur Barseghyan " 4 | __copyright__ = "2022-2025 Artur Barseghyan" 5 | __license__ = "MIT" 6 | -------------------------------------------------------------------------------- /src/faker_file/cli/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/src/faker_file/cli/__init__.py -------------------------------------------------------------------------------- /src/faker_file/cli/command.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import sys 3 | import typing 4 | 5 | from .. import __version__ 6 | 7 | __author__ = "Artur Barseghyan " 8 | __copyright__ = "2023 Artur Barseghyan" 9 | __license__ = "MIT" 10 | __all__ = ("main",) 11 | 12 | 13 | def main(): 14 | try: 15 | from .helpers import ( 16 | PROVIDERS, 17 | generate_completion_file, 18 | generate_file, 19 | get_method_kwargs, 20 | is_optional_type, 21 | ) 22 | except ImportError: 23 | print("You need to pip install faker-file[common] to use the CLI") 24 | sys.exit(1) 25 | 26 | parser = argparse.ArgumentParser( 27 | description="CLI for the faker-file package." 28 | ) 29 | subparsers = parser.add_subparsers( 30 | dest="command", help="Available file providers." 31 | ) 32 | 33 | # Add generate-completion subparser 34 | __generate_completion_subparser = subparsers.add_parser( 35 | "generate-completion", 36 | help="Generate bash completion file.", 37 | ) 38 | 39 | # Add version subparser 40 | __version_subparser = subparsers.add_parser( 41 | "version", 42 | help="Print version.", 43 | ) 44 | 45 | for method_name, provider in PROVIDERS.items(): 46 | subparser = subparsers.add_parser( 47 | method_name, 48 | help=f"Generate a {method_name.split('_file')[0]} file.", 49 | ) 50 | method_kwargs, annotations = get_method_kwargs(provider, method_name) 51 | for arg, default in method_kwargs.items(): 52 | arg_type = annotations[arg] 53 | arg_kwargs = { 54 | "default": default, 55 | "help": f"{arg} (default: {default})", 56 | "type": ( 57 | arg_type.__args__[0] 58 | if isinstance(arg_type, typing._GenericAlias) 59 | and is_optional_type(arg_type) 60 | else arg_type 61 | ), 62 | } 63 | 64 | subparser.add_argument(f"--{arg}", **arg_kwargs) 65 | 66 | # Add the optional num_files argument 67 | subparser.add_argument( 68 | "--nb_files", 69 | default=1, 70 | type=int, 71 | help="number of files to generate (default: 1)", 72 | ) 73 | 74 | args = parser.parse_args() 75 | 76 | if args.command == "generate-completion": 77 | generate_completion_file() 78 | elif args.command == "version": 79 | print(__version__) 80 | elif args.command: 81 | kwargs = {k: v for k, v in vars(args).items() if k not in ("command",)} 82 | for counter in range(args.nb_files): 83 | output_file = generate_file(args.command, **kwargs) 84 | print( 85 | f"Generated {args.command} file " 86 | f"({counter+1} of {args.nb_files}): " 87 | f"{output_file.data['filename']}" 88 | ) 89 | else: 90 | parser.print_help() 91 | sys.exit(1) 92 | -------------------------------------------------------------------------------- /src/faker_file/constants.py: -------------------------------------------------------------------------------- 1 | __author__ = "Artur Barseghyan " 2 | __copyright__ = "2022-2025 Artur Barseghyan" 3 | __license__ = "MIT" 4 | __all__ = ( 5 | "DEFAULT_AUDIO_MAX_NB_CHARS", 6 | "DEFAULT_FILE_ENCODING", 7 | "DEFAULT_FONT_NAME", 8 | "DEFAULT_FONT_PATH", 9 | "DEFAULT_IMAGE_MAX_NB_CHARS", 10 | "DEFAULT_TEXT_CONTENT_TEMPLATE", 11 | "DEFAULT_TEXT_MAX_NB_CHARS", 12 | "DEFAULT_XML_DATA_COLUMNS", 13 | ) 14 | 15 | DEFAULT_AUDIO_MAX_NB_CHARS = 500 16 | DEFAULT_FILE_ENCODING = "utf-8" 17 | DEFAULT_IMAGE_MAX_NB_CHARS = 5_000 18 | DEFAULT_TEXT_CONTENT_TEMPLATE = """{{text}}""" 19 | DEFAULT_TEXT_MAX_NB_CHARS = 10_000 20 | DEFAULT_FONT_NAME = "Vera" 21 | DEFAULT_FONT_PATH = "Vera.ttf" 22 | DEFAULT_XML_DATA_COLUMNS = { 23 | "name": "{{name}}", 24 | "address": "{{address}}", 25 | } 26 | -------------------------------------------------------------------------------- /src/faker_file/contrib/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/src/faker_file/contrib/__init__.py -------------------------------------------------------------------------------- /src/faker_file/contrib/image/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/src/faker_file/contrib/image/__init__.py -------------------------------------------------------------------------------- /src/faker_file/contrib/image/imgkit_snippets.py: -------------------------------------------------------------------------------- 1 | from ..pdf_file.pdfkit_snippets import * # noqa 2 | 3 | __author__ = "Artur Barseghyan " 4 | __copyright__ = "2022-2025 Artur Barseghyan" 5 | __license__ = "MIT" 6 | -------------------------------------------------------------------------------- /src/faker_file/contrib/image/pil_snippets.py: -------------------------------------------------------------------------------- 1 | from ..pdf_file.pil_snippets import * # noqa 2 | 3 | __author__ = "Artur Barseghyan " 4 | __copyright__ = "2022-2025 Artur Barseghyan" 5 | __license__ = "MIT" 6 | -------------------------------------------------------------------------------- /src/faker_file/contrib/pdf_file/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/src/faker_file/contrib/pdf_file/__init__.py -------------------------------------------------------------------------------- /src/faker_file/providers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/src/faker_file/providers/__init__.py -------------------------------------------------------------------------------- /src/faker_file/providers/augment_file_from_dir/augmenters/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/src/faker_file/providers/augment_file_from_dir/augmenters/__init__.py -------------------------------------------------------------------------------- /src/faker_file/providers/augment_file_from_dir/augmenters/nlpaug_augmenter.py: -------------------------------------------------------------------------------- 1 | import nlpaug.augmenter.word as naw 2 | 3 | from ...base.text_augmenter import BaseTextAugmenter 4 | 5 | __author__ = "Artur Barseghyan " 6 | __copyright__ = "2022-2025 Artur Barseghyan" 7 | __license__ = "MIT" 8 | __all__ = ( 9 | "ContextualWordEmbeddingsAugmenter", 10 | "DEFAULT_ACTION", 11 | "DEFAULT_MODEL_PATH", 12 | ) 13 | 14 | DEFAULT_MODEL_PATH = "bert-base-multilingual-cased" 15 | DEFAULT_ACTION = "substitute" 16 | 17 | 18 | class ContextualWordEmbeddingsAugmenter(BaseTextAugmenter): 19 | """Text extractor based on `ContextualWordEmbsAug` of `nlpaug`. 20 | 21 | Usage example: 22 | 23 | .. code-block:: python 24 | 25 | from faker import Faker 26 | from faker_file.providers.augment_file_from_dir import ( 27 | AugmentFileFromDirProvider, 28 | ) 29 | from faker_file.providers.augment_file_from_dir.augmenters import ( 30 | nlpaug_augmenter, 31 | ) 32 | 33 | FAKER = Faker() 34 | FAKER.add_provider(AugmentFileFromDirProvider) 35 | 36 | file = FAKER.augment_file_from_dir( 37 | source_dir_path="/tmp/tmp/", 38 | text_augmenter_cls=( 39 | nlpaug_augmenter.ContextualWordEmbeddingsAugmenter 40 | ), 41 | text_augmenter_kwargs={ 42 | "model_path": "bert-base-uncased", 43 | "action": "substitute", 44 | } 45 | ) 46 | 47 | Refer to `nlpaug` official documentation and check examples 48 | for `Textual augmenters`: 49 | 50 | https://nlpaug.readthedocs.io/en/latest/example/example.html 51 | 52 | Some well working options for `model_path` are: 53 | 54 | - bert-base-multilingual-cased 55 | - bert-base-multilingual-uncased 56 | - bert-base-cased 57 | - bert-base-uncased 58 | - bert-base-german-cased 59 | - GroNLP/bert-base-dutch-cased 60 | 61 | Options for `action` are: 62 | 63 | - insert 64 | - substitute 65 | """ 66 | 67 | model_path: str = DEFAULT_MODEL_PATH 68 | action: str = DEFAULT_ACTION 69 | 70 | def handle_kwargs( 71 | self: "ContextualWordEmbeddingsAugmenter", **kwargs 72 | ) -> None: 73 | """Handle kwargs.""" 74 | if "model_path" in kwargs: 75 | self.model_path = kwargs["model_path"] 76 | if "action" in kwargs: 77 | self.action = kwargs["action"] 78 | 79 | def augment( 80 | self: "ContextualWordEmbeddingsAugmenter", 81 | text: str, 82 | ) -> str: 83 | """Augment text.""" 84 | aug = naw.ContextualWordEmbsAug( 85 | model_path=self.model_path, 86 | action=self.action, 87 | ) 88 | return aug.augment(text)[0] 89 | -------------------------------------------------------------------------------- /src/faker_file/providers/augment_file_from_dir/augmenters/textaugment_augmenter.py: -------------------------------------------------------------------------------- 1 | from typing import Any, Dict, Type 2 | 3 | import nltk 4 | from textaugment import EDA 5 | 6 | from ...base.text_augmenter import BaseTextAugmenter 7 | 8 | __author__ = "Artur Barseghyan " 9 | __copyright__ = "2022-2025 Artur Barseghyan" 10 | __license__ = "MIT" 11 | __all__ = ( 12 | "EDATextaugmentAugmenter", 13 | "DEFAULT_ACTION", 14 | ) 15 | 16 | DEFAULT_ACTION = "synonym_replacement" 17 | 18 | 19 | class EDATextaugmentAugmenter(BaseTextAugmenter): 20 | """Text extractor based on `ContextualWordEmbsAug` of `nlpaug`. 21 | 22 | Usage example: 23 | 24 | .. code-block:: python 25 | 26 | from faker import Faker 27 | from faker_file.providers.augment_file_from_dir import ( 28 | AugmentFileFromDirProvider, 29 | ) 30 | from faker_file.providers.augment_file_from_dir.augmenters import ( 31 | textaugment_augmenter, 32 | ) 33 | 34 | FAKER = Faker() 35 | FAKER.add_provider(AugmentFileFromDirProvider) 36 | 37 | file = FAKER.augment_file_from_dir( 38 | source_dir_path="/tmp/tmp/", 39 | text_augmenter_cls=( 40 | textaugment_augmenter.EDATextaugmentAugmenter 41 | ), 42 | text_augmenter_kwargs={ 43 | "action": "random_insertion", 44 | } 45 | ) 46 | 47 | Refer to `textaugment` official documentation and check examples for `EDA`: 48 | 49 | ://github.com/dsfsi/textaugment/blob/master/examples/eda_example.ipynb 50 | 51 | Options for `action` are: 52 | 53 | - random_deletion 54 | - random_insertion 55 | - random_swap 56 | - synonym_replacement 57 | """ 58 | 59 | action: str = DEFAULT_ACTION 60 | kwargs: Dict[str, Any] = {} 61 | _data_downloaded: bool = False 62 | 63 | def handle_kwargs(self: "EDATextaugmentAugmenter", **kwargs) -> None: 64 | """Handle kwargs.""" 65 | if "action" in kwargs: 66 | self.action = kwargs["action"] 67 | if "kwargs" in kwargs: 68 | self.kwargs = kwargs["kwargs"] 69 | self.__class__.init() 70 | 71 | @classmethod 72 | def init(cls: Type["EDATextaugmentAugmenter"]) -> None: 73 | """Initialize the class. Should be run only once.""" 74 | if not cls._data_downloaded: 75 | nltk.download("punkt") 76 | nltk.download("wordnet") 77 | nltk.download("stopwords") 78 | cls._data_downloaded = True 79 | 80 | def augment(self: "EDATextaugmentAugmenter", text: str) -> str: 81 | """Augment text.""" 82 | aug = EDA() 83 | func = getattr(aug, self.action) 84 | return func(text, **self.kwargs) 85 | -------------------------------------------------------------------------------- /src/faker_file/providers/augment_file_from_dir/extractors/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/src/faker_file/providers/augment_file_from_dir/extractors/__init__.py -------------------------------------------------------------------------------- /src/faker_file/providers/augment_file_from_dir/extractors/tika_extractor.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | from typing import Union 3 | 4 | import tika 5 | from tika import parser 6 | 7 | from ...base.text_extractor import BaseTextExtractor 8 | 9 | __author__ = "Artur Barseghyan " 10 | __copyright__ = "2022-2025 Artur Barseghyan" 11 | __license__ = "MIT" 12 | __all__ = ("TikaTextExtractor",) 13 | 14 | 15 | class TikaTextExtractor(BaseTextExtractor): 16 | """Text extractor based on `Apache Tika` and `tika-python`. 17 | 18 | Usage example: 19 | 20 | .. code-block:: python 21 | 22 | from faker import Faker 23 | from faker_file.providers.augment_file_from_dir import ( 24 | AugmentFileFromDirProvider, 25 | ) 26 | from faker_file.providers.augment_file_from_dir.extractors import ( 27 | tika_extractor, 28 | ) 29 | 30 | FAKER = Faker() 31 | FAKER.add_provider(AugmentFileFromDirProvider) 32 | 33 | file = FAKER.augment_file_from_dir( 34 | text_extractor_cls=tika_extractor.TikaTextExtractor 35 | ) 36 | """ 37 | 38 | def handle_kwargs(self: "TikaTextExtractor", **kwargs) -> None: 39 | """Handle kwargs.""" 40 | 41 | def extract( 42 | self: "TikaTextExtractor", 43 | source_file: Union[Path, str], 44 | ) -> str: 45 | """Extract text.""" 46 | tika.initVM() 47 | parsed = parser.from_file(str(source_file)) 48 | return parsed["content"] 49 | -------------------------------------------------------------------------------- /src/faker_file/providers/base/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/src/faker_file/providers/base/__init__.py -------------------------------------------------------------------------------- /src/faker_file/providers/base/image_generator.py: -------------------------------------------------------------------------------- 1 | from typing import Any, Dict, Union 2 | 3 | from faker import Faker 4 | from faker.generator import Generator 5 | from faker.providers.python import Provider 6 | 7 | __author__ = "Artur Barseghyan " 8 | __copyright__ = "2022-2025 Artur Barseghyan" 9 | __license__ = "MIT" 10 | __all__ = ("BaseImageGenerator",) 11 | 12 | 13 | class BaseImageGenerator: 14 | """Base image generator.""" 15 | 16 | def __init__( 17 | self: "BaseImageGenerator", 18 | **kwargs, 19 | ) -> None: 20 | """Constructor. 21 | 22 | :param kwargs: Dictionary with parameters (for PDF generator 23 | specific tuning). 24 | """ 25 | self.handle_kwargs(**kwargs) 26 | 27 | def handle_kwargs(self: "BaseImageGenerator", **kwargs): 28 | """Handle kwargs.""" 29 | 30 | def generate( 31 | self: "BaseImageGenerator", 32 | content: str, 33 | data: Dict[str, Any], 34 | provider: Union[Faker, Generator, Provider], 35 | ) -> bytes: 36 | raise NotImplementedError("Method `generate` is not implemented.") 37 | -------------------------------------------------------------------------------- /src/faker_file/providers/base/mp3_generator.py: -------------------------------------------------------------------------------- 1 | from typing import Union 2 | 3 | from faker import Faker 4 | from faker.generator import Generator 5 | from faker.providers.python import Provider 6 | 7 | __author__ = "Artur Barseghyan " 8 | __copyright__ = "2022-2025 Artur Barseghyan" 9 | __license__ = "MIT" 10 | __all__ = ("BaseMp3Generator",) 11 | 12 | 13 | class BaseMp3Generator: 14 | """Base MP3 generator.""" 15 | 16 | content: str 17 | generator: Union[Faker, Generator, Provider] 18 | 19 | def __init__( 20 | self: "BaseMp3Generator", 21 | content: str, 22 | generator: Union[Faker, Generator, Provider], 23 | **kwargs, 24 | ) -> None: 25 | """Constructor. 26 | 27 | :param content: Text content to generate MP3 from. 28 | :param generator: `Faker` instance that could contain useful 29 | information, such as active locale. 30 | :param kwargs: Dictionary with parameters (for MP3 generator 31 | specific tuning). 32 | """ 33 | self.content = content 34 | self.generator = generator 35 | self.handle_kwargs(**kwargs) 36 | 37 | def handle_kwargs(self: "BaseMp3Generator", **kwargs): 38 | """Handle kwargs.""" 39 | 40 | def generate(self: "BaseMp3Generator", **kwargs) -> bytes: 41 | raise NotImplementedError("Method `generate` is not implemented.") 42 | -------------------------------------------------------------------------------- /src/faker_file/providers/base/pdf_generator.py: -------------------------------------------------------------------------------- 1 | from typing import Any, Dict, Union 2 | 3 | from faker import Faker 4 | from faker.generator import Generator 5 | from faker.providers.python import Provider 6 | 7 | __author__ = "Artur Barseghyan " 8 | __copyright__ = "2022-2025 Artur Barseghyan" 9 | __license__ = "MIT" 10 | __all__ = ("BasePdfGenerator",) 11 | 12 | 13 | class BasePdfGenerator: 14 | """Base PDF generator.""" 15 | 16 | def __init__( 17 | self: "BasePdfGenerator", 18 | **kwargs, 19 | ) -> None: 20 | """Constructor. 21 | 22 | :param kwargs: Dictionary with parameters (for PDF generator 23 | specific tuning). 24 | """ 25 | self.handle_kwargs(**kwargs) 26 | 27 | def handle_kwargs(self: "BasePdfGenerator", **kwargs): 28 | """Handle kwargs.""" 29 | 30 | def generate( 31 | self: "BasePdfGenerator", 32 | content: str, 33 | data: Dict[str, Any], 34 | provider: Union[Faker, Generator, Provider], 35 | ) -> bytes: 36 | raise NotImplementedError("Method `generate` is not implemented.") 37 | -------------------------------------------------------------------------------- /src/faker_file/providers/base/text_augmenter.py: -------------------------------------------------------------------------------- 1 | __author__ = "Artur Barseghyan " 2 | __copyright__ = "2022-2025 Artur Barseghyan" 3 | __license__ = "MIT" 4 | __all__ = ("BaseTextAugmenter",) 5 | 6 | 7 | class BaseTextAugmenter: 8 | """Base text augmenter.""" 9 | 10 | def __init__( 11 | self: "BaseTextAugmenter", 12 | **kwargs, 13 | ) -> None: 14 | """Constructor. 15 | 16 | :param kwargs: Dictionary with parameters (for text extractor 17 | specific tuning). 18 | """ 19 | self.handle_kwargs(**kwargs) 20 | 21 | def handle_kwargs(self: "BaseTextAugmenter", **kwargs): 22 | """Handle kwargs.""" 23 | 24 | def augment( 25 | self: "BaseTextAugmenter", 26 | text: str, 27 | ) -> str: 28 | raise NotImplementedError("Method `augment` is not implemented.") 29 | -------------------------------------------------------------------------------- /src/faker_file/providers/base/text_extractor.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | from typing import Union 3 | 4 | __author__ = "Artur Barseghyan " 5 | __copyright__ = "2022-2025 Artur Barseghyan" 6 | __license__ = "MIT" 7 | __all__ = ("BaseTextExtractor",) 8 | 9 | 10 | class BaseTextExtractor: 11 | """Base text extractor.""" 12 | 13 | path: str 14 | 15 | def __init__( 16 | self: "BaseTextExtractor", 17 | **kwargs, 18 | ) -> None: 19 | """Constructor. 20 | 21 | :param kwargs: Dictionary with parameters (for text extractor 22 | specific tuning). 23 | """ 24 | self.handle_kwargs(**kwargs) 25 | 26 | def handle_kwargs(self: "BaseTextExtractor", **kwargs): 27 | """Handle kwargs.""" 28 | 29 | def extract( 30 | self: "BaseTextExtractor", 31 | source_file: Union[Path, str], 32 | ) -> str: 33 | raise NotImplementedError("Method `extract` is not implemented.") 34 | -------------------------------------------------------------------------------- /src/faker_file/providers/file_from_url.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/src/faker_file/providers/file_from_url.py -------------------------------------------------------------------------------- /src/faker_file/providers/helpers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/src/faker_file/providers/helpers/__init__.py -------------------------------------------------------------------------------- /src/faker_file/providers/image/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/src/faker_file/providers/image/__init__.py -------------------------------------------------------------------------------- /src/faker_file/providers/mixins/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/src/faker_file/providers/mixins/__init__.py -------------------------------------------------------------------------------- /src/faker_file/providers/mp3_file/generators/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/src/faker_file/providers/mp3_file/generators/__init__.py -------------------------------------------------------------------------------- /src/faker_file/providers/mp3_file/generators/edge_tts_generator.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import logging 3 | from io import BytesIO 4 | 5 | import edge_tts 6 | 7 | from ...base.mp3_generator import BaseMp3Generator 8 | 9 | __author__ = "Artur Barseghyan " 10 | __copyright__ = "2022-2025 Artur Barseghyan" 11 | __license__ = "MIT" 12 | __all__ = ("EdgeTtsMp3Generator",) 13 | 14 | DEFAULT_VOICE = "en-GB-SoniaNeural" 15 | LOGGER = logging.getLogger(__name__) 16 | 17 | 18 | class EdgeTtsMp3Generator(BaseMp3Generator): 19 | """Edge Text-to-Speech generator. 20 | 21 | Usage example: 22 | 23 | .. code-block:: python 24 | 25 | from faker import Faker 26 | from faker_file.providers.mp3_file import Mp3FileProvider 27 | from faker_file.providers.mp3_file.generators import edge_tts_generator 28 | 29 | FAKER = Faker() 30 | FAKER.add_provider(Mp3FileProvider) 31 | 32 | file = FAKER.mp3_file( 33 | mp3_generator_cls=edge_tts_generator.EdgeTtsMp3Generator 34 | ) 35 | """ 36 | 37 | voice: str = DEFAULT_VOICE 38 | 39 | def handle_kwargs(self: "EdgeTtsMp3Generator", **kwargs) -> None: 40 | if "voice" in kwargs: 41 | self.voice = kwargs["voice"] 42 | 43 | def generate(self: "EdgeTtsMp3Generator", **kwargs) -> bytes: 44 | """Generate MP3.""" 45 | with BytesIO() as _fake_file: 46 | 47 | async def _generate(): 48 | """Async generate. 49 | 50 | edge-tts is an async library. We can't use it in non-async 51 | context. Therefore, this trick. 52 | """ 53 | async for chunk in edge_tts.Communicate( 54 | self.content, self.voice 55 | ).stream(): 56 | if chunk["type"] == "audio": 57 | _fake_file.write(chunk["data"]) 58 | elif chunk["type"] == "WordBoundary": 59 | LOGGER.debug(f"WordBoundary: {chunk}") 60 | 61 | # Run the async function 62 | loop = asyncio.get_event_loop_policy().new_event_loop() 63 | loop.run_until_complete(_generate()) 64 | # Return result 65 | loop.close() 66 | return _fake_file.getvalue() 67 | -------------------------------------------------------------------------------- /src/faker_file/providers/mp3_file/generators/gtts_generator.py: -------------------------------------------------------------------------------- 1 | from io import BytesIO 2 | 3 | from gtts import gTTS 4 | 5 | from ...base.mp3_generator import BaseMp3Generator 6 | 7 | __author__ = "Artur Barseghyan " 8 | __copyright__ = "2022-2025 Artur Barseghyan" 9 | __license__ = "MIT" 10 | __all__ = ("GttsMp3Generator",) 11 | 12 | 13 | DEFAULT_LANG = "en" 14 | DEFAULT_TLD = "com" 15 | 16 | 17 | class GttsMp3Generator(BaseMp3Generator): 18 | """Google Text-to-Speech generator. 19 | 20 | Usage example: 21 | 22 | .. code-block:: python 23 | 24 | from faker import Faker 25 | from faker_file.providers.mp3_file import Mp3FileProvider 26 | from faker_file.providers.mp3_file.generators.gtts_generator import ( 27 | GttsMp3Generator, 28 | ) 29 | 30 | FAKER = Faker() 31 | FAKER.add_provider(Mp3FileProvider) 32 | 33 | file = FAKER.mp3_file( 34 | mp3_generator_cls=GttsMp3Generator 35 | ) 36 | """ 37 | 38 | lang: str = DEFAULT_LANG 39 | tld: str = DEFAULT_TLD 40 | 41 | def handle_kwargs(self: "GttsMp3Generator", **kwargs) -> None: 42 | if "lang" in kwargs: 43 | self.lang = kwargs["lang"] 44 | if "tld" in kwargs: 45 | self.tld = kwargs["tld"] 46 | 47 | def generate(self: "GttsMp3Generator", **kwargs) -> bytes: 48 | """Generate MP3.""" 49 | with BytesIO() as __fake_file: 50 | tts = gTTS(self.content, lang=self.lang, tld=self.tld) 51 | tts.write_to_fp(__fake_file) 52 | return __fake_file.getvalue() 53 | -------------------------------------------------------------------------------- /src/faker_file/providers/pdf_file/generators/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/src/faker_file/providers/pdf_file/generators/__init__.py -------------------------------------------------------------------------------- /src/faker_file/registry.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from threading import Lock 3 | from typing import Optional, Set, Union 4 | 5 | from .base import StringValue 6 | 7 | __author__ = "Artur Barseghyan " 8 | __copyright__ = "2022-2025 Artur Barseghyan" 9 | __license__ = "MIT" 10 | __all__ = ( 11 | "FILE_REGISTRY", 12 | "FileRegistry", 13 | ) 14 | 15 | 16 | LOGGER = logging.getLogger(__name__) 17 | 18 | 19 | class FileRegistry: 20 | """Stores list `StringValue` instances. 21 | 22 | .. code-block:: python 23 | 24 | from faker import Faker 25 | from faker_file.providers.txt_file import TxtFileProvider 26 | 27 | FAKER = Faker() 28 | FAKER.add_provider(TxtFileProvider) 29 | 30 | txt_file_1 = FAKER.txt_file() 31 | txt_file_2 = FAKER.txt_file() 32 | ... 33 | txt_file_n = FAKER.txt_file() 34 | 35 | # The FileRegistry._registry would then contain this: 36 | { 37 | txt_file_1, 38 | txt_file_2, 39 | ..., 40 | txt_file_n, 41 | } 42 | """ 43 | 44 | def __init__(self): 45 | self._registry: Set[StringValue] = set() 46 | self._lock = Lock() 47 | 48 | def add(self, string_value: StringValue) -> None: 49 | with self._lock: 50 | self._registry.add(string_value) 51 | 52 | def remove(self, string_value: Union[StringValue, str]) -> bool: 53 | if not isinstance(string_value, StringValue): 54 | string_value = self.search(string_value) 55 | 56 | if not string_value: 57 | return False 58 | 59 | with self._lock: 60 | # No error if the element doesn't exist 61 | self._registry.discard(string_value) 62 | try: 63 | string_value.data["storage"].unlink( 64 | string_value.data["filename"] 65 | ) 66 | return True 67 | except Exception as e: 68 | LOGGER.error( 69 | f"Failed to unlink file " 70 | f"{string_value.data['filename']}: {e}" 71 | ) 72 | return False 73 | 74 | def search(self, value: str) -> Optional[StringValue]: 75 | with self._lock: 76 | for string_value in self._registry: 77 | if string_value == value: 78 | return string_value 79 | return None 80 | 81 | def clean_up(self) -> None: 82 | with self._lock: 83 | while self._registry: 84 | file = self._registry.pop() 85 | try: 86 | file.data["storage"].unlink(file.data["filename"]) 87 | except Exception as err: 88 | LOGGER.error( 89 | f"Failed to unlink file {file.data['filename']}: {err}" 90 | ) 91 | 92 | 93 | FILE_REGISTRY = FileRegistry() 94 | -------------------------------------------------------------------------------- /src/faker_file/storages/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/src/faker_file/storages/__init__.py -------------------------------------------------------------------------------- /src/faker_file/storages/aws_s3.py: -------------------------------------------------------------------------------- 1 | from .pathy_based.aws_s3 import AWSS3Storage 2 | 3 | __author__ = "Artur Barseghyan " 4 | __copyright__ = "2022-2025 Artur Barseghyan" 5 | __license__ = "MIT" 6 | __all__ = ("AWSS3Storage",) 7 | -------------------------------------------------------------------------------- /src/faker_file/storages/azure_cloud_storage.py: -------------------------------------------------------------------------------- 1 | from .pathy_based.azure_cloud_storage import AzureCloudStorage 2 | 3 | __author__ = "Artur Barseghyan " 4 | __copyright__ = "2022-2025 Artur Barseghyan" 5 | __license__ = "MIT" 6 | __all__ = ("AzureCloudStorage",) 7 | -------------------------------------------------------------------------------- /src/faker_file/storages/base.py: -------------------------------------------------------------------------------- 1 | import random 2 | import string 3 | from typing import Any, Optional 4 | 5 | __author__ = "Artur Barseghyan " 6 | __copyright__ = "2022-2025 Artur Barseghyan" 7 | __license__ = "MIT" 8 | __all__ = ("BaseStorage",) 9 | 10 | 11 | class BaseStorage: 12 | """Base storage.""" 13 | 14 | def __init__(self, *args, **kwargs) -> None: 15 | self.args = args 16 | self.kwargs = kwargs 17 | 18 | def generate_basename( 19 | self: "BaseStorage", 20 | prefix: str = "tmp", 21 | length: int = 8, 22 | ) -> str: 23 | """Generate a random alphanumeric sequence.""" 24 | if not prefix: 25 | prefix = "tmp" 26 | # Use lowercase letters, digits and underscore 27 | characters = string.ascii_lowercase + string.digits + "_" 28 | return prefix + "".join(random.choices(characters, k=length)) 29 | 30 | def generate_filename( 31 | self: "BaseStorage", 32 | extension: str, 33 | prefix: Optional[str] = None, 34 | basename: Optional[str] = None, 35 | ) -> Any: 36 | """Generate filename.""" 37 | raise NotImplementedError( 38 | "Method generate_filename is not implemented!" 39 | ) 40 | 41 | def write_text( 42 | self: "BaseStorage", 43 | filename: Any, 44 | data: str, 45 | encoding: Optional[str] = None, 46 | ) -> int: 47 | """Write text.""" 48 | raise NotImplementedError("Method write_text is not implemented!") 49 | 50 | def write_bytes(self: "BaseStorage", filename: Any, data: bytes) -> int: 51 | """Write bytes.""" 52 | raise NotImplementedError("Method write_bytes is not implemented!") 53 | 54 | def exists(self: "BaseStorage", filename: Any) -> bool: 55 | """Check if file exists.""" 56 | raise NotImplementedError("Method exists is not implemented!") 57 | 58 | def relpath(self: "BaseStorage", filename: Any) -> str: 59 | """Return relative path.""" 60 | raise NotImplementedError("Method relpath is not implemented!") 61 | 62 | def abspath(self: "BaseStorage", filename: Any) -> str: 63 | """Return absolute path.""" 64 | raise NotImplementedError("Method abspath is not implemented!") 65 | 66 | def unlink(self: "BaseStorage", filename: Any) -> None: 67 | """Delete the file.""" 68 | raise NotImplementedError("Method unlink is not implemented!") 69 | -------------------------------------------------------------------------------- /src/faker_file/storages/cloud.py: -------------------------------------------------------------------------------- 1 | from .pathy_based.cloud import ( 2 | CloudStorage, 3 | LocalCloudFileSystemStorage, 4 | PathyFileSystemStorage, 5 | ) 6 | 7 | __author__ = "Artur Barseghyan " 8 | __copyright__ = "2022-2025 Artur Barseghyan" 9 | __license__ = "MIT" 10 | __all__ = ( 11 | "CloudStorage", 12 | "LocalCloudFileSystemStorage", 13 | "PathyFileSystemStorage", 14 | ) 15 | -------------------------------------------------------------------------------- /src/faker_file/storages/google_cloud_storage.py: -------------------------------------------------------------------------------- 1 | from .pathy_based.google_cloud_storage import GoogleCloudStorage 2 | 3 | __author__ = "Artur Barseghyan " 4 | __copyright__ = "2022-2025 Artur Barseghyan" 5 | __license__ = "MIT" 6 | __all__ = ("GoogleCloudStorage",) 7 | -------------------------------------------------------------------------------- /src/faker_file/storages/pathy_based/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/src/faker_file/storages/pathy_based/__init__.py -------------------------------------------------------------------------------- /src/faker_file/storages/pathy_based/aws_s3.py: -------------------------------------------------------------------------------- 1 | from pathy import set_client_params 2 | 3 | from .cloud import CloudStorage 4 | 5 | __author__ = "Artur Barseghyan " 6 | __copyright__ = "2022-2025 Artur Barseghyan" 7 | __license__ = "MIT" 8 | __all__ = ("AWSS3Storage",) 9 | 10 | 11 | class AWSS3Storage(CloudStorage): 12 | """AWS S3 Storage. 13 | 14 | Usage example: 15 | 16 | .. code-block:: python 17 | 18 | from faker_file.storages.aws_s3 import AWSS3Storage 19 | 20 | s3_storage = AWSS3Storage( 21 | bucket_name="artur-testing-1", 22 | rel_path="tmp", 23 | ) 24 | file = s3_storage.generate_filename(prefix="zzz_", extension="docx") 25 | s3_storage.write_text(file, "Lorem ipsum") 26 | s3_storage.write_bytes(file, b"Lorem ipsum") 27 | """ 28 | 29 | schema: str = "s3" 30 | 31 | def authenticate( 32 | self: "AWSS3Storage", key_id: str, key_secret: str, **kwargs 33 | ) -> None: 34 | """Authenticate to AWS S3.""" 35 | set_client_params("s3", key_id=key_id, key_secret=key_secret) 36 | -------------------------------------------------------------------------------- /src/faker_file/storages/pathy_based/azure_cloud_storage.py: -------------------------------------------------------------------------------- 1 | from pathy import set_client_params 2 | 3 | from .cloud import CloudStorage 4 | 5 | __author__ = "Artur Barseghyan " 6 | __copyright__ = "2022-2025 Artur Barseghyan" 7 | __license__ = "MIT" 8 | __all__ = ("AzureCloudStorage",) 9 | 10 | 11 | class AzureCloudStorage(CloudStorage): 12 | """Azure Cloud Storage. 13 | 14 | Usage example: 15 | 16 | .. code-block:: python 17 | 18 | from faker_file.storages.azure_cloud_storage import AzureCloudStorage 19 | 20 | azure_storage = AzureCloudStorage( 21 | bucket_name="artur-testing-1", 22 | rel_path="tmp", 23 | ) 24 | file = azure_storage.generate_filename(prefix="zzz_", extension="docx") 25 | azure_storage.write_text(file, "Lorem ipsum") 26 | azure_storage.write_bytes(file, b"Lorem ipsum") 27 | """ 28 | 29 | schema = "azure" 30 | 31 | def authenticate( 32 | self: "AzureCloudStorage", connection_string: str, **kwargs 33 | ) -> None: 34 | """Authenticate to Azure Cloud Storage.""" 35 | set_client_params("azure", connection_string=connection_string) 36 | -------------------------------------------------------------------------------- /src/faker_file/storages/pathy_based/google_cloud_storage.py: -------------------------------------------------------------------------------- 1 | from google.oauth2 import service_account 2 | from pathy import set_client_params 3 | 4 | from .cloud import CloudStorage 5 | 6 | __author__ = "Artur Barseghyan " 7 | __copyright__ = "2022-2025 Artur Barseghyan" 8 | __license__ = "MIT" 9 | __all__ = ("GoogleCloudStorage",) 10 | 11 | 12 | class GoogleCloudStorage(CloudStorage): 13 | """Google Cloud Storage. 14 | 15 | Usage example: 16 | 17 | .. code-block:: python 18 | 19 | from faker_file.storages.google_cloud_storage import GoogleCloudStorage 20 | 21 | gs_storage = GoogleCloudStorage( 22 | bucket_name="artur-testing-1", 23 | rel_path="tmp", 24 | ) 25 | file = gs_storage.generate_filename(prefix="zzz_", extension="docx") 26 | gs_storage.write_text(file, "Lorem ipsum") 27 | gs_storage.write_bytes(file, b"Lorem ipsum") 28 | """ 29 | 30 | schema = "gs" 31 | 32 | def authenticate( 33 | self: "GoogleCloudStorage", json_file_path: str, **kwargs 34 | ) -> None: 35 | """Authenticate to Google Cloud Storage.""" 36 | credentials = service_account.Credentials.from_service_account_file( 37 | json_file_path 38 | ) 39 | set_client_params("gs", credentials=credentials) 40 | -------------------------------------------------------------------------------- /src/faker_file/storages/pathy_based/helpers.py: -------------------------------------------------------------------------------- 1 | import importlib.metadata 2 | from typing import Union 3 | 4 | from packaging import version 5 | 6 | __author__ = "Artur Barseghyan " 7 | __copyright__ = "2022-2025 Artur Barseghyan" 8 | __license__ = "MIT" 9 | __all__ = ("is_legacy_pathy_version",) 10 | 11 | 12 | def is_legacy_pathy_version() -> Union[bool, None]: 13 | """Check if a pathy version is less than 0.11. 14 | 15 | :return: True if `pathy` version is less than 0.11. 16 | False if `pathy` version is greater or equal than 0.11. 17 | None if `pathy` is not installed. 18 | :rtype: Union[bool, None] 19 | """ 20 | try: 21 | current_version = importlib.metadata.version("pathy") 22 | except importlib.metadata.PackageNotFoundError: 23 | return None 24 | return version.parse(current_version) < version.parse("0.11") 25 | -------------------------------------------------------------------------------- /src/faker_file/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/faker-file/4bed05141d2fbef6b979f9ce9f1fae1e17fa9d0c/src/faker_file/tests/__init__.py -------------------------------------------------------------------------------- /src/faker_file/tests/_conftest.py: -------------------------------------------------------------------------------- 1 | """ 2 | Configuration hooks for pytest. Normally this wouldn't be necessary, 3 | but since `pytest-codeblock` is used, we want to clean-up files generated by 4 | running documentation tests. Therefore, this hook, which simply 5 | calls the `clean_up` method of the `FILE_REGISTRY` instance. 6 | """ 7 | 8 | from faker_file.registry import FILE_REGISTRY 9 | from moto import mock_aws 10 | from pytest_codeblock.constants import CODEBLOCK_MARK 11 | 12 | __author__ = "Artur Barseghyan " 13 | __copyright__ = "2022-2025 Artur Barseghyan" 14 | __license__ = "MIT" 15 | __all__ = ( 16 | "pytest_runtest_teardown", 17 | "pytest_collection_modifyitems", 18 | ) 19 | 20 | # Modify test item during collection 21 | def pytest_collection_modifyitems(config, items): 22 | for item in items: 23 | if item.get_closest_marker("aws"): 24 | # Apply `mock_aws` to all tests marked as `aws` 25 | item.obj = mock_aws(item.obj) 26 | 27 | 28 | def pytest_runtest_teardown(item, nextitem): 29 | """Clean up after test ends.""" 30 | if item.get_closest_marker(CODEBLOCK_MARK): 31 | FILE_REGISTRY.clean_up() 32 | -------------------------------------------------------------------------------- /src/faker_file/tests/test_augment.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | import pytest 4 | from PIL import Image, ImageDraw 5 | 6 | from ..providers.image.augment import solarize 7 | 8 | __author__ = "Artur Barseghyan " 9 | __copyright__ = "2022-2025 Artur Barseghyan" 10 | __license__ = "MIT" 11 | __all__ = ("TestSolarizeFunction",) 12 | 13 | 14 | @pytest.mark.ml 15 | class TestSolarizeFunction(unittest.TestCase): 16 | """Test `solarize` function.""" 17 | 18 | def create_rgba_image(self): 19 | """Create a sample RGBA image.""" 20 | img = Image.new("RGBA", (100, 100), (150, 60, 90, 255)) 21 | draw = ImageDraw.Draw(img) 22 | draw.rectangle((25, 25, 75, 75), fill=(60, 170, 210, 200)) 23 | return img 24 | 25 | def create_rgb_image(self): 26 | """Create a sample RGB image.""" 27 | img = Image.new("RGB", (100, 100), (150, 60, 90)) 28 | draw = ImageDraw.Draw(img) 29 | draw.rectangle((25, 25, 75, 75), fill=(60, 170, 210)) 30 | return img 31 | 32 | def test_solarize_rgba(self): 33 | img = self.create_rgba_image() 34 | solarized_img = solarize(img) 35 | 36 | # Assuming values above 128 are inverted, check some pixel values 37 | self.assertEqual(solarized_img.getpixel((10, 10)), (105, 60, 90, 255)) 38 | self.assertEqual( 39 | solarized_img.getpixel((50, 50)), (60, 85, 45, 200) 40 | ) # Alpha should remain unaffected 41 | 42 | def test_solarize_rgb(self): 43 | img = self.create_rgb_image() 44 | solarized_img = solarize(img) 45 | 46 | # Assuming values above 128 are inverted, check some pixel values 47 | self.assertEqual(solarized_img.getpixel((10, 10)), (105, 60, 90)) 48 | self.assertEqual(solarized_img.getpixel((50, 50)), (60, 85, 45)) 49 | -------------------------------------------------------------------------------- /src/faker_file/tests/test_django_integration.py: -------------------------------------------------------------------------------- 1 | from typing import Any, Callable, Dict 2 | 3 | from django.conf import settings 4 | from django.core.files.storage import default_storage 5 | from django.test import TestCase 6 | from faker import Faker 7 | from parametrize import parametrize 8 | from storages.backends.s3boto3 import S3Boto3Storage 9 | 10 | import factories 11 | 12 | from ..registry import FILE_REGISTRY 13 | from ..storages.aws_s3 import AWSS3Storage 14 | from ..storages.filesystem import FileSystemStorage 15 | 16 | __author__ = "Artur Barseghyan " 17 | __copyright__ = "2022-2025 Artur Barseghyan" 18 | __license__ = "MIT" 19 | __all__ = ("DjangoIntegrationTestCase",) 20 | 21 | 22 | # Faker doesn't know anything about Django. That's why, if we want to support 23 | # remote storages, we need to manually check which file storage backend is 24 | # used. If `Boto3` storage backend (of the `django-storages` package) is used 25 | # we use the correspondent `AWSS3Storage` class of the `faker-file`. 26 | # Otherwise, fall back to native file system storage (`FileSystemStorage`) of 27 | # the `faker-file`. 28 | if isinstance(default_storage, S3Boto3Storage): 29 | STORAGE = AWSS3Storage( 30 | bucket_name=settings.AWS_STORAGE_BUCKET_NAME, 31 | credentials={ 32 | "key_id": settings.AWS_ACCESS_KEY_ID, 33 | "key_secret": settings.AWS_SECRET_ACCESS_KEY, 34 | }, 35 | rel_path="tmp", 36 | ) 37 | else: 38 | STORAGE = FileSystemStorage(root_path=settings.MEDIA_ROOT, rel_path="tmp") 39 | 40 | 41 | class DjangoIntegrationTestCase(TestCase): 42 | """Django integration test case.""" 43 | 44 | FAKER: Faker 45 | 46 | def tearDown(self, *args, **kwargs) -> None: 47 | super().tearDown(*args, **kwargs) 48 | FILE_REGISTRY.clean_up() 49 | 50 | @parametrize( 51 | "factory, kwargs", 52 | [ 53 | (factories.UploadFactory, {}), 54 | (factories.UploadFactory, {"random_file": True}), 55 | (factories.UploadFactory, {"pdf_file": True}), 56 | (factories.UploadFactory, {"pptx_file": True}), 57 | (factories.UploadFactory, {"txt_file": True}), 58 | (factories.UploadFactory, {"zip_file": True}), 59 | ], 60 | ) 61 | def test_file( 62 | self: "DjangoIntegrationTestCase", 63 | factory: Callable, 64 | kwargs: Dict[str, Any], 65 | ) -> None: 66 | """Test file.""" 67 | _upload = factory(**kwargs) 68 | if kwargs: 69 | self.assertTrue(STORAGE.exists(_upload.file.name)) 70 | -------------------------------------------------------------------------------- /src/faker_file/tests/test_helpers.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from copy import deepcopy 3 | 4 | from ..helpers import random_pop 5 | 6 | __author__ = "Artur Barseghyan " 7 | __copyright__ = "2022-2025 Artur Barseghyan" 8 | __license__ = "MIT" 9 | __all__ = ("HelpersTestCase",) 10 | 11 | 12 | class HelpersTestCase(unittest.TestCase): 13 | """Test StringList test case.""" 14 | 15 | def test_random_pop_empty_list(self: "HelpersTestCase") -> None: 16 | """Test `random_pop`.""" 17 | my_list = [] 18 | element = random_pop(my_list) 19 | self.assertIsNone(element) 20 | 21 | def test_random_pop(self: "HelpersTestCase") -> None: 22 | """Test `random_pop`.""" 23 | my_list = [1, 2, 3, 4, 5] 24 | orig_my_list = deepcopy(my_list) 25 | while len(my_list): 26 | element = random_pop(my_list) 27 | self.assertIn(element, orig_my_list) 28 | self.assertNotIn(element, my_list) 29 | -------------------------------------------------------------------------------- /src/faker_file/tests/test_sqlalchemy_integration.py: -------------------------------------------------------------------------------- 1 | from typing import Any, Callable, Dict 2 | from unittest import TestCase 3 | 4 | import pytest 5 | from faker import Faker 6 | from parametrize import parametrize 7 | from sqlalchemy import create_engine 8 | from sqlalchemy.orm import sessionmaker 9 | 10 | import sqlalchemy_factories as factories 11 | from faker_file_admin import app 12 | from faker_file_admin.models import Upload 13 | 14 | from ..registry import FILE_REGISTRY 15 | from ..storages.filesystem import FileSystemStorage 16 | 17 | __author__ = "Artur Barseghyan " 18 | __copyright__ = "2022-2025 Artur Barseghyan" 19 | __license__ = "MIT" 20 | __all__ = ("SQLAlchemyIntegrationTestCase",) 21 | 22 | 23 | STORAGE = FileSystemStorage(root_path="", rel_path="tmp") 24 | 25 | 26 | @pytest.mark.sqlalchemy 27 | class SQLAlchemyIntegrationTestCase(TestCase): 28 | """SQLAlchemy integration test case.""" 29 | 30 | engine = create_engine("sqlite:///:memory:") 31 | Session = sessionmaker(bind=engine) 32 | session = Session() 33 | 34 | def setUp(self: "SQLAlchemyIntegrationTestCase"): 35 | Upload.metadata.create_all(self.engine) 36 | self.session.commit() 37 | 38 | def tearDown(self: "SQLAlchemyIntegrationTestCase"): 39 | Upload.metadata.drop_all(self.engine) 40 | FILE_REGISTRY.clean_up() 41 | 42 | FAKER: Faker 43 | 44 | @parametrize( 45 | "factory, kwargs", 46 | [ 47 | (factories.UploadFactory, {}), 48 | (factories.UploadFactory, {"random_file": True}), 49 | (factories.UploadFactory, {"pdf_file": True}), 50 | (factories.UploadFactory, {"pptx_file": True}), 51 | (factories.UploadFactory, {"txt_file": True}), 52 | (factories.UploadFactory, {"zip_file": True}), 53 | ], 54 | ) 55 | @pytest.mark.optional 56 | def test_file( 57 | self: "SQLAlchemyIntegrationTestCase", 58 | factory: Callable, 59 | kwargs: Dict[str, Any], 60 | ) -> None: 61 | """Test file.""" 62 | with app.app_context(): 63 | _upload = factory(**kwargs) 64 | self.session.commit() 65 | if kwargs: 66 | self.assertTrue(STORAGE.exists(_upload.file)) 67 | -------------------------------------------------------------------------------- /tests.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | relative_files = True 3 | 4 | [report] 5 | show_missing = True 6 | exclude_lines = 7 | pragma: no cover 8 | # raise NotImplementedError 9 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = 3 | ; py{39,310,311}-django{42} 4 | ; py{310,311}-django{50} 5 | py{39,310,311}-django{42,50}-pathy{0103,0110} 6 | py312-django{42,50}-pathy0110 7 | 8 | [testenv] 9 | envlogdir={work_dir}/{env_name}/tmp 10 | passenv = * 11 | allowlist_externals=* 12 | deps = 13 | django42: -r{toxinidir}/examples/requirements/django_4_2.txt 14 | django50: -r{toxinidir}/examples/requirements/django_5_0.txt 15 | pathy0103: pathy==0.10.3 16 | pathy0110: pathy==0.11.0 17 | commands = 18 | mkdir -p examples/django_example/project/media/ 19 | mkdir -p examples/django_example/project/static/ 20 | pip install -e .[all] 21 | {envpython} -m pytest -vrx -m "not optional" --ignore src/faker_file/tests/test_sqlalchemy_integration.py --ignore src/faker_file/tests/test_augment_file_from_dir_provider.py 22 | 23 | [gh-actions] 24 | python = 25 | 3.9: py39 26 | 3.10: py310 27 | 3.11: py311 28 | 3.12: py312 29 | --------------------------------------------------------------------------------