Introduction to Python Internals via CPython implementation

We discuss how Python works internally, what is PyObject and how types are being handled internally

Before we dive into the deep of Python language implementation, we need to get familiar with the main concept in Python. It’s quite simple – everything is an object. This is our first step in learning about Python internals and an entry point to our journey.

Main topic today is to understand how Python’s objects are being handled on a low-level. We’ll be talking about CPython implementation of Python 2.7.8.

I assume you download Python sources and unzip it, so all references to source code will be pointed relative to the root folder.

PyObject & PyVarObject

Everything in Python is an Object. Literally, anything you are working with in Python is a C‘s PyObject:

  • functions
  • slices
  • files
  • classes
  • iterators
  • descriptors
  • sequences
  • numeric types

Source: Introduction to Python Internals via CPython implementation