finds.dev← search

// the find

dabeaz/cluegen

★ 367 · Python · updated Nov 2021

Get a clue, get some code

cluegen is a 100-line Python library by David Beazley that generates __init__, __repr__, __iter__, and __eq__ methods from type annotations using lazy code generation via the descriptor protocol. It's aimed at developers who want dataclass-like convenience without the startup overhead or the inflexibility when you need to customize method generation. The intended use is: copy the file into your project, then extend it to suit your needs.

Lazy generation is the real win here — methods are generated on first access, so you only pay for what you actually use, and import time is genuinely faster than dataclasses. The extension model is clean: you write a function that returns a string of Python code, decorate it with @cluegen, and it replaces itself on first access. The 'true story' example of adding a lineno attribute to a base class shows a real limitation of dataclasses that cluegen handles without drama. At ~100 lines, the entire implementation fits in your head, which means you can actually trust it when something goes wrong.

No PyPI package and no setup.py is a philosophical choice, but it means there's no version pinning, no changelog, and no upgrade path — you own whatever you copy. Last commit was November 2021, so any Python 3.11+ quirks or edge cases are yours to fix. No type enforcement is fine for a data container, but the absence of validators, converters, or frozen instances means you'll quickly find yourself reinventing attrs. The 367-star count and 13 forks signal that this never crossed from 'interesting technique' to 'production dependency' for most people.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →