Skip to main content

comtypes

Works on Windows only
PyPI version PyPI - Python Version PyPI - License PyPI - Downloads
GitHub Repo stars GitHub forks
Tidelift Subscription

About

comtypes is a lightweight Python COM package, based on the ctypes FFI library.

comtypes allows to define, call, and implement custom and dispatch-based COM interfaces in pure Python.

This package works on Windows only.

Available on Python 3.7-3.12.

  • comtypes==1.2.1 is the last version supporting Python 2.7 and 3.3-3.6.
  • In Python 3.7.6 and 3.8.1, comtypes would not work as reported in GH-202.
    This bug has been fixed in Python >= 3.7.7 and >= 3.8.2.
  • In Python 3.8 and 3.9, some of comtypes functionalities may not work correctly as reported in GH-212.
    This bug has been fixed in Python >= 3.10.10 and >= 3.11.2.

Where to get it

The source code is currently hosted on GitHub at: https://github.com/enthought/comtypes

An installer for the latest released version is available at the Python Package Index (PyPI).

# PyPI
pip install comtypes

Dependencies

comtypes requires no third-party packages to run - this is truly pure Python package.

Optional features include the follows...

  • to process arrays as numpy's ndarray
  • type hints be interpreted by mypy or several static type checkers

But these third-parties are not required as a prerequisite for runtime.

Community of the developers

Tracking issues, reporting bugs and contributing to the codebase and documentation are on GitHub at: https://github.com/enthought/comtypes

For Enterprise

Available as part of the Tidelift Subscription.

This project and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.

Learn more.

Frequently Asked Questions

Q: Why does this package not support platforms other than Windows?

A: The Microsoft Component Object Model (COM) is a technology that is unique to Windows and is not supported on other platforms.

The phrase "COM is a platform-independent" in the MS documentation means that COM maintains compatibility across different versions of Windows, and does NOT imply that it is supported on Linux or Mac.

As long as COM is not supported outside of Windows, this project does not plan to port to other platforms.

Q: Why does cannot import name 'COMError' from '_ctypes' error occur when using this package on platforms other than Windows?

A: The _ctypes is part of the internal implementation of the ctypes standard library that exists for Python on all platforms.
However, COMError and COM-related features are implemented only in Python for Windows.

In cross-platform software development, care must be taken to ensure that codebase dependent on comtypes does not execute in environments other than Windows.

Q: Despite a script that depends on comtypes having run successfully before, a error (ImportError, NameError, or SyntaxError) is raised now, and the same error occurs again and again.

A: Executing py -m comtypes.clear_cache and then running the script again might resolve the problem.

When comtypes.client.GetModule is called (either directly or indirectly), comtypes generates Python module files.
If Python is forced to terminate or crashes in the middle of file generation, the codebase written to the file becomes partial.
When Python tries to import this unexecutable partial codebase module, an error occurs.

Executing py -m comtypes.clear_cache identifies the directories where the "cache module files" are stored and deletes them.
After deleting these partial modules and running the script again, comtypes.client.GetModule is called and executable modules are generated anew.

However, if the script implementation does not use comtypes.client.GetModule or processes generated files, it may not be a solution.

Documentation:

The documentation is currently hosted on pythonhosted at: https://pythonhosted.org/comtypes

Metadata

Release files for comtypes 1.4.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for comtypes 1.4.4
File Size Uploaded Provenance Actions
comtypes-1.4.4.zip 233.8 kB Without provenance Details for comtypes-1.4.4.zip

Built distribution (wheel)

Table of built distributions (wheels) for comtypes 1.4.4
File Interpreter ABI Platform Actions
comtypes-1.4.4-py3-none-any.whl Python 3 none any Details for comtypes-1.4.4-py3-none-any.whl

Total release size: 444.4 kB

Release files / comtypes-1.4.4.zip

Download URL comtypes-1.4.4.zip
Size 233.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b7ead79b42ed8707ce8be8ad1e3020d9483c0bd2a905dc1903efaf73b4f6651d
BLAKE2b-256 checksum
How to use checksums
8f8829f47d1ffeb317686a552b70fa9f1e9922372ae497a7d9c69d7693bc95b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.3

Release files / comtypes-1.4.4-py3-none-any.whl

Download URL comtypes-1.4.4-py3-none-any.whl
Size 210.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8db0d45aca5e891b3ffb77fe47cfd256cc3799d409d8e39baf8dd7884859d828
BLAKE2b-256 checksum
How to use checksums
f5c014dae7492649d7b41cc4f1dd392dd7bb2bc46a07f099f1d2cf4d8dff03e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.3

Security for comtypes 1.4.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.4.4 This release

2 release files No provenance

0.6.2

0.6.1

0.6.0

0.5.3

0.5.2

0.5.1

0.4.2

0.4.1

0.4.0

0.3.3

0.3.2

0.2.1

0.2

0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page