Generate fake files.
Project description
Generate fake files
Prerequisites
Core package requires Python 3.7, 3.8, 3.9, 3.10 and 3.11.
Django integration (with factory_boy) has been tested with Django 2.2, 3.0, 3.1, 3.2, 4.0 and 4.1.
DOCX file support requires python-docx.
ICO, JPEG, PNG, SVG and WEBP files support requires imgkit.
PDF file support requires pdfkit.
PPTX file support requires python-pptx.
XLSX file support requires openpyxl.
Documentation
Documentation is available on Read the Docs.
Installation
Latest stable version on PyPI:
pip install faker-file[all]
Or development version from GitHub:
pip install https://github.com/barseghyanartur/faker-file/archive/main.tar.gz
Supported file types
BIN
CSV
DOCX
ICO
JPEG
PDF
PNG
PPTX
SVG
TXT
WEBP
XLSX
ZIP
Usage examples
With Faker
One way
from faker import Faker
from faker_file.providers.txt_file import TxtFileProvider
FAKER = Faker()
file = TxtFileProvider(FAKER).txt_file()
Or another
from faker import Faker
from faker_file.providers.txt_file import TxtFileProvider
FAKER = Faker()
FAKER.add_provider(TxtFileProvider)
file = FAKER.txt_file()
With factory_boy
upload/models.py
from django.db import models
class Upload(models.Model):
# ...
file = models.FileField()
upload/factory.py
Note, that when using faker-file with Django, you need to pass your MEDIA_ROOT setting as root_path value (which is by default set to tempfile.gettempdir()).
import factory
from django.conf import settings
from factory import Faker
from factory.django import DjangoModelFactory
from faker_file.providers.docx_file import DocxFileProvider
from upload.models import Upload
factory.Faker.add_provider(DocxFileProvider)
class UploadFactory(DjangoModelFactory):
# ...
file = Faker("docx_file", root_path=settings.MEDIA_ROOT)
class Meta:
model = Upload
Testing
Simply type:
pytest -vvv
Or use tox:
tox
Or use tox to check specific env:
tox -e py310-django41
Writing documentation
Keep the following hierarchy.
=====
title
=====
header
======
sub-header
----------
sub-sub-header
~~~~~~~~~~~~~~
sub-sub-sub-header
^^^^^^^^^^^^^^^^^^
sub-sub-sub-sub-header
++++++++++++++++++++++
sub-sub-sub-sub-sub-header
**************************
License
MIT
Support
For any security issues contact me at the e-mail given in the Author section.
For overall issues, go to GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for faker_file-0.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | caded1ab56f1d2a37449e49eaa81835f5889f611a97626bf6930ca896c6f2ee3 |
|
MD5 | f07a0c4bf87011030e505f58ccfaff87 |
|
BLAKE2b-256 | 4b202a2b1dac5e41780a52513bdcb0abde62184f1b3302e42f761cf3f5b53ea4 |