Photo by Edoardo Galati / Unsplash

TIL - Python's types.SimpleNamespace Gives Quick Dot-Notation Access

Today I Learned Jun 6, 2026

When you need an object to hold properties but a dict feels too clunky and a dataclass is overkill, SimpleNamespace provides a fast dictionary-like object with attribute access.

from types import SimpleNamespace

config = SimpleNamespace(host="localhost", port=8080, debug=True)

print(config.host)  # localhost

# You can dynamically add new attributes later
config.timeout = 30

It acts exactly like an empty class instance class Empty: pass, but has a clean __repr__ and takes kwargs in its constructor.

Tags