Python Win32 Extensions.

This set of extensions for Python exposes much of the Win32 API and other Win32 extensions.

You will find support for the following areas:

Generic API's

The API itself

NT Specific Support

NT Services
Performance Helper
Event Log

The API Itself

Python supports most of the windows API. You will find wrappers for the most core areas, including network, events, files, pipes, Remote Access (ie, Dial Up Networking), LZ Compression, DDE, Security, Memory Mapped Files, etc.

In general, these modules will expose the raw Windows API. The package includes a reference WinHelp file that documents all the methods available, their arguments and return types.


ODBC (Open Database Connectivity) is an API that works across multiple database vendors. Please visit our ODBC documentation for more information on this module.

NT Services

Python fully supports NT Services. Python code can work as a native NT Services, responding to NT Service control requests in any way it chooses. This is a very unique feature of scripting languages for this platform.

The design philosophy is that you create a Python class which implements the service. The NT Service control functions are mapped to methods on your class.

Once the software is installed, you will find 2 sample services in the demos directory.

Memory Mapped Files

Access to Win32 Memory Mapped files. Memory mapped files allow efficient sharing of data between separate processes. It allows a block of (possibly shared) memory to behave like a file.

NT Performance Monitor

Modules: win32pdh.pyd,,

The win32 Performance Data Helper module and utility. These are interfaces to the pdh dll from Microsoft. MSDN has documentation on the interface, and the .py files contain sample code.

Mike Fletcher (the author of the win32pdhquery module) has also kindly written this tutorial on win32pdhquery.


A module that provides popen() functionality (and more!) to work from a win32 GUI process (which os.popen doesnt!). This module also exposes the win32 pipe API, allowing you to create and connect named pipes.


These modules allow one Python process to generate output via a "print" statement, and another unrelated Python process to display the data. This works even if the Python process generating the output is running under the context of a service, where more traditional means are not available. The module works on Windows 95 and Windows NT.

To enable this debugging, simply "import win32traceutil" somewhere in your program - thats it! This automatically re-directs the standard Python output streams to the remote collector (If that behaviour is undesirable, you will need to use win32trace directly.) To actually see the output as it is produced, start a DOS prompt, and run the file "" (eg, double-click on it from Explorer, or "python.exe") This will print all output from all other Python processes (that have imported win32traceutil) until you kill it with Ctrl+Break!)

You should ensure that only one "collector" process is running at a time. If not, only one of the collector processes will see the output - although which process gets which bit of output is indeterminate!

Also, there is a limitation of 64k of buffered data. If 64k of data is stored before any collector has read it, the buffer will be emptied, and filled from the start. This means previous output is lost. This should only ever happen if an output process has been running for a while with no collector running.


Access to the Win32 timers. Timers are only available in GUI programs. No documentation, except what follows:

The following code demos how to make a timer.

import timer

# glork holds a simple counter for us.

class glork:

        def __init__ (self, delay=1000, max=10):
                self.x = 0
                self.max = max
       = timer.set_timer (delay, self.increment)

        def increment (self, id, time):
                print 'x = %d' % self.x
                self.x = self.x + 1
                # if we've reached the max count,
                # kill off the timer.
                if self.x > self.max:
                        # we could have used '' here, too
                        timer.kill_timer (id)

# create a counter that will count from '1' thru '10', incrementing
# once a second, and then stop.

def demo (delay=1000, stop=10):
        g = glork(delay, stop)


Access to the Win32 API.


Access to the Win32 Remote Access API. This allows you to make and break RAS connections, query the status of connections, etc. Some of the methods may only work on certain platforms (eg, "AddPhoneBook" does not work on Windows NT 3.51 - presumably it will in later versions of NT.