List of File Extensions Used With Python

This post lists the most commonly used file extensions related to Python programming.

Table of Contents

Common Python Extensions


py

text file

Python file.

Python source code saved in a file with .py extension. This is the most common and widely used extension for Python files.

As the basic unit of code organization, such a file is a Python module. A module typically contains functions, classes, or other Python objects designed to be imported and used in different .py files.

If such a file contains code that performs certain tasks when it is run directly, the file can also be called a Python script. A script is usually a relatively short and simple program, but a single Python file can contain a complete CLI or GUI code.

The default Python source file encoding is UTF-8.


pyw

text file

Python file (no console).

This is the Python source code saved in a file with .pyw extension. Python script that can be executed using pythonw.exe on Windows instead of python.exe.

.pyw files can contain GUI source code written in Python. When you double-click the .py file or select the Open option from the context menu, a console window appears along with your graphical user interface window. To keep the console from appearing, you can use the .pyw extension.

.pyw files can also contain non-GUI code. They can be used if you want to prevent the console from popping up to display the output.


py2, py3

text file

Python file.

Same as .py extension. These extensions are rarely used.


pyc

binary file

Compiled Python file.

Compiled source code of Python scripts in Python bytecode. Compiling from source to bytecode is one of the steps in the execution of Python code.

This bytecode can be cached in .pyc files. This will allow you to execute the same .py file faster next time. These files can be found in the __pycache__ folder in the same place as the .py files they correspond to.

As of now, .pyc files can contain both unoptimized and optimized bytecode. See also .pyo extension.


pyo

binary file

Compiled Python file.

Python optimized code. The .pyo file contains compiled code, similar to a .pyc file.


pyd

binary file

Python extension module. Python dynamic module.

Equivalent to Windows .dll file (dynamic-link libraries). A .pyd file is a library file that contains code that can be imported and used in Python applications.


pyi

text file

Python stub file.

These files are used to add optional typing to Python code without changing the source code itself. Stub files have the same Python syntax as regular .py files.

Stub files containing type hints that are used by a type checker such as MyPy. PyCharm IDE supports stub files.


pickle

binary file

Binary serialization file.

The .pickle file is used to store serialized Python objects. This is a Python-specific format.


p, pkl, pck, pcl

binary file

Binary serialization files.

Other extensions used for the pickle file.


whl

binary file

Built distribution, "wheels".

The .whl file is a versioned zip archive containing the files and metadata for installing a Python project. pip prefers wheels if available when installing a package from PyPI.

Wheels provide faster installation, especially when the project contains compiled extensions.


pyz, pyzw

binary file

Python zip application file.

An executable archive created from a directory containing Python code. You can pack the directory and run it on the command line: $ python appname.pyz.

The purpose of this file is to create stand-alone Python programs in which all application dependencies are archived along with the application code. This archive can be run on any machine with an appropriate Python interpreter.

The "w", in "pyzw", means "windowed". The .pyzw extension is used if your Python program is a GUI application.

The .pyz extension means that your application is a console or command-line application (CLI).


pth

text file

Python path configuration file.

The .pth files can be used to add additional local paths to sys.path. sys.path is a list of paths to search for Python modules when you do "import modulename".

.pth file can contain the path to the source directory of the Python package. If you put such a path configuration file in the site-packages folder, you can import and use the code from that package as if it were installed using pip.

Instead of a path, such a file can contain code that finds a particular package and adds it to sys.path. This approach is common when you do an editable installation with pip.

.pth files can contain executable code. It allows installed packages to customize sys.path using code (for example, add platform-specific conditions). The code in the .pth file runs at every Python startup. In essence, such a file can contain arbitrary Python code as a string. This code is executed automatically using the exec function.

Users are suggesting that developers remove this feature from Python (issue24534, issue33944).


Other Extensions


pt, pth

binary file

Binary serialization file.

PyTorch, an open source machine learning framework. There is a convention for storing PyTorch models using .pt or .pth files.


npy

binary file

Binary serialization file.

NumPy is the Python package for scientific computing. The .npy format is used to store a single NumPy array on a disk.


npz

binary file

Zip archive containing .npy files.

The .npz format is used to store multiple NumPy arrays on a disk.


rpy

text file

Ren'Py file.

Ren'Py is an open source visual novel engine. Files with the rpy extension are Python scripts that can contain both Python syntax and Ren'Py-specific features.


ipy

text file

IPython file.

IPython (Interactive Python) is a toolkit for interactive and parallel computing in Python. One of its main features is an improved command shell. IPython scripts can use normal Python syntax and some additional functionality. You need to have the ipython package installed to run .ipy files.

The Jupyter Notebook server depends on the functionality of the IPython kernel.


ipynb

text file

Jupyter notebook.

Jupyter Notebook (formerly IPython Notebook) is an open source browser-based application. Jupyter Notebook provides an interactive data processing environment that can run like an IDE. This application was originally intended for use in data science and scientific computing.

The Jupyter Notebook application allows you to edit and run notebook documents, files with the ipynb extension. Such a document may contain formatted explanatory text, code examples, the output of that code, plots, data samples from dataframes, etc. In fact, it's a file formatted as json.


Popular posts from this blog

Tkinter Button Widget