Registry / testing / autofaker

autofaker

JSON →
library2.0.24pypypi✓ verified 83d ago

autofaker is a Python library designed to minimize the setup/arrange phase of unit tests by automatically generating anonymous variables for various data types and classes. It supports built-in types (int, str, float), datetime types (datetime, date), and simple, nested, or dataclasses. As of version 1.0.22, it remains actively developed with a focus on simplifying test data generation.

pip install autofaker
INSTALL
IMPORT
SIG · AUTOFAKER
A
autofaker
testingpythonv2.0.24
Install
9.0s avg
Import
Disk
188MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.24 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 189.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 9.0s · import 0.000s · 182MB
188MB installed
● package 188MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Autodata
from autofaker import Autodata
from autofaker import Fake
autodata
from autofaker import autodata
from autofaker import Fake
TypeDataGenerator
from autofaker import TypeDataGenerator
from autofaker import Fake

This quickstart demonstrates how to use `autofaker.Fake()` to generate instances of complex dataclasses with nested structures and built-in types, as well as standalone fake primitive values. autofaker leverages type hints to infer and generate appropriate data.

from autofaker import Fake from dataclasses import dataclass import datetime @dataclass class Product: name: str price: float is_available: bool @dataclass class Customer: customer_id: str name: str email: str age: int registration_date: datetime.date products_bought: list[Product] # Generate a fake instance of the Customer class fake_customer = Fake(Customer) print(f"Fake Customer Name: {fake_customer.name}") print(f"Fake Customer Email: {fake_customer.email}") # Generate a fake string fake_string = Fake(str) print(f"Fake String: {fake_string}") # Generate a fake integer fake_int = Fake(int) print(f"Fake Integer: {fake_int}")
Debug
Known issues
gotchaautofaker relies heavily on type hints to generate meaningful data for class attributes. If type hints are missing, especially for custom classes or complex structures, autofaker might not be able to infer the desired type or might default to `None`.
fix
Always provide explicit type hints for class attributes that you expect autofaker to populate. For example, `name: str` instead of `name`.
affects: >=1.0.0
gotchaWhen dealing with `default_factory` in dataclasses, be aware that it will take precedence over autofaker's generation for that specific field. If you want autofaker to handle the default value generation, ensure your `default_factory` does not conflict or explicitly uses `Fake()` within it.
fix
If `default_factory` is used and you still want autofaker to generate the value, embed `Fake()` in the factory, e.g., `field(default_factory=lambda: Fake(str))` or remove the `default_factory` entirely if autofaker should generate it based on the type hint.
affects: >=1.0.0
gotchaWhile autofaker supports nested classes, excessively deep or mutually recursive class definitions can lead to `RecursionError`. The library does not implement infinite recursion protection for all complex scenarios.
fix
Design your classes to avoid overly deep or circular dependencies when using autofaker. For testing, consider faking parts of the deeper structure manually or simplifying the test subject's dependencies.
affects: >=1.0.0
Upgrade
Version history
2.0.24latest on PyPI · released Jun 5, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
27 hits · last 30 days
node
22
OpenAI (training)
1
Resources
autofaker — pip install autofaker · libregistry