polyfactory

polyfactory is a skill for Claude Code from litestar-org/litestar-skills. It costs 46 tokens per session (2,983 once invoked), scanned A, original, MIT.

A typed test-data factory library for Python that creates example objects from model definitions. It supports models such as Pydantic models, dataclasses, TypedDicts, Msgspec types, and attrs classes.

In plain words
What is it for?
Use it to build test objects with .build(), register them as pytest fixtures, and provide request data for Litestar test clients. It is intended for tests, not for filling production data.
Why use it?
It reduces the need to write and maintain test fixtures by hand, especially when models have type annotations and constraints. TDD, or test-driven development, benefits from repeatable example data when testing code before or alongside its implementation.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the litestar plugin — 31 skills, 1 agent, 1 hook shipped together

Good fit Use it to build test objects with .build(), register them as pytest fixtures, and provide request data for Litestar test clients. It is intended for tests, not for filling production data.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/litestar-org/litestar-skills/polyfactory
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add litestar-org/litestar-skills --skill polyfactory
Clone the repo
git clone --depth 1 https://github.com/litestar-org/litestar-skills

Made for: Claude Code.

Or install litestar, the plugin that ships this one along with the rest of its 31 skills, 1 agent, 1 hook.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for polyfactory

README.md
[![agentmods](https://agentmods.dev/badge/skills/litestar-org/litestar-skills/polyfactory/github.svg)](https://agentmods.dev/skills/litestar-org/litestar-skills/polyfactory)
Your own site
<a href="https://agentmods.dev/skills/litestar-org/litestar-skills/polyfactory"><img src="https://agentmods.dev/badge/skills/litestar-org/litestar-skills/polyfactory/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for polyfactory

Your own site · 80×15
<a href="https://agentmods.dev/skills/litestar-org/litestar-skills/polyfactory"><img src="https://agentmods.dev/badge/skills/litestar-org/litestar-skills/polyfactory.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 46 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,983 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00046 $0.02983
Opus 5 $0.00023 $0.01491
Sonnet 5 $0.00009 $0.00597
Haiku 4.5 $0.00005 $0.00298

Measured 9d ago against content hash 64c517c1e38a, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

polyfactory scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 9d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/litestar/skills/polyfactory/SKILL.md · 306 lines

How it starts

The opening of the file, as written. The whole thing — 306 lines — stays where its author put it; the contents beside it link to each section on GitHub.

polyfactory

Polyfactory is a typed mock-data factory library: declare ModelFactory[T] (or DataclassFactory, MsgspecFactory, AttrsFactory, TypedDictFactory) and .build() returns a populated instance of T. The matching factory base inspects the model's annotations and supported constraints so tests do not need hand-written happy-path fixtures.

In Litestar projects, polyfactory's pytest plugin is the canonical way to feed TestClient.post(...) / AsyncTestClient.put(...) payloads. The companion skill litestar:litestar-testing covers the request side.

Code Style Rules

  • PEP 604 unions: T | None, never Optional[T].
  • One factory per model. Don't reuse a factory across unrelated models — clarity beats DRY when the test fails at 3am.
  • Pick the right factory base by backend: ModelFactory (Pydantic), DataclassFactory, MsgspecFactory, AttrsFactory, TypedDictFactory. A mismatched base raises ConfigurationException.
  • Prefer register_fixture over hand-rolled @pytest.fixture wrappers. Call it in a pytest-discovered test module or conftest.py so the injected fixture is collected.

Quick Reference

Picking the right factory base

Model kind Factory base Import
pydantic.BaseModel ModelFactory from polyfactory.factories.pydantic_factory import ModelFactory
@dataclass DataclassFactory from polyfactory.factories import DataclassFactory
msgspec.Struct MsgspecFactory from polyfactory.factories.msgspec_factory import MsgspecFactory
@attrs.define / attr.s AttrsFactory from polyfactory.factories.attrs_factory import AttrsFactory
TypedDict TypedDictFactory from polyfactory.factories.typed_dict_factory import TypedDictFactory
Beanie / Odmantic / SQLA dedicated bases see factories.md

Defining a factory

from dataclasses import dataclass
from polyfactory.factories import DataclassFactory


@dataclass
class Order:
    id: int
    customer_email: str
    total_cents: int
    status: str


class OrderFactory(DataclassFactory[Order]):
    pass


# Use it
one = OrderFactory.build()
many = OrderFactory.batch(10)

Read the full file on GitHub · 306 lines

Files

What ships with it

3 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 9d ago First seen · 306 lines · 46 tokens per session scan A 64c517c1e38a

Subscribe to this mod's changes

polyfactory is a skill published in the GitHub repository litestar-org/litestar-skills (14 stars, last pushed 19d ago), licensed MIT. It adds 46 tokens to every session and 2,983 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

craft-pest

Testing Craft CMS 5 plugins and modules with Pest — test isolation, database safety, and the markhuot/craft-pest-core harness. ALWAYS load when writing, running, fixing, or reviewing tests for a Craft plugin or module, and whenever a suite touches a real Craft install. Covers why rollback is opt-in, tests/Pest.php +…

michtio/craftcms-claude-skills · 353 tokens

tools-unity-test-framework

Unity Test Framework patterns for EditMode and PlayMode tests including async testing, mocking, and test organization.

IdoCohen560/claude-unity-game-studio · 27 tokens

solution-validation-testing

When the user wants to verify optimization code: independent feasibility checkers, objective recomputation separate from the solver, unit tests for constraint builders and operators, known-optimum regression tests, and exact-vs-heuristic cross-validation on small instances. Also use when the user mentions "validate…

hajibabaie/combinatorial-optimization-skills · 121 tokens

phx-verify

Verify Elixir/Phoenix changes — compile, format, and test in one loop. Use after implementation, before PRs, or after fixing bugs.

oliver-kriska/claude-elixir-phoenix · 36 tokens

swi-prolog-programmer

SWI-Prolog-specific tooling, standards, and idioms. Use when working with SWI-Prolog code. Emphasizes relational thinking, steadfastness, DCGs, constraints, and mandatory testing with PlUnit.

Pyroxin/opinionated-claude-skills · 51 tokens

test-writer

Generates comprehensive unit and integration tests for a given file or function, auto-detecting the project test framework and matching existing test style.

RealDougEubanks/ClaudeMarketplace · 32 tokens