Skip to main content

Pure Python COM package

Project description

comtypes

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

Ongoing plans

GetModule will also generate static typing for methods and properties

comtypes.client.GetModule generates Python wrapper modules from a COM type library, containing interface classes, coclasses, constants, and structures. The .py files are generated in the comtypes.gen package.

In the current comtypes specification, type checkers could not infer static type information from generated modules codebase, since methods and properties were mostly defined and implemented by metaclasses.
In future release, in generated modules, static typing will be added to part of methods and properties.

Static type information is added only under if TYPE_CHECKING: blocks. Consequently, it will not override any methods defined with metaclasses at runtime, ensuring that the runtime behavior remains unchanged.

Please refer to the GitHub issue for details.

In friendly modules, the names that were used as aliases for ctypes.c_int will be used for enumeration types implemented with enum

comtypes.client.GetModule generates two Python modules in the comtypes.gen package with a single call.

A first wrapper module is created with a long name that is derived from the type library guid, version number and lcid. It contains interface classes, coclasses, constants, and structures.
A second friendly module is created with a shorter name derived from the type library name itself. It imports items from the wrapper module, and will be the module returned from GetModule.

In the current comtypes specification, if a COM type kind is defined as an enumeration type, that type name is used as an alias for ctypes.c_int in the wrapper module, and that symbol is imported into the friendly module.
In future release, in friendly modules, their names will no longer be aliases for c_int. Instead, they will be defined as enumerations implemented with enum.

When imported into the friendly module, the wrapper module will be aliased with an abstracted name (__wrapper_module__). This allows users to continue using the old definitions by modifying the import sections of their codebase.

Please refer to the GitHub issue for details.

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.

Documentation:

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

comtypes-1.3.0.zip (216.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

comtypes-1.3.0-py3-none-any.whl (194.1 kB view details)

Uploaded Python 3

File details

Details for the file comtypes-1.3.0.zip.

File metadata

  • Download URL: comtypes-1.3.0.zip
  • Upload date:
  • Size: 216.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for comtypes-1.3.0.zip
Algorithm Hash digest
SHA256 b77cca9faaa9c1246eb4dbfa0723ef161ab852f633330a097a5b6c7a8d8bfc05
MD5 61b17663beabe395954a6ae54233156d
BLAKE2b-256 a60859d77ff3bdf61b1ff181cf6e71d68e9806f8bedfe51c38a2a4cb9a4e7e20

See more details on using hashes here.

File details

Details for the file comtypes-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: comtypes-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 194.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for comtypes-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5473b0eb8c85f17c11d2269c46e41fdef6ce21c8441ed674d2921c63cf171b6a
MD5 ecaa32250c6fbb5fff07a5b878d38e7e
BLAKE2b-256 7ef1759a8c4d58695b9fcc2e22b0c986447759534084ddd6c4ad53df07c6fdfa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page