Skip to content

builtins

The Python builtins module provides direct access to all of Python’s built-in identifiers, including functions, types, exceptions, and constants. It is available in every Python environment without installation and is imported automatically by the interpreter at startup.

Here is a quick demonstration:

Python
>>> import builtins

>>> builtins.len([1, 2, 3])
3
>>> builtins.isinstance(42, builtins.int)
True

Most code never imports builtins directly because its contents are always in scope. The module becomes useful when a local name shadows a built-in and the original needs to be reached explicitly.

Key Features

  • Exposes all built-in functions such as len(), print(), open(), range(), and isinstance()
  • Exposes all built-in types such as int, str, list, dict, tuple, and set
  • Exposes all built-in exceptions such as ValueError, TypeError, and KeyError
  • Exposes built-in constants such as True, False, None, Ellipsis, and NotImplemented
  • Allows access to built-in names that have been overridden in the local or global scope

Frequently Used Objects

Object Type Description
builtins.open() function The original built-in file-open function, useful when a local open shadows it
builtins.print() function The original built-in print function
builtins.__dict__ dict Mapping of all built-in names to their objects

Examples

Accessing the original open() after defining a local version that shadows it:

Python upper_open.py
import builtins

def open(path):
    f = builtins.open(path, "r")
    return f.read().upper()

print(open("readme.txt"))

Inspecting all available built-in names:

Python
>>> import builtins

>>> [name for name in dir(builtins) if not name.startswith("_")][:3]
["ArithmeticError", "AssertionError", "AttributeError"]

Checking whether a name is a built-in:

Python
>>> import builtins

>>> hasattr(builtins, "map")
True
>>> hasattr(builtins, "flatten")
False

Common Use Cases

The most common tasks for builtins include:

  • Accessing a built-in function or type that has been overridden by a local definition
  • Inspecting the full set of built-in names available in any Python session
  • Adding or modifying built-in names at runtime in testing or framework code
  • Referencing built-in names explicitly for clarity in low-level or metaprogramming code

Real-World Example

The following example adds a custom built-in helper that becomes available in all modules without an import, a technique sometimes used in testing frameworks or application bootstrapping:

Python bootstrap.py
import builtins

def debug(obj):
    print(f"[debug] {type(obj).__name__}: {obj!r}")

builtins.debug = debug

After this module is imported once, any other module in the same process can call debug(value) without importing anything:

Python app.py
import bootstrap  # Registers the helper

debug([1, 2, 3])  # Works in any module loaded after bootstrap

Injecting names into builtins affects the entire interpreter session, so this pattern is generally reserved for development tooling and test fixtures.

Tutorial

Python's Built-in Functions: A Complete Exploration

In this tutorial, you'll learn the basics of working with Python's numerous built-in functions. You'll explore how to use these predefined functions to perform common tasks and operations, such as mathematical calculations, data type conversions, and string manipulations.

basics python

For additional information on related topics, take a look at the following resources:


By Leodanis Pozo Ramos • Updated March 2, 2026