Change the future

Sunday 2:30 p.m.–3 p.m.

Namespaces in Python

Eric Snow

Audience level:
Core Python (Language, Stdlib)


In the infamous words of Tim Peters, "Namespaces are one honking great idea -- let's do more of those!" (PEP 20) Python's type system is built on the basis of well-bounded namespaces. Come look behind the curtain and you'll see Python in a whole new light. We'll also talk about how to put this knowledge to use whenever you write modules, classes, and functions.


The idea of grouping variables within namespaces is nothing new, inside and outside of Python. Perhaps the concept is so pervasive now that we don't stop to consider the principles at work. By understanding the lower layers of abstraction here, we can make even better use of namespaces. For Python, this understanding is all the more useful since namespaces are the essence of the type system.

In this talk we will cover the following topics, peppered with examples:

  1. what are namespaces? (3 min)
  2. what kinds of namespaces are there? (5 min)
    • mapping-based namespaces
    • attribute-based namespaces
  3. the use-cases for mapping-based vs. attribute-based namespaces (5 min)
    • sys.implementation
  4. namespaces in the Python language (7 min)
    • object namespaces and how dotted-access works
    • namespace containers (dict, list, namedtuple,
  5. namespace types in the stdlib (2 min)
  6. namespace abuses and the Zen of Python (3 min)