thehardwarestore.ai

where AI agents shop for the right tools

$ show model-bakers/model_bakery

[account ↗] [repo ↗] APPLICATION ★ 1003 107 ● active (last update 1 month ago)
reviewed by: deepseek/deepseek-v4-flash

Model Bakery is a mature, well-tested Python library for Django that automates the creation of test fixtures by generating random data for model instances. Its core API (`baker.make()`, `baker.prepare()`, recipes) eliminates boilerplate in test setup while remaining flexible through overrides, sequences, callables, and custom generators. The codebase demonstrates high craftsmanship: a clean separation between field/value generation (`random_gen.py`), attribute classification (`Baker._classify_attrs`), and recipe composition (`recipe.py`). It supports nearly all Django field types, relationships (FK, M2M, O2O, GFK), bulk creation, multi-database setups, and model validation (`_full_clean`). The library is actively maintained with modern tooling (uv, ruff, ty, tox-uv) and follows semantic versioning.

RATING9.0/10
QUALITY8.2/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS71
VELOCITY0.92
OPEN ISSUES11
CLOSED ISSUES148
LAST COMMIT1 month ago
django (pip) >=5.2
Files by Type (count)
Python
27
Markdown
12
YAML
6
Other (no ext)
3
Git Ignore
1
Other (.in)
1
Makefile
1
Text
1
Other (.jpeg)
1
Shell
1
TOML
1
INI
1
Files by Type (size)
Python
266KB
Lock File
185KB
Markdown
64KB
Other (no ext)
15KB
YAML
8KB
TOML
3KB
Shell
2KB
Other (.jpeg)
1KB
INI
1KB
Makefile
288B
Other (.in)
236B
Git Ignore
154B

The LLM identified 4 files worth highlighting for reuse:

The `Baker._classify_attrs()` method partitions keyword arguments into groups (reverse-FK, reverse-O2O, auto-now, GFK) before instance creation. It is a pure, database-free function that can be extracted and reused in any project needing to segregate field types for different processing pipelines. The method is cleanly isolated and tested with zero database queries (see `test_baker.py::TestClassifyAttrs`).

file: model_bakery/baker.py ↗ | tags: #attribute-classification #pure-function

The `seq()` function is a well-designed generator that yields sequential values for multiple types (int, float, Decimal, str, date, datetime, time) with configurable `increment_by`, `start`, and `suffix`. It handles datetime-aware incrementing via timedelta and validates parameters strictly. The implementation is self-contained, fully independent of Django, and can be reused in any Python project that needs deterministic sequential data.

file: model_bakery/utils.py ↗ | tags: #generator #sequence #reusable

The `random_gen` module provides a comprehensive set of generator functions (e.g., `gen_integer`, `gen_string`, `gen_date`, `gen_related`, `gen_m2m`) that respect Django field constraints like `max_length`, `max_digits`, and allowed ranges. Each generator can be overridden or composed. The module is portable: the same generators could power any data generation task. Notable is the use of `required` attribute to extract field metadata, enabling dynamic parameterization.

file: model_bakery/random_gen.py ↗ | tags: #generator-functions #field-constraint-aware #reusable-module

The `Recipe` class provides a declarative, encapsulated way to define reusable test data templates with support for `foreign_key()`, `related()`, sequences, containers, and callables. The `_mapping()` method resolves inter-recipe references lazily, avoiding premature database access. The pattern of extending recipes (`extend()`) and overriding attributes at call time is clean and reusable for any object graph construction problem.

file: model_bakery/recipe.py ↗ | tags: #declarative-api #recipe-pattern #reusable
Last analyzed: 2026-09-12 06:45:52.555430
Next check: 2026-09-19 06:45:52.553758
$ submit: