Freedom251 › Test Data Generation Tools
factory_boy

What factory_boy is
factory_boy is a free, open-source Python tool for replacing static test fixtures with customizable factories. Its declarative syntax defines object attributes, then factories can build unsaved instances, create saved instances, or return stub objects. Faker supplies realistic random values, and the factory.random module includes seed helpers for reproducible test data. Multiple factories can target one class, including through inheritance, while SubFactory creates related objects using an associated factory’s strategy. Documented integrations cover Django, Mogo, MongoEngine, and SQLAlchemy. SQLAlchemyModelFactory requires a session supplied through sqlalchemy_session or sqlalchemy_session_factory. The support policy covers active Python versions and PyPy3. Installation is documented for PyPI and Git source. The MIT-licensed project is self-hosted and provides detailed logging through the factory logger plus a factory.debug() helper. Questions and suggestions can go to GitHub Issues or a Google Groups mailing list. It supports synthetic and relational data generation, with database connectors listed for Django ORM, MongoDB, MongoEngine, and SQLAlchemy.
Who it suits
It suits Python developers writing tests who need generated objects, related data, or ORM-backed fixtures. It is also useful when tests require repeatable random values and self-hosted tooling.
What it does well
- Declarative factories replace static fixtures
- Builds unsaved, saved, or stub objects
- Faker generates realistic random values
- Supports Django, Mogo, MongoEngine, and SQLAlchemy
- MIT-licensed and free
What to know first
- SQLAlchemy factories require a configured session
- Self-hosted deployment
- Support policy covers active Python versions and PyPy3
Limits
SQLAlchemyModelFactory cannot operate without a session supplied through sqlalchemy_session or sqlalchemy_session_factory. Supported runtimes are active Python versions and PyPy3.
Getting started
- Open the factory_boy documentation website
- Install the package from PyPI or the Git source
- Define factory attributes with its declarative syntax
- Choose build, create, or stub generation
- Configure an ORM integration when needed
- Set sqlalchemy_session or sqlalchemy_session_factory for SQLAlchemyModelFactory
Verdict
factory_boy provides flexible fixture generation for Python tests, including ORM integrations, related objects, and reproducible randomness. Its SQLAlchemy session requirement and self-hosted setup should be planned for in advance.
Questions
Is factory_boy free?
Yes. It is free and distributed as open-source software under the MIT License.
Which Python runtimes are supported?
The support policy covers active Python versions and PyPy3.
Which ORM integrations are documented?
Documentation describes integrations for Django, Mogo, MongoEngine, and SQLAlchemy.
Can generated values be repeatable?
Yes. factory.random provides helpers for managing seeds and reseeding random values.
How can users get support?
Questions and suggestions can be sent through GitHub Issues or the Google Groups mailing list.
Facts from factory_boy's own pages
- Audience
- It is a fixtures replacement tool for Python tests. · factoryboy.readthedocs.io, 9 Oct 2026
- Build strategies
- Factories can build unsaved instances, create saved instances, or return stub objects. · factoryboy.readthedocs.io, 9 Oct 2026
- Community support
- The documentation directs users to GitHub Issues and a Google Groups mailing list for questions and suggestions. · factoryboy.readthedocs.io, 9 Oct 2026
- Debugging
- Detailed logging is available through the factory logger, and factory.debug() is provided as a debugging helper. · factoryboy.readthedocs.io, 9 Oct 2026
- Distribution
- The documentation gives PyPI installation and Git source installation instructions. · factoryboy.readthedocs.io, 9 Oct 2026
- Factory syntax
- Factories use a declarative syntax to define attributes for creating Python objects. · factoryboy.readthedocs.io, 9 Oct 2026
- Generated data
- factory_boy uses the Faker library to generate realistic random values. · factoryboy.readthedocs.io, 9 Oct 2026
- Generated values
- It uses Faker for realistic random values and provides helpers to reseed random values for reproducible tests. · factoryboy.readthedocs.io, 9 Oct 2026
- Inheritance
- It supports multiple factories for a class, including inheritance. · factoryboy.readthedocs.io, 9 Oct 2026
- License
- The project is distributed under the MIT License. · factoryboy.readthedocs.io, 9 Oct 2026
- ORM integrations
- Documented ORM integrations include Django, Mogo, MongoEngine, and SQLAlchemy. · factoryboy.readthedocs.io, 9 Oct 2026
- ORM support
- The documentation describes integrations for Django, Mogo, MongoEngine, and SQLAlchemy. · factoryboy.readthedocs.io, 9 Oct 2026
- Purpose
- factory_boy replaces static test fixtures with customizable factories for complex objects. · factoryboy.readthedocs.io, 9 Oct 2026
- Python support
- The support policy covers active Python versions and PyPy3. · factoryboy.readthedocs.io, 9 Oct 2026
- Related objects
- SubFactory creates associated objects and uses the associated factory's strategy. · factoryboy.readthedocs.io, 9 Oct 2026
- Reproducible randomness
- The factory.random module provides helpers for managing random seeds. · factoryboy.readthedocs.io, 9 Oct 2026
- SQLAlchemy requirement
- SQLAlchemyModelFactory requires a session object configured through sqlalchemy_session or sqlalchemy_session_factory. · factoryboy.readthedocs.io, 9 Oct 2026
- Support channels
- The project directs users to GitHub Issues and welcomes questions and suggestions on its mailing list. · factoryboy.readthedocs.io, 9 Oct 2026
- Supported runtimes
- The support policy says factory_boy supports active Python versions and PyPy3. · factoryboy.readthedocs.io, 9 Oct 2026
Where factory_boy stands on Freedom251
- Test Data Generation Tools#20 of 28