Skip to main content

pycomtypelib

A pure-Python, cross-platform decoder for the MSFT COM type library binary format (.tlb files, and RT_TYPELIB resources embedded in .dll / .ocx / .exe files). No Windows, no COM, no oleaut32.dll required.

This is a Python port of the type library reading logic in Wine's dlls/oleaut32/typelib.c and typelib.h, cross-checked against public documentation of the format (notably Geoff Chappell's notes on ITypeLib). Only the MSFT format is supported (the format produced by ICreateTypeLib2 / MIDL and used by essentially all modern type libraries); the older SLTG format (ICreateTypeLib, legacy VB5/VB6) is out of scope.

Wine's typelib.c is licensed LGPL-2.1-or-later; this project inherits that license since its parsing logic is derived from it.

Install

pip install -e .

Library usage

from pycomtypelib import load_typelib_file

tlb = load_typelib_file("stdole2.tlb")
print(tlb.name, tlb.guid, tlb.version)
for ti in tlb.typeinfos:
    print(ti.typekind.name, ti.name)

To pull a type library out of a compiled binary (DLL/OCX/EXE) instead of a standalone .tlb file:

from pycomtypelib import load_typelib_from_pe

tlb = load_typelib_from_pe("MSCOMCTL.OCX")

CLI

pycomtypelib dump stdole2.tlb
pycomtypelib dump MSCOMCTL.OCX --json > mscomctl.json

Cross-library references (e.g. an interface inheriting from IUnknown or IDispatch, which live in stdole2.tlb) can't be resolved to a full TypeInfo without also parsing the imported library, so by default they're shown by name via a small built-in table of well-known COM/OLE Automation interface GUIDs (pycomtypelib.WELL_KNOWN_INTERFACES). Pass -n / --no-wellknown-guids to disable that and show the raw GUID and import library name instead:

pycomtypelib dump -n stdole2.tlb

This only affects display (--json's wellknown_name field, and the IDL-like text renderer); it never affects decoding itself.

Scope

  • Reads the MSFT binary layout: header, segment directory, GUID/name/string tables, type descriptors, array descriptors, per-TypeInfo function/variable/ implemented-type records, imported type libraries, and custom data.
  • Resolves this into a friendly object model (TypeLib, TypeInfo, FuncDesc, VarDesc, ParamDesc, TypeDesc, ...) analogous to what ITypeInfo exposes, including resolution of VT_USERDEFINED references to other TypeInfo entries (in the same library or in imported libraries).
  • Read-only: this library decodes type libraries, it does not write/compile them.

Metadata

Release files for pycomtypelib 0.1.0

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

Source distribution (sdist)

Source distribution for pycomtypelib 0.1.0
File Size Uploaded
pycomtypelib-0.1.0.tar.gz 35.6 kB Details

Built distribution (wheel)

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

Total release size: 71.0 kB

Release files / pycomtypelib-0.1.0.tar.gz

Download URL pycomtypelib-0.1.0.tar.gz
Size 35.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0cc3ce0680f984b89dca84bbb80f195ff9c75c9ec4eab8920a140ef192aa432c
BLAKE2b-256 checksum
How to use checksums
3b440bcad64c32191250e8999164abf29f474148bc80db5fe2698aeb269e9c9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / pycomtypelib-0.1.0-py3-none-any.whl

Download URL pycomtypelib-0.1.0-py3-none-any.whl
Size 35.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c9ce70df4cc19c68d7df271f5cf051ef46fb3227eb5c37a9bbd5ed38149d9a4
BLAKE2b-256 checksum
How to use checksums
cf9606c8664ff78847155943d79bd62d08d4edc080d7ee0a57cc05ce4a3060e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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