Faker
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.
Warnings
- 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.
- 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.
- 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.
- 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.
- 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.
Install
-
pip install Faker
Imports
- Faker
from faker import Faker
Quickstart
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))