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. Since it is my personal playground, the selection of supported APIs and the way those are wrapped are solely dictated by 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 already another Python module that does something very similar to ctwin32 (pywin32-ctypes), it has a different purpose (namely to serve the internal needs of its creator). However, ctwin32 wraps significantly more API functions than pywin32-ctypes (as of September 2025: 417 / 16).


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 4.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 4.0.0
File Size Uploaded
ctwin32-4.0.0.tar.gz 203.0 kB Details

Built distribution (wheel)

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

Total release size: 365.3 kB

Release files / ctwin32-4.0.0.tar.gz

Download URL ctwin32-4.0.0.tar.gz
Size 203.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5a13813fd4ff9bae1f35f205b7394dc745c94013bb1f587a3280f5707ad3bddf
BLAKE2b-256 checksum
How to use checksums
2c5cdedf0b7f886662bc58cb251452bbf576bb987588f696eaabfba81d536b28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 8, 2025.

Transparency log

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

Download URL ctwin32-4.0.0-py3-none-any.whl
Size 162.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b938a42c2fbb49d26dd8d7fbbdfde62574d4f8217413bd941e2bcd421e65fcf
BLAKE2b-256 checksum
How to use checksums
3c3ea1b0d1acf1500e922eebb9f8c0093bb58e2119c43a55584f26e44fab2f3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 8, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

4.0.0 This release

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