class polyfactory.factories.beanie_odm_factory.BeaniePersistenceHandler[source]

Bases: Generic[T], AsyncPersistenceProtocol[T]

Persistence Handler using beanie logic

async save(data: T) T[source]

Persist a single instance in mongoDB.

async save_many(data: list[T]) list[T][source]

Persist multiple instances in mongoDB.


we cannot use the .insert_many method from Beanie here because it doesn’t return the created instances

class polyfactory.factories.beanie_odm_factory.BeanieDocumentFactory[source]

Bases: Generic[T], ModelFactory[T]

Base factory for Beanie Documents


alias of BeaniePersistenceHandler

__is_base_factory__: bool = True

Flag dictating whether the factory is a ‘base’ factory. Base factories are registered globally as handlers for types. For example, the ‘DataclassFactory’, ‘TypedDictFactory’ and ‘ModelFactory’ are all base factories.

classmethod is_supported_type(value: Any) TypeGuard[type[T]][source]

Determine whether the given value is supported by the factory.


value – An arbitrary value.


A typeguard

classmethod get_field_value(field_meta: FieldMeta, field_build_parameters: Any | None = None, build_context: BuildContext | None = None) Any[source]

Return a field value on the subclass if existing, otherwise returns a mock value.

  • field_meta – FieldMeta instance.

  • field_build_parameters – Any build parameters passed to the factory as kwarg values.

  • build_context – BuildContext instance.


An arbitrary value.