factory_boy
factory_boy is a Python library that replaces static test fixtures with declarative factories for creating test objects. It simplifies test setup by allowing you to define only the fields relevant to each test while auto-generating defaults, and integrates with Django, SQLAlchemy, MongoDB, and other ORMs.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | FactoryBoy/factory_boy |
| Owner | FactoryBoy |
| Primary language | Python |
| License | MIT — OSI-approved |
| Stars | 3.8k |
| Forks | 418 |
| Open issues | 208 |
| Latest release | Unknown |
| Last updated | 2026-01-01 |
| Source | https://github.com/FactoryBoy/factory_boy |
What factory_boy is
A fixture replacement tool providing multiple build strategies (build, create, stub), lazy attribute evaluation, sequences, SubFactory associations, and Faker integration for realistic test data. Supports Django, SQLAlchemy, MongoEngine, and Mogo ORM backends via inheritance-based factory classes.
Get the factory_boy source
Clone the repository and explore it locally.
git clone https://github.com/FactoryBoy/factory_boy.gitcd factory_boy# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- Requires Python environment and pip; integrates as a dev dependency—no production impact.
- Learn factory syntax and declarative patterns; documentation includes examples for Django, SQLAlchemy, and plain models.
- Plan ORM integration upfront (DjangoModelFactory, SQLAlchemyModelFactory, etc.) to avoid refactoring factories later.
- Use Faker judiciously; seeding with factory.random.reseed_random() is needed for reproducible test runs.
- Consider factory inheritance and mixins for DRY factory definitions across many models.
When to avoid it — and what to weigh
- Non-ORM or custom object models — While factory_boy supports plain Python classes, its design philosophy favors ORM integration. Projects with bespoke object initialization may require significant custom coding.
- High-volume performance testing — Factory creation has runtime overhead; if tests require millions of objects or sub-millisecond creation time, direct instantiation or bulk SQL inserts may be more suitable.
- Real-time production data synthesis — factory_boy is a testing library. Using it for production data generation or ETL is out of scope and not recommended.
- Projects already deeply invested in fixtures — Migration cost from existing fixture frameworks (e.g., pytest fixtures, unittest fixtures) may outweigh benefits if test coverage is large and stable.
License & commercial use
Licensed under MIT (Massachusetts Institute of Technology License), an OSI-approved permissive license allowing commercial use, modification, and distribution with minimal restrictions. Attribution required; no warranty provided.
MIT license permits commercial use in proprietary projects, products, and services. No license fees or restrictions on commercial deployment. Typical for test libraries. Recommend including MIT license text in distributions as per standard practice.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Moderate |
| Documentation | Adequate |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Strong |
| Assessment confidence | High |
factory_boy is a testing library executed in dev/test environments. No production exposure. Standard Python dependency security hygiene applies: pin versions, audit for CVEs via tools like pip-audit or Dependabot. Use Faker with caution if test data is intended to resemble PII; mask before sharing test artifacts. No encryption, authentication, or secrets management handled by factory_boy.
Alternatives to consider
pytest fixtures
Built-in pytest feature for parametrized test data; lighter-weight for simple cases but less expressive for complex object graphs and ORM associations.
Hypothesis (property-based testing)
Generates randomized test data to find edge cases; complementary rather than replacement, and does not handle ORM object setup as directly.
django-seed / model_bakery
Django-specific alternatives; model_bakery is lighter-weight and auto-discovers fields, but less explicit and less portable across ORMs.
Build on factory_boy with DEV.co software developers
Evaluate factory_boy for your Django, SQLAlchemy, or ORM-based project. Compare against pytest fixtures and model_bakery. MIT license, no production risk.
Talk to DEV.coRelated open-source tools
Surfaced by semantic similarity across the DEV.co open-source index.
Related on DEV.co
Explore the category and the services that help you build with it.
factory_boy FAQ
Does factory_boy work with non-ORM objects?
Can I use factory_boy with pytest?
How do I ensure test reproducibility with random data?
What is the performance impact on large test suites?
Software developers & web developers for hire
From first prototype to production, DEV.co delivers software development services around tools like factory_boy. Our software development agency staffs experienced software developers and web developers for custom software development, web development, integrations, and ongoing support across open-source testing and beyond.
Ready to streamline your Python test suite?
Evaluate factory_boy for your Django, SQLAlchemy, or ORM-based project. Compare against pytest fixtures and model_bakery. MIT license, no production risk.