class polyfactory.factories.attrs_factory.AttrsFactory[source]

Bases: Generic[T], BaseFactory[T]

Base factory for attrs classes.

__model__: type[T]

The model for the factory. This attribute is required for non-base factories and an exception will be raised if it’s not set. Can be automatically inferred from the factory generic argument.

__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_model_fields() list[polyfactory.field_meta.FieldMeta][source]

Retrieve a list of fields from the factory’s model.


A list of field MetaData instances.

classmethod resolve_types(model: type[T], **kwargs: Any) None[source]

Resolve any strings and forward annotations in type annotations.

  • model – The model to resolve the type annotations for.

  • kwargs – Any parameters that need to be passed to attrs.resolve_types.