Skip to content
Skills Library
Programming · Building & coding

python-dataclasses

/python-dataclasses

Choose between dataclass, NamedTuple, and pydantic, and configure frozen, slots, and validation correctly. Use when modeling structured data in Python or reviewing class boilerplate.

Repository
AI-SKILLS ↗
Licence
MIT
Last repository change
05.09.2026

Assessment and security

90/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content25 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 05.09.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Choose between dataclass, NamedTuple, and pydantic, and configure frozen, slots, and validation correctly. Use when modeling structured data in Python or reviewing class boilerplate.

Original author description

Choose between dataclass, NamedTuple, and pydantic, and configure frozen, slots, and validation correctly. Use when modeling structured data in Python or reviewing class boilerplate.

How it works

  1. Method
  2. Boundaries
Original SKILL.md headings · 43 lines, 286 words
SKILL.md preview
---
name: python-dataclasses
description: Choose between dataclass, NamedTuple, and pydantic, and configure frozen, slots, and validation correctly. Use when modeling structured data in Python or reviewing class boilerplate.
---

# Python dataclasses

Pick the lightest structure that enforces what you need: dataclass for
behavior-bearing records, NamedTuple for immutable tuples with names,
pydantic only where data crosses a trust boundary.

## Method

1. **Default to `@dataclass(slots=True)`.** Slots cut per-instance memory
   roughly in half and catch attribute typos at assignment. Omit slots only
   when you need dynamic attributes, multiple inheritance with other
   slotted classes, or `functools.cached_property`.
2. **Freeze value objects.** `frozen=True` gives hashability (with `eq=True`)
   and safe use as dict keys and set members. Model identities (things with
   a lifecycle) as mutable; model values (money, coordinates, config) as
   frozen.
3. **Use NamedTuple when tuple-ness is the point.** Unpacking, positional
   returns from internal helpers, zero-cost immutability. Its weakness is
   accidental comparison and unpacking compatibility with any same-length
   tuple; do not use it for domain models.
4. **Reserve pydantic for untrusted input.** Parsing JSON from an API, env
   config, user forms: validation and coercion earn their runtime cost at
   the boundary. Inside your own code, plain dataclasses keep imports light
   and construction honest.
5. **Validate in `__post_init__`, not in callers.** Raise `ValueError` there
   for invariants ("port must be 1-65535"). For frozen classes set derived
   fields with `object.__setattr__(self, "field", value)`.
6. **Beware mutable defaults.** `field(default_factory=list)`, never
   `= []`. The class-level default is shared across instances; the factory
   is per instance.
7. **Control the generated API.** `kw_only=True` keeps wide constructors
   readable and lets you reorder fields without breaking callers;
   `repr=False` on secrets keeps them out of logs.

## Boundaries

- Dataclasses do not validate types at runtime; annotations are
  documentation plus static-checker input. Do not assume a `int` field
  rejects a string.
- Inheritance across dataclasses with defaults is field-order sensitive;
  prefer composition when the hierarchy needs more than one level.

Versions

The database has no other skills named python-dataclasses.

Database snapshot: 13.11.2026 · package version 7d775349890d (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100writing-dataclasses
    House rules for Python dataclasses in PostHog: when to reach for one instead of a tuple or `dict[str, Any]`, which decorator to use (`@frozen` from `posthog.dataclasses`), how to name, construct, consume and evolve them, how to keep secrets out of `repr`, and when a function…
  • 95python-data-classes
    Use when Python data modeling with dataclasses, attrs, and Pydantic. Use when creating data structures and models.
  • 100writing-data-models
    Governs implementation and review of Python data modeling with Pydantic v2, dataclasses, SQLModel, SQLAlchemy 2.0 bridging, serialization, and immutability and performance constraints. Use when working with Pydantic BaseModel, dataclass, SQLModel (table=True/False), domain…
  • 90python-domain-modeling
    Designs Python type annotations, domain objects, validation boundaries, dataclass/Pydantic models, invariants, interfaces, fixed choices, and object-copy semantics. Use when choosing ABC for owned nominal implementations versus Protocol for third-party structural compatibility,…
  • 100pydantic
    Pydantic is a Python data validation and serialization library, based on type hints. Use this skill whenever you need to do relatively complex data modeling using Pydantic, e.g. when adding constraints, defining a model hierarchy with subclasses, etc.
  • 95pydantic
    Pydantic v2 data validation library. Covers BaseModel, field validators, custom types, serialization, and schema generation. Use when validating data structures, parsing configs, or defining typed data models in Python. USE WHEN: user mentions "pydantic", "BaseModel", "Field()",…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.