{"id":20959,"library":"async-factory-boy","title":"Async Factory Boy","description":"An extension for factory_boy that adds asynchronous ORM support, enabling creation of model instances with async-compatible factories. Current version is 1.0.1, released in 2024. Maintained actively.","status":"active","version":"1.0.1","language":"python","source_language":"en","source_url":"https://github.com/kuzxnia/async_factory_boy","tags":["factory-boy","async","sqlalchemy","testing","orm"],"install":[{"cmd":"pip install async-factory-boy","lang":"bash","label":"default install"}],"dependencies":[{"reason":"core dependency for factory definitions","package":"factory_boy","optional":false},{"reason":"commonly used async ORM (optional)","package":"sqlalchemy","optional":true},{"reason":"async database adapter used with SQLAlchemy (optional)","package":"databases","optional":true}],"imports":[{"note":"AsyncFactory is in the factory submodule, not top-level","wrong":"from async_factory_boy import AsyncFactory","symbol":"AsyncFactory","correct":"from async_factory_boy.factory import AsyncFactory"},{"note":"common mistake: SQLAlchemy-specific factory is in a submodule","wrong":"from async_factory_boy import AsyncSQLAlchemyModelFactory","symbol":"AsyncSQLAlchemyModelFactory","correct":"from async_factory_boy.factory.sqlalchemy import AsyncSQLAlchemyModelFactory"}],"quickstart":{"code":"import asyncio\nfrom async_factory_boy.factory.sqlalchemy import AsyncSQLAlchemyModelFactory\nfrom factory import Faker\nfrom myapp.models import User\n\nclass UserFactory(AsyncSQLAlchemyModelFactory):\n    class Meta:\n        model = User\n        sqlalchemy_session = None  # set per test\n    name = Faker('name')\n\nasync def test_create_user(db_session):\n    user = await UserFactory.create_async(sqlalchemy_session=db_session)\n    assert user.id is not None","lang":"python","description":"Define an async factory for a SQLAlchemy model and create an instance asynchronously."},"warnings":[{"fix":"Always pass a session when creating instances. Use an async fixture to provide the session.","message":"Async factories require an explicit async session. Do not rely on a global session; use 'create_async(sqlalchemy_session=session)' or 'build_async()' with session=None.","severity":"gotcha","affected_versions":"all"},{"fix":"Replace factory.create() with await factory.create_async().","message":"Using 'create()' (sync) with an async session will fail. Use 'create_async()' instead.","severity":"gotcha","affected_versions":"all"},{"fix":"Use dedicated factory classes for your ORM (e.g., AsyncSQLAlchemyModelFactory) instead of AsyncFactory.","message":"The 'AsyncFactory' base class is considered deprecated in favor of specific ORM factories like 'AsyncSQLAlchemyModelFactory'.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Always pass `sqlalchemy_session` keyword argument to `create_async()`.","message":"`Meta.sqlalchemy_session` defined on the factory class is ignored when using `create_async`. It must be passed as an argument.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Pass `sqlalchemy_session=your_async_session` to `create_async()`.","cause":"Calling `create_async()` without a `sqlalchemy_session` argument.","error":"RuntimeError: No async session provided"},{"fix":"Use `await factory.create_async()` instead of `factory.create()`.","cause":"Using sync `create()` on an async factory, which tries to add the object to a `sqlalchemy_session` that is None.","error":"AttributeError: 'NoneType' object has no attribute 'add'"},{"fix":"Use `from async_factory_boy.factory import AsyncFactory` (or the ORM-specific import).","cause":"Trying to import AsyncFactory from the top-level package, but it's in a submodule.","error":"ImportError: cannot import name 'AsyncFactory' from 'async_factory_boy'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}