Что такое формат файла PYD?
Python dynamic modules are saved as .pyd files on Windows systems. A .pyd file is a Windows DLL in PE (Portable Executable) binary format, distinguished by exporting a PyInit_<modulename> entry point that the interpreter calls on import. .pyd modules contain libraries that can be used by other Python applications; dynamic libraries allow faster code loading and application modularity. In contrast to .pyc and .pyo bytecode files, .pyd files are specific to Windows - the .so format serves the same role on Linux and macOS.
.pyd files contain compiled Python extension modules. Modules contain one or more namespaces, and Python programs that use such modules can refer to functions in those modules. Modules can be used by multiple Python applications. Modern builds include an ABI tag in the filename - for example, cp312-win_amd64.pyd - locking the file to a specific CPython version and bitness. Creating and distributing .pyd modules is typically handled by build tools such as Cython or setuptools.
Безопасность и защита
РИСК: MEDIUMA .pyd is native executable code that Python runs in-process with no sandbox, so a malicious .pyd can do anything your Python program can. The practical risks: (1) a .pyd dropped into a folder Python searches can hijack an import (DLL/PYD search-order hijacking), and (2) downloading individual .pyd files from random sites to "fix" an error is a malware vector - always reinstall the proper package from PyPI with pip instead. .pyd files inside legitimate pip-installed packages are normal. Treat an unexpected, unsigned .pyd in Downloads or a project folder with suspicion and scan it.
Детали формата
в двух словахПрограммы, открывающие файлы PYD
Технические подробности
глубокая спецификация| Container format | Windows PE (Portable Executable) - the same binary container as `.dll` and `.exe` files |
| Magic bytes | `MZ` (0x4D 0x5A) at offset 0 (DOS stub); PE signature at the offset stored at 0x3C |
| Byte order | Little-endian |
| Key exported symbol | `PyInit_<modulename>` (Python 3) or `init<modulename>` (Python 2) - CPython's import system calls this function to initialize the module |
| ABI filename tag | Version-tagged builds use the pattern `name.cpXYZ-win_amd64.pyd`; for example `cp312-win_amd64` targets CPython 3.12 on 64-bit Windows |
| Platform | Windows only; the Linux and macOS equivalent is a `.so` shared object |
| MIME type | `application/octet-stream`; also registered as `application/vnd.microsoft.portable-executable` |
| Typical file size | 20 KB - several MB; large native libraries (e.g., NumPy or SciPy components) can reach tens of MB |
| Compression | None - raw PE sections, no built-in compression |
| Code signing | Optional Authenticode (PE) digital signature; integrity is otherwise unverified (native machine code) |
| Interpreter compatibility | Must match the exact CPython version, bitness (32/64-bit), and ABI tag; a mismatched file raises `ImportError` on import |
| Build toolchain | Typically compiled from C, C++, or Cython source via setuptools `ext_modules`, CMake/scikit-build, or CFFI |
| Выпущен | Late 1990s - Python on Windows has loaded extension modules from .pyd (a renamed .dll) since the Python 1.x/2.0 era |
| Последняя версия | Tracks CPython; the per-version ABI tag (e.g. cp312-win_amd64) determines compatibility, current CPython 3.13 (2024) |
| Открыть стандартное | Да · без роялти |
| Спецификация | docs.python.org |
Конвертации PYD
Вопросы и ответы сообщества
спрошено пользователямиВопросов пока нет - станьте первым, кто спросит о файлах PYD.