Skip to main content

comtypes

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

comtypes is a lightweight pure Python COM package based on the ctypes foreign function interface library.

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

comtypes requires Windows and Python 3.9 or later.

  • Note about Python 3.15 and enum behavior
    Starting with Python 3.15, the internal handling of IntFlag(Flag) values is planned to change:
    Negative IntFlag members will be reinterpreted by masking them to the defined positive bit domain, instead of keeping their original negative literal values.
    This can affect enumeration types generated by comtypes from COM type libraries. Action is needed to maintain literal evaluation.
    For details and ongoing discussion, see: GH-894.
  • Version 1.4.12 is the last version to support Python 3.8.
  • Version <= 1.4.7 does not work with Python 3.13 as reported in GH-618. Version 1.4.8 can work with Python 3.13.
  • Version 1.4.6 is the last version to support Python 3.7.
  • Version 1.2.1 is the last version to support Python 2.7 and 3.3–3.6.
  • Certain comtypes functions may not work correctly in Python 3.8 and 3.9 as reported in GH-212. This bug has been fixed in Python >= 3.10.10 and >= 3.11.2.

Installation

comtypes is available on PyPI and can be installed with pip:

# PyPI
pip install comtypes

The source code is currently hosted here on GitHub.

Dependencies

comtypes is a pure Python package — it has no additional required dependencies.

Optional functionalities can be enabled by installing:

  • numpy, in order to process arrays as numpy's ndarray.
  • mypy or other static type checkers, in order to interpret type hints.

None of these packages, however, are required in order to run comtypes.

Community

The GitHub repository is used for tracking issues, reporting bugs, and contributing to the codebase and documentation.

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.

For as long as COM is not supported outside of Windows, there is no plan to port comtypes 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 only implemented in Python for Windows.

In cross-platform software development, care must be taken to ensure that codebases that depend on comtypes do 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 here on ReadTheDocs.

Release files for comtypes 1.4.17

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.17
File Size Uploaded
comtypes-1.4.17.tar.gz 262.7 kB Details

Built distribution (wheel)

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

Total release size: 561.5 kB

Release files / comtypes-1.4.17.tar.gz

Download URL comtypes-1.4.17.tar.gz
Size 262.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3d9c1e92ad8daf7600d371e76ee16161a627a5fb70c3144f6e52e78af6034363
BLAKE2b-256 checksum
How to use checksums
0effc7836bd0d78fc615281016f154f514e9d523d7cb9ab9e8b4d344adc5f5e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

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

Download URL comtypes-1.4.17-py3-none-any.whl
Size 298.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4e0a221dde2c589b82977bed802efd71cd5eb67a380347b732e02735e597f586
BLAKE2b-256 checksum
How to use checksums
899cd0bc1fb69ad22a04bdc01dd9b5613a2ebc4d02ba1ec24b02127dc93791ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

This release

1.4.17 This release

2 release files

1.4.15

2 release files

1.4.14

2 release files

1.4.13

2 release files

1.4.12

2 release files

1.4.11

2 release files

1.4.9

2 release files

1.4.8

2 release files

1.4.7

2 release files

1.4.6

2 release files

1.4.5

2 release files

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.14

2 release files

1.1.11

2 release files

1.1.10

1 release file

1.1.9

1 release file

1.1.8

1 release file

1.1.7

1 release file

1.1.6

1 release file

1.1.5

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.0

1 release file

0.6.4

1 release file

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