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:

Language: 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:

Language: Python Filename: 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:

Language: 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:

Language: 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:

Language: Python Filename: 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:

Language: Python Filename: 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.

Python's Built-in Functions: A Complete Exploration

Tutorial

Python Built-in Functions: A Complete Guide

Use Python's built-in functions for math, data types, iterables, and I/O to write shorter, more Pythonic code.

intermediate python

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


By Leodanis Pozo Ramos • Updated June 19, 2026