• The fake.FAKER is an instance of the fake.Faker class.

  • The fake.FACTORY is an instance of the fake.Factory class, initialized with fake.FAKER instance.

The Faker class is easy to customize. See the following example:

import random
import string

from fake import Faker, Factory, provider

# Custom first names dictionary

# Custom last names dictionary

# Custom words dictionary
    "time", "person", "year", "way", "day", "thing", "man", "world",
    "life", "hand", "part", "child", "eye", "woman", "place", "work",
    "week", "case", "point", "government", "company", "number", "group",
    "problem", "fact", "be", "have", "do", "say", "get", "make", "go",
    "know", "take", "see", "come", "think", "look", "want", "give",
    "use", "find", "tell", "ask", "work", "seem", "feel", "try", "leave",
    "call", "good", "new", "first", "last", "long", "great", "little",
    "own", "other", "old", "right", "big", "high", "different", "small",
    "large", "next", "early", "young", "important", "few", "public",
    "bad", "same", "able", "to", "of", "in", "for", "on", "with", "as",
    "at", "by", "from", "up", "about", "into", "over", "after",
    "beneath", "under", "above", "the", "and", "a", "that", "I", "it",


    "Den Haag",


class CustomFaker(Faker):
    """Custom Faker class."""

    def load_names(self) -> None:
        """Override default first- and last-names dictionaries."""
        self._first_names = FIRST_NAMES
        self._last_names = LAST_NAMES

    def load_words(self) -> None:
        """Override default words dictionary."""
        self._words = WORDS

    def address_line(self) -> str:
        """Generate a random Dutch address line like 'Oranjestraat 1'.

        :return: A randomly generated Dutch address line as a string.
        # Generate components of the address
        street = random.choice(STREET_NAMES)
        house_number = random.randint(1, 200)
        suffixes = [""] * 10 + ["A", "B", "C"]  # Optional suffixes
        suffix = random.choice(suffixes)

        # Combine components into a Dutch address format
        return f"{street} {house_number}{suffix}"

    def city(self) -> str:
        return random.choice(CITIES)

    def region(self) -> str:
        return random.choice(REGIONS)

    def postal_code(self) -> str:
        """Generate a random Dutch postal code in the format '1234 AB'.

        :return: A randomly generated Dutch postal code as a string.
        number_part = "".join(random.choices(string.digits, k=4))
        letter_part = "".join(random.choices(string.ascii_uppercase, k=2))
        return f"{number_part} {letter_part}"

FAKER = CustomFaker()

The postal_code is the provider method and shall be decorated with @provider decorator.

You can now use both FAKER and FACTORY as you would normally do.

from dataclasses import dataclass
from datetime import date

class Address:
    id: int
    address_line: str
    postal_code: str
    city: str
    region: str

    def __str__(self) -> str:
        return self.address_line

class Person:
    id: int
    first_name: str
    last_name: str
    email: str
    dob: date
    address: Address

    def __str__(self) -> str:
        return self.username

from fake import ModelFactory, SubFactory, post_save, pre_save

from models import Address, Person
from custom_fake import FACTORY

class AddressFactory(ModelFactory):
    id = FACTORY.pyint()
    address_line = FACTORY.address_line()
    postal_code = FACTORY.postal_code()
    city =
    region = FACTORY.region()

    class Meta:
        model = Address

class PersonFactory(ModelFactory):
    id = FACTORY.pyint()
    first_name = FACTORY.first_name()
    last_name = FACTORY.last_name()
    email =
    dob =
    address = SubFactory(AddressFactory)

    class Meta:
        model = Person