Faker

raw JSON →
40.11.1 verified Tue May 12 auth: no python install: verified quickstart: verified

Faker is a Python package that generates fake data such as names, addresses, emails, and more, for various purposes including testing applications, populating databases, creating sample reports, and anonymizing sensitive data. It is currently on version 40.11.1 and maintains an active development cycle with frequent releases.

pip install Faker
error ModuleNotFoundError: No module named 'faker'
cause The 'faker' library has not been installed in your Python environment or your interpreter is not pointing to the correct environment where it is installed.
fix
Install the Faker library using pip: pip install Faker or python -m pip install Faker. If using Anaconda, use conda install -c conda-forge faker.
error AttributeError: 'Faker' object has no attribute 'some_method_name'
cause You are trying to call a fake data generation method (e.g., 'zipcode', 'password') that does not exist, is misspelled, or is not supported by the currently selected locale.
fix
Check the Faker documentation for the correct method name and ensure it's available for your chosen locale. For example, if 'zipcode' isn't working for 'pl_PL', it might be called 'postalcode' in that locale, or the provider for that data type is not loaded. If it's a known provider, ensure your Faker instance is created correctly: from faker import Faker; fake = Faker('en_US'); print(fake.name()).
error TypeError: Calling `.seed()` on instances is deprecated. Use the class method `Faker.seed()` instead.
cause In newer versions of Faker (since v3.0.0), the `seed()` method is intended to be called as a class method on `Faker` itself, not on an instance of `Faker`, to ensure consistent seeding across all generators.
fix
Change fake.seed(0) to Faker.seed(0) before creating any Faker instances. For example: from faker import Faker; Faker.seed(0); fake = Faker(); print(fake.name()).
error ImportError: cannot import name 'Faker' from partially initialized module 'faker'
cause This error typically occurs when you have named one of your own Python files or modules 'faker.py', which conflicts with the installed 'faker' library, causing Python to try importing from your local file instead of the package.
fix
Rename your local Python file or module that has the name 'faker.py' to something else (e.g., 'my_faker_script.py') to avoid the naming conflict.
error ValueError: No locale found for 'unsupported_locale_code'
cause You have specified a locale code (e.g., 'unsupported_locale_code') when initializing Faker that is not recognized or supported by the library.
fix
Use a supported locale code. Refer to the Faker documentation for a list of available locales (e.g., 'en_US', 'fr_FR', 'it_IT'). For example: from faker import Faker; fake = Faker('fr_FR'); print(fake.name()).
breaking Faker dropped support for Python 2 starting from version 4.0.0, and from version 5.0.0, it only supports Python 3.8 and above. For Python 2 compatibility, install version 3.0.1.
fix Upgrade Python to 3.10+ or pin Faker to an older, compatible version (e.g., `Faker==3.0.1` for Python 2).
breaking Calling the `seed()` method on a `Faker` *instance* (e.g., `fake.seed(0)`) is deprecated and will raise a `TypeError`. Seeding should now be done using the class method `Faker.seed(0)` for consistent results across test runs.
fix Change `fake_instance.seed(value)` to `Faker.seed(value)`.
gotcha While `Faker.seed()` ensures reproducibility for a given Faker version, the generated data is not guaranteed to be consistent across *patch versions* (e.g., between 40.11.0 and 40.11.1) due to potential dataset updates.
fix For strict reproducibility in tests or data generation where results must be identical across environments and time, pin the Faker library to a specific patch version in your `requirements.txt` (e.g., `Faker==40.11.1`).
gotcha The Faker package was previously known as `fake-factory` and was deprecated by the end of 2016. Ensure your project and its dependencies do not rely on the old `fake-factory` package to avoid conflicts or outdated behavior.
fix Migrate any lingering `fake-factory` dependencies to `faker`.
gotcha When using the `.unique` property on a Faker generator, be aware that if it struggles to find a unique value after a number of attempts (especially with a small pool of possible values), it will raise a `UniquenessException` to prevent infinite loops.
fix Ensure the pool of unique values is sufficiently large or handle `UniquenessException` in your code if uniqueness is critical but the pool is limited.
gotcha The test output contains pip warnings about running as the 'root' user and a new pip version being available. These are environmental warnings/notices and do not indicate a failure of the Faker library itself.
fix Address pip warnings by using virtual environments or updating pip as suggested in the output, if desired. These are not Faker-specific issues.
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.24s 42.0M
3.10 slim (glibc) - - 0.17s 43M
3.11 alpine (musl) - - 0.33s 43.2M
3.11 slim (glibc) - - 0.28s 44M
3.12 alpine (musl) - - 0.30s 35.0M
3.12 slim (glibc) - - 0.30s 35M
3.13 alpine (musl) - - 0.27s 34.6M
3.13 slim (glibc) - - 0.28s 35M
3.9 alpine (musl) - - 0.21s 42.8M
3.9 slim (glibc) - - 0.20s 43M

Initialize the Faker generator and access various fake data providers as properties. Each call generates a different random value by default. Locales can be specified for region-specific data.

from faker import Faker

fake = Faker('en_US') # You can specify a locale

print("Fake Name:", fake.name())
print("Fake Address:", fake.address())
print("Fake Email:", fake.email())
print("Fake Text:", fake.text(max_nb_chars=100))