What is the standard file extension for Python source files? The standard extension is .py. A Python source file such as hello.py contains human-readable Python code that can be executed by an interpreter or imported as a module.
The extension helps people and development tools recognize the file as Python source. When a module is imported, Python may compile it into bytecode and store that cached form with a .pyc extension inside a __pycache__ directory. The .pyc file is generated implementation data, not the usual editable source file.
Several related extensions also exist. .pyw is associated with Python scripts on Windows that run without opening a console window, while .pyi is used for interface or type-stub files. Python extension modules may use platform-specific endings such as .pyd or shared-library suffixes. These do not change the canonical answer for ordinary Python source code.
A file can contain Python code without a .py suffix, especially when launched as an executable script, but .py remains the conventional and standard source-file extension.