VOOZH about

URL: https://pypi.org/project/Faker/0.8.3/

⇱ Faker Β· PyPI


Skip to main content

Faker 0.8.3

pip install Faker==0.8.3

Newer version available (40.23.0)

Released:

Faker is a Python package that generates fake data for you.

Navigation

Verified details

These details have been verified by PyPI
Maintainers
πŸ‘ Avatar for curella.org from gravatar.com
curella.org πŸ‘ Avatar for joke2k from gravatar.com
joke2k

Unverified details

These details have not been verified by PyPI
Project links
Meta
  • License: MIT License (MIT License)
  • Author: joke2k
  • Tags faker , fixtures , data , test , mock , generator

Project description

Faker is a Python package that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you.

Faker is heavily inspired by PHP Faker, Perl Faker, and by Ruby Faker.


_|_|_|_| _|
_| _|_|_| _| _| _|_| _| _|_|
_|_|_| _| _| _|_| _|_|_|_| _|_|
_| _| _| _| _| _| _|
_| _|_|_| _| _| _|_|_| _|

πŸ‘ Latest version released on PyPi
πŸ‘ Build status of the master branch on Mac/Linux
πŸ‘ Build status of the master branch on Windows
πŸ‘ Test coverage
πŸ‘ Package license


For more details, see the extended docs.

Basic Usage

Install with pip:

pipinstallFaker

Note: this package was previously called fake-factory.

Use faker.Faker() to create and initialize a faker generator, which can generate data by accessing properties named after the type of data you want.

from faker import Fakerfake = Faker()fake.name()# 'Lucy Cechtelar'fake.address()# "426 Jordy Lodge# Cartwrightshire, SC 88120-6700"fake.text()# Sint velit eveniet. Rerum atque repellat voluptatem quia rerum. Numquam excepturi# beatae sint laudantium consequatur. Magni occaecati itaque sint et sit tempore. Nesciunt# amet quidem. Iusto deleniti cum autem ad quia aperiam.# A consectetur quos aliquam. In iste aliquid et aut similique suscipit. Consequatur qui# quaerat iste minus hic expedita. Consequuntur error magni et laboriosam. Aut aspernatur# voluptatem sit aliquam. Dolores voluptatum est.# Aut molestias et maxime. Fugit autem facilis quos vero. Eius quibusdam possimus est.# Ea quaerat et quisquam. Deleniti sunt quam. Adipisci consequatur id in occaecati.# Et sint et. Ut ducimus quod nemo ab voluptatum.

Each call to method fake.name() yields a different (random) result. This is because faker forwards faker.Generator.method_name() calls to faker.Generator.format(method_name).

for _ in range(10): print(fake.name())# Adaline Reichel# Dr. Santa Prosacco DVM# Noemy Vandervort V# Lexi O'Conner# Gracie Weber# Roscoe Johns# Emmett Lebsack# Keegan Thiel# Wellington Koelpin II# Ms. Karley Kiehn V

Providers

Each of the generator properties (like name, address, and lorem) are called β€œfake”. A faker generator has many of them, packaged in β€œproviders”.

Check the extended docs for a list of bundled providers and a list of community providers.

Localization

faker.Factory can take a locale as an argument, to return localized data. If no localized provider is found, the factory falls back to the default en_US locale.

from faker import Fakerfake = Faker('it_IT')for _ in range(10): print(fake.name())> Elda Palumbo> Pacifico Giordano> Sig. Avide Guerra> Yago Amato> Eustachio Messina> Dott. Violante Lombardo> Sig. Alighieri Monti> Costanzo Costa> Nazzareno Barbieri> Max Coppola

You can check available Faker locales in the source code, under the providers package. The localization of Faker is an ongoing process, for which we need your help. Please don’t hesitate to create a localized provider for your own locale and submit a Pull Request (PR).

Included localized providers:

Command line usage

When installed, you can invoke faker from the command-line:

faker[-h][--version][-ooutput][-l{bg_BG,cs_CZ,...,zh_CN,zh_TW}][-rREPEAT][-sSEP][-i{module.containing.custom_providerothermodule.containing.custom_provider}][fake][fakeargument[fakeargument...]]

Where:

  • faker: is the script when installed in your environment, in development you could use python -m faker instead

  • -h, --help: shows a help message

  • --version: shows the program’s version number

  • -o FILENAME: redirects the output to the specified filename

  • -l {bg_BG,cs_CZ,...,zh_CN,zh_TW}: allows use of a localized provider

  • -r REPEAT: will generate a specified number of outputs

  • -s SEP: will generate the specified separator after each generated output

  • -i {my.custom_provider other.custom_provider} list of additional custom providers to use. Note that is the import path of the module containing your Provider class, not the custom Provider class itself.

  • fake: is the name of the fake to generate an output for, such as name, address, or text

  • [fake argument ...]: optional arguments to pass to the fake (e.g. the profile fake takes an optional list of comma separated field names as the first argument)

Examples:

$fakeraddress968BahringerGardenApt.722Kristinaland,NJ09890$faker-lde_DEaddressSamira-Niemeier-Allee5694812Biedenkopf$fakerprofilessn,birthdate{'ssn':u'628-10-1085','birthdate':'2008-03-29'}$faker-r=3-s=";"nameWillamKertzmann;JosiahMaggio;GaylaSchmitt;

How to create a Provider

from faker import Fakerfake = Faker()# first, import a similar Provider or use the default onefrom faker.providers import BaseProvider# create new provider classclass MyProvider(BaseProvider): def foo(self): return 'bar'# then add new provider to faker instancefake.add_provider(MyProvider)# now you can use:fake.foo()> 'bar'

How to customize the Lorem Provider

You can provide your own sets of words if you don’t want to use the default lorem ipsum one. The following example shows how to do it with a list of words picked from cakeipsum :

from faker import Fakerfake = Faker()my_word_list = ['danish','cheesecake','sugar','Lollipop','wafer','Gummies','sesame','Jelly','beans','pie','bar','Ice','oat' ]fake.sentence()#'Expedita at beatae voluptatibus nulla omnis.'fake.sentence(ext_word_list=my_word_list)# 'Oat beans oat Lollipop bar cheesecake.'

How to use with Factory Boy

Factory Boy already ships with integration with Faker. Simply use the factory.Faker method of factory_boy:

import factoryfrom myapp.models import Bookclass BookFactory(factory.Factory): class Meta: model = Book title = factory.Faker('sentence', nb_words=4) author_name = factory.Faker('name')

Accessing the random instance

The .random property on the generator returns the instance of random.Random used to generate the values:

from faker import Fakerfake = Faker()fake.randomfake.random.getstate()

By default all generators share the same instance of random.Random, which can be accessed with from faker.generator import random. Using this may be useful for plugins that want to affect all faker instances.

Seeding the Generator

When using Faker for unit testing, you will often want to generate the same data set. For convenience, the generator also provide a seed() method, which seeds the shared random number generator. Calling the same methods with the same version of faker and seed produces the same results.

from faker import Fakerfake = Faker()fake.seed(4321)print(fake.name())> Margaret Boehm

Each generator can also be switched to its own instance of random.Random, separate to the shared one, by using the seed_instance() method, which acts the same way. For example:

from faker import Fakerfake = Faker()fake.seed_instance(4321)print(fake.name())> Margaret Boehm

Tests

Installing dependencies:

$pipinstall-rtests/requirements.txt

Run tests:

$pythonsetup.pytest

or

$python-munittest-vtests

Write documentation for providers:

$python-mfaker>docs.txt

Contribute

Please see CONTRIBUTING.

License

Faker is released under the MIT License. See the bundled LICENSE file for details.

Credits

Project details

Verified details

These details have been verified by PyPI
Maintainers
πŸ‘ Avatar for curella.org from gravatar.com
curella.org πŸ‘ Avatar for joke2k from gravatar.com
joke2k

Unverified details

These details have not been verified by PyPI
Project links
Meta
  • License: MIT License (MIT License)
  • Author: joke2k
  • Tags faker , fixtures , data , test , mock , generator

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

Faker-0.8.3.tar.gz (631.7 kB view details)

Uploaded Source

Built Distribution

Filter files by name, interpreter, ABI, and platform.

If you're not sure about the file name format, learn more about wheel file names.

Copy a direct link to the current filters

Faker-0.8.3-py2.py3-none-any.whl (630.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file Faker-0.8.3.tar.gz.

File metadata

  • Download URL: Faker-0.8.3.tar.gz
  • Upload date:
  • Size: 631.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Faker-0.8.3.tar.gz
Algorithm Hash digest
SHA256 79b0682d59c4c6961f10edcc9453563a278640e9ffcfee21427fea7a19972bf8
MD5 c5974522e418fb43c603d2cd0c597636
BLAKE2b-256 e7c96154ac5d858f7eb06a0726e0e1e043b457fdec1895d5b478c9aec469121a

See more details on using hashes here.

File details

Details for the file Faker-0.8.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for Faker-0.8.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 499fc2c238501b9846b7e5c771c54f73177f300049aa61e829a46f47e6cd7af2
MD5 fa3ad772e9d9fe2a12042589d7ce1625
BLAKE2b-256 e93fab5a5e3cde3e21c91f2acf4af3891899526903d1bb4532576281480673cd

See more details on using hashes here.

Supported by

πŸ‘ Image
AWS Cloud computing and Security Sponsor πŸ‘ Image
Datadog Monitoring πŸ‘ Image
Depot Continuous Integration πŸ‘ Image
Fastly CDN πŸ‘ Image
Google Download Analytics πŸ‘ Image
Pingdom Monitoring πŸ‘ Image
Sentry Error logging πŸ‘ Image
StatusPage Status page