API Reference

Faker

Fake data generator for Python producing localized names, addresses, and numbers with seeded runs.

Official Documentation ↗
CompatibilityThis documentation covers version v40.44.0. Check the official docs for the latest API surface.

Installation

pippip install faker

Methods

Fake data generator for Python producing localized names, addresses, and numbers with seeded runs.

Overview

Faker produces localized synthetic data for tests, demos, and anonymized fixtures. A Faker instance exposes hundreds of methods for names, contact details, companies, finance, and internet artifacts, with providers like zh_CN or fr_FR giving realistic local shapes.

Seeding makes output deterministic for reproducible tests, unique wraps methods to guarantee distinct values, and custom providers extend the vocabulary with domain-specific generators. Factories and ORMs commonly consume Faker inside fixture builders.

Core Methods

The most frequently used entry points, with signatures and runnable examples:

  • Faker — Creates a generator for a locale; methods yield plausible values for people, places, and things.
  • Faker.seed / seed_instance — Fixes randomness globally or per instance so generated datasets are reproducible.
  • fake.unique — De-duplicating proxy that never returns a previously generated value per method.
  • add_provider — Registers a custom provider class whose methods appear directly on the instance.

Usage Notes

  • Seed per test with seed_instance to keep fixtures independent and reproducible.
  • Build higher-level fixture builders over raw calls so domain invariants hold across seeds.
  • Use fake.unique for identifier fields and clear it between entity batches.

Common Pitfalls

  • Unseeded generation makes flaky tests: the same test can pass and fail across runs.
  • unique over tiny domains throws UniquenessException quickly; widen or avoid it there.
  • fake.email() output is not deliverable; never point it at systems that send mail.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://faker.readthedocs.io/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:32.697Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

  • Note, to avoid infinite loops, after a number of attempts to find a unique value, Faker will throw a UniquenessException . (https://faker.readthedocs.io/)

FAQ

Why do tests flake without seeding?
Unseeded Faker uses process randomness, so boundary values, unlucky names, or colliding emails differ per run. Seed per test or per module so failures reproduce exactly.
Can Faker data be used in production screenshots or demos?
Yes, that is its purpose, but stay aware that fake emails use real TLDs and fake addresses resemble real ones. Avoid implying real people exist and keep synthetic data out of systems that email or bill.
What happens when unique values run out?
fake.unique raises UniquenessException after exhausting the generator space for a method, which can happen quickly for small domains like boolean or small enums. Clear or widen the provider when domains are tiny.