faker.providers.file

class faker.providers.file.Provider(generator)

Bases: faker.providers.BaseProvider

Implement default file provider for Faker.

file_extension(category=None)

Generate a file extension under the specified category.

If category is None, a random category will be used. The list of valid categories include: 'audio', 'image', 'office', 'text', and 'video'.

Examples:
>>> Faker.seed(0)
>>> for _ in range(5):
...     fake.file_extension()
...
'webm'
'xlsx'
'pptx'
'csv'
'ods'
>>> Faker.seed(0)
>>> for _ in range(5):
...     fake.file_extension(category='image')
...
'tiff'
'png'
'jpeg'
'gif'
'jpg'
file_name(category=None, extension=None)

Generate a random file name with extension.

If extension is None, a random extension will be created under the hood using file_extension() with the specified category. If a value for extension is provided, the value will be used instead, and category will be ignored. The actual name part itself is generated using word().

Examples:
>>> Faker.seed(0)
>>> for _ in range(10):
...     fake.file_name()
...
'inside.webm'
'if.jpg'
'live.csv'
'measure.key'
'peace.png'
'work.tiff'
'financial.webm'
'range.txt'
'its.docx'
'whom.txt'
>>> Faker.seed(0)
>>> for _ in range(5):
...     fake.file_name(category='audio')
...
'serious.wav'
'else.mp3'
'if.mp3'
'field.wav'
'on.mp3'
>>> Faker.seed(0)
>>> for _ in range(5):
...     fake.file_name(extension='abcdef')
...
'such.abcdef'
'serious.abcdef'
'inside.abcdef'
'else.abcdef'
'memory.abcdef'
>>> Faker.seed(0)
>>> for _ in range(5):
...     fake.file_name(category='audio', extension='abcdef')
...
'such.abcdef'
'serious.abcdef'
'inside.abcdef'
'else.abcdef'
'memory.abcdef'
file_path(depth=1, category=None, extension=None)

Generate an absolute pathname to a file.

This method uses file_name() under the hood to generate the file name itself, and depth controls the depth of the directory path, and word() is used under the hood to generate the different directory names.

Examples:
>>> Faker.seed(0)
>>> for _ in range(10):
...     fake.file_path()
...
'/else/inside.webm'
'/field/six.pptx'
'/measure/traditional.ods'
'/economy/peace.png'
'/total/special.webm'
'/range/together.png'
'/particularly/its.docx'
'/tend/local.webm'
'/add/nature.png'
'/property/station.html'
>>> Faker.seed(0)
>>> for _ in range(5):
...     fake.file_path(depth=3)
...
'/if/memory/else/inside.webm'
'/measure/traditional/on/live.csv'
'/work/travel/economy/peace.png'
'/range/together/role/financial.webm'
'/whom/tree/particularly/its.docx'
>>> Faker.seed(0)
>>> for _ in range(5):
...     fake.file_path(depth=5, category='video')
...
'/six/if/memory/else/inside/serious.webm'
'/sense/example/measure/traditional/on/live.avi'
'/financial/total/special/work/travel/economy.mov'
'/particularly/its/beyond/line/range/together.mov'
'/nature/source/employee/tend/local/whom.webm'
>>> Faker.seed(0)
>>> for _ in range(5):
...     fake.file_path(depth=5, category='video', extension='abcdef')
...
'/if/memory/else/inside/serious/such.abcdef'
'/measure/traditional/on/live/field/six.abcdef'
'/work/travel/economy/peace/sense/example.abcdef'
'/range/together/role/financial/total/special.abcdef'
'/whom/tree/particularly/its/beyond/line.abcdef'
mime_type(category=None)

Generate a mime type under the specified category.

If category is None, a random category will be used. The list of valid categories include 'application', 'audio', 'image', 'message', 'model', 'multipart', 'text', and 'video'.

Examples:
>>> Faker.seed(0)
>>> for _ in range(5):
...     fake.mime_type()
...
'text/vcard'
'message/imdn+xml'
'model/mesh'
'text/csv'
'message/partial'
>>> Faker.seed(0)
>>> for _ in range(5):
...     fake.mime_type(category='application')
...
'application/xop+xml'
'application/xhtml+xml'
'application/ogg'
'application/json'
'application/postscript'
unix_device(prefix=None)

Generate a Unix device file name.

If prefix is None, a random prefix will be used. The list of valid prefixes include: 'sd', 'vd', and 'xvd'.

Examples:
>>> Faker.seed(0)
>>> for _ in range(5):
...     fake.unix_device()
...
'/dev/xvdt'
'/dev/vdg'
'/dev/vdk'
'/dev/xvdh'
'/dev/vdp'
>>> Faker.seed(0)
>>> for _ in range(5):
...     fake.unix_device(prefix='mmcblk')
...
'/dev/mmcblkv'
'/dev/mmcblkt'
'/dev/mmcblkk'
'/dev/mmcblkg'
'/dev/mmcblkn'
unix_partition(prefix=None)

Generate a Unix partition name.

This method uses unix_device() under the hood to create a device file name with the specified prefix.

Examples:
>>> Faker.seed(0)
>>> for _ in range(5):
...     fake.unix_partition()
...
'/dev/xvdt6'
'/dev/sdz7'
'/dev/vdu4'
'/dev/xvdj3'
'/dev/vdh1'
>>> Faker.seed(0)
>>> for _ in range(5):
...     fake.unix_partition(prefix='mmcblk')
...
'/dev/mmcblkv6'
'/dev/mmcblkb8'
'/dev/mmcblkm4'
'/dev/mmcblkz5'
'/dev/mmcblkp3'