![38% of CISOs Fear They’re Not Moving Fast Enough on AI](https://cdn.sanity.io/images/cgdhsj6q/production/faa0bc28df98f791e11263f8239b34207f84b86f-1024x1024.webp?w=400&fit=max&auto=format)
Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Polyfactory is a simple and powerful mock data generation library, based around type hints and supporting dataclasses, typed-dicts, pydantic models, msgspec structs and more.
Polyfactory part of the Litestar project and as such actively maintained by a community of maintainers and contributors.
from dataclasses import dataclass
from polyfactory.factories import DataclassFactory
@dataclass
class Person:
name: str
age: float
height: float
weight: float
class PersonFactory(DataclassFactory[Person]):
...
def test_is_person() -> None:
person_instance = PersonFactory.build()
assert isinstance(person_instance, Person)
That's it - with almost no work, we are able to create a mock data object fitting the Person
class model definition.
This is possible because of the typing information available on the dataclass, which are used as a source of truth for data generation.
The factory parses the information stored in the dataclass and generates a dictionary of kwargs that are passed to
Person
.
Usage and API reference documentation is available on https://polyfactory.litestar.dev/.
pip install polyfactory
Prior to version 2, this library was known as pydantic-factories, a name
under which it gained quite a bit of popularity.
A main motivator for the 2.0 release was that we wanted to support more than just Pydantic models, something which also
required a change to its core architecture. As this library would no longer be directly tied to Pydantic, polyfactory
was chosen as its new name to reflect its capabilities; It can generate mock data for dataclasses, typed-dicts,
Pydantic, odmantic, and beanie ODM models, as well as custom factories.
This library is a community driven open source project. We welcome and encourage contributions. Please checkout the GitHub issues, read the contribution guide (at the repository's root), and you're always welcome to join our discord server.
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
FAQs
Mock data generation factories
We found that polyfactory demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.