Skip to main content

logo ctwin32

winonly PyPI - Version PyPI - Python Version License - MIT PyPI - Stats


ctwin32 is a pure Python module, that wraps some Windows APIs (win32) by using ctypes. The selection of supported APIs and the way they are wrapped is largely based on my needs and preferences.

ctwin32 is not a replacement for pywin32, although it serves that purpose for me (in conjunction with comtypes). Compared with pywin32 the coverage of ctwin32 is downright tiny.

Here is an example of a classic ‘Hello world’ program:

from ctwin32 import user, gdi, wndcls, wtypes
from ctwin32 import WM_CREATE, WM_PAINT, WM_DESTROY
from ctwin32 import DT_CENTER, DT_SINGLELINE, DT_VCENTER

class HelloWnd(wndcls.SimpleWnd):

    DT_FLAGS = DT_CENTER | DT_SINGLELINE | DT_VCENTER
    MSG = "Hello from ctwin32!"

    def on_message(self, msg, wp, lp):

        if msg == WM_CREATE:
            lf = wtypes.LOGFONT(
                lfHeight=-72,
                lfFaceName = "MS Shell Dlg"
                )
            self.font = gdi.CreateFontIndirect(lf)
            return 0

        if msg == WM_PAINT:
            hdc, ps = self.begin_paint()
            oldfont = gdi.SelectObject(hdc, self.font)
            user.DrawText(hdc, self.MSG, self.client_rect(), self.DT_FLAGS)
            gdi.SelectObject(hdc, oldfont)
            self.end_paint(ps)
            return 0

        if msg == WM_DESTROY:
            gdi.DeleteObject(self.font)
            user.PostQuitMessage(0)
            return 0

        return self.def_win_proc(msg, wp, lp)

if __name__ == "__main__":

    icon = wndcls.load_ctwin32_ico()
    wnd = HelloWnd(wndcls.WndCreateParams("Hello Window", icon))
    wnd.show()

    while msg := user.GetMessage():
        user.TranslateMessage(msg)
        user.DispatchMessage(msg)

See the samples directory for several instances of how ctwin32 can be used.

While there is another Python module that does something very similar to ctwin32 (pywin32-ctypes), ctwin32 wraps significantly more API functions than pywin32-ctypes (as of October 2026: 440 / 21).


Note: Even though ctwin32 is a pure Python module, it can of course only be used on Windows. For the first three years or so, packages were tagged with the Windows platform tags to prevent pip from using them on other operating systems. However, it became futile to try to prevent this when after only one year the sdist package was also released. In the absence of suitable wheel packages for other operating systems, this would mean that pip install ctwin32 would now use the sdist package to install ctwin32 anyway. Therefore, a universal wheel is now distributed and it is up to the user to be smart enough to use it on Windows only.

Metadata

Release files for ctwin32 5.0.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 ctwin32 5.0.0
File Size Uploaded
ctwin32-5.0.0.tar.gz 226.2 kB Details

Built distribution (wheel)

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

Total release size: 405.4 kB

Release files / ctwin32-5.0.0.tar.gz

Download URL ctwin32-5.0.0.tar.gz
Size 226.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b9129bb169c1068d514500150d91e8f0e69db0664babb79f1c3cf77072111c58
BLAKE2b-256 checksum
How to use checksums
728fb988292d163ebed96b0fb6179adcd4492fa4c275ecb70b7a96c8c393f724
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.

Transparency log

Release files / ctwin32-5.0.0-py3-none-any.whl

Download URL ctwin32-5.0.0-py3-none-any.whl
Size 179.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
873f1bcd1512bf697745bf3f2f76d53f3ad2a9e426b11f820b8040adf2328f81
BLAKE2b-256 checksum
How to use checksums
2b5bf97eb2975ebb46f17dcd7e6fe4339c7f33d6c7199bc78993b2f12600a7fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

5.0.0 This release

2 release files

4.0.0

2 release files

3.0.0

2 release files

2.7.1

4 release files

2.7.0

4 release files

2.6.0

4 release files

2.5.0

4 release files

2.4.0

4 release files

2.3.0

4 release files

2.2.0

4 release files

2.1.0

4 release files

2.0.0

4 release files

1.11.0

4 release files

1.10.0

4 release files

1.9.0

3 release files

1.8.0

3 release files

1.7.12

3 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.4

2 release files

0.1.3

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