Cited, real implementations to study (or point an agent at) when designing or reviewing module-API code.
random. The flagship:random.random,random.seed, and friends are bound methods of one hiddenRandom()built at import, andrandom.Randomstays public for isolated streams. docs.python.org/3/library/random.html · sourcesecrets.choiceandrandbitsare prebound from a module-levelSystemRandominstance — the same wiring with a different engine. (The useful contrast:token_hex/token_bytesare plain module functions that merely call it — they have no__self__and would fail this unit's ownshares_instance()check.) docs.python.org/3/library/secrets.htmlcalendar. Module functions likecalendar.monthdelegate to a module-levelTextCalendarinstance. source
- The naming conventions, the import-time-cost warning, and the keep-the-class-public rule this unit encodes: python-patterns.guide/python/prebound-methods
Every stdlib example keeps both doors open: the convenient module functions for the common case, the public class for isolation. When reviewing a module-level API over shared state, check for the second door — its absence is tomorrow's monkeypatch.