Our take
- Activity
- 19
- Community
- 75
- Issues
- 21
- Pull requests
- 20
+0 stars in the last 30 days
- More contributors than 78% of the projects we track
Project history
Daily GitHub snapshots since Oct 7, 2026. History covers stars and forks; health signals are not tracked historically.
Stars
3,811Forks
427Change since Nov 14, 2026: 0 stars·+1 forks
Overview
factory_boy is a Python library for generating test objects from reusable factory definitions. Rather than maintaining large sets of static fixtures, developers can specify defaults and override only the fields relevant to a test, including values for associated objects.
It is intended for Python projects that need object setup for tests or demos. ORM-specific factory classes support Django, MongoDB libraries, and SQLAlchemy; the project can also be extended for other libraries.
Key Features
- Declarative factory classes with defaults for model attributes.
- Per-call keyword overrides for test-specific values.
- Build unsaved objects, create saved ORM instances, or return stub objects.
- Generate batches of objects and unique sequence-based values.
- Compose related objects with subfactories and lazy attributes.
- Generate realistic values with Faker and reseed randomness for reproducible tests.
- ORM integrations for Django, Mogo, MongoEngine, and SQLAlchemy.
Use Cases
- Python application teams can replace brittle, shared fixture files with object definitions tailored to each test.
- Django, SQLAlchemy, or supported MongoDB users can prepare model instances using ORM-aware factories.
- Test authors can create related object graphs, such as a post with an author, without repeating setup code.
- Developers can generate batches of representative records for tests or demos, and seed random values when failures need to be reproduced.
Getting Started
Install from PyPI:
pip install factory_boy
See the README and documentation for setup and usage details.
Alternatives
- mixer: Mixer generates and optionally saves model instances with inferred or supplied values, while factory_boy centers on explicit, reusable factory definitions and creation strategies.
| Project | Language | License | Stars | Status |
|---|---|---|---|---|
| factory_boy | Python | MIT | 3.8k | Not checked yet |
| mixer | Python | – | 953 | Inactive |
Considerations
- ORM persistence requires using the appropriate ORM-specific factory class; the default factory can build objects without saving them.
- The project supports active Python versions and PyPy3, and its documented ORM support policies vary by integration. Check the documentation for compatibility details.
- Randomized values can make failures harder to reproduce unless random seeds are controlled.
Found this useful?
Share it with someone who would like factory_boy.