Skip to content

Open Source ยท Python ยท snoodleboot

The factory system
Python deserves

Thread-safe. Type-safe. Zero magic.
Register once, create anything.

$ uv add sweet-tea
PyPI Python CI License

What's in the box

๐Ÿ”’
Thread-Safe Registry
RLock-backed global registry. Concurrent reads and writes without races.
๐Ÿงฌ
Type-Safe Generics
Full TypeVar support with __class_getitem__. Your IDE stays happy.
๐Ÿ”
Flexible Key Matching
MyClass, my_class, or myclass โ€” all resolve to the same entry.
๐Ÿ”
Lazy Singletons
SingletonFactory caches on first create. No decorators, no metaclasses.
๐Ÿ”Œ
Optional Dependencies
Graceful fallbacks with clear warnings. Nothing blows up at import time.
๐Ÿ“ฆ
Auto-Registration
Call fill_registry() and every class in your package is registered instantly.

60-second quickstart

from sweet_tea import Registry, Factory

class PostgresDB:
    def __init__(self, host="localhost", port=5432):
        self.host = host

Registry.register("postgres", PostgresDB)

db = Factory.create("postgres", configuration={"host": "prod.db"})
from sweet_tea import Registry, SingletonFactory

class AppConfig:
    def __init__(self, env="prod"):
        self.env = env

Registry.register("config", AppConfig)

# Same instance every time
cfg = SingletonFactory.create("config", configuration={"env": "staging"})
from sweet_tea import Registry, AbstractFactory

class BaseService: ...

class EmailService(BaseService): ...

Registry.register("email", EmailService)

# Only accepts subclasses of BaseService
svc_factory = AbstractFactory[BaseService]
svc = svc_factory.create("email")

Installation

uv add sweet-tea
pip install sweet-tea
poetry add sweet-tea

Built by snoodleboot, LLC ยท Apache 2.0