pywin32 Documentation

repository·main·Indexed 26 days ago

https://github.com/mhammond/pywin32

Python extensions for accessing Windows APIs and comprehensive COM support. Includes the adodbapi module for database connectivity via ADO, instructions for running Python code as a Windows Service, and guidance on installation via pip or pacman for MingGW/msys2. Provides details on the MAPI Stub Library, SWIG Win32 extensions, and the AutoDuck 2.0 documentation utility.

Tokens
9.6K
Snippets
21
Records
70
Agent score
91%

What's inside pywin32

  1. Use adodbapi for database connections

    main

    The adodbapi module is a PEP-249 (DB-API 2.0) compliant interface for Microsoft ADO. It allows you to connect to various data sources and execute SQL queries.

    Key Features:

    • Column Name Access: You can retrieve data by column name directly from the row object.
    • Parameter Styles: Supports multiple paramstyles: 'qmark', 'named', 'format', 'pyformat', and 'dynamic'.
      • If using 'named', you must pass a dictionary of parameters to the .execute() method.
      • If using 'format', 'pyformat', or 'dynamic', you may pass a dictionary if the SQL string is formatted correctly.
    • Context Managers: Connection objects act as context managers for transactions (automatically committing or rolling back), and Cursor objects act as context managers to ensure they are automatically closed.
    # Example of data retrieval by column name
    for row in myCurser.execute("select name,age from students"):
        print("Student", row.name, "is", row.age, "years old.")
  2. Use AutoDuck 2.0 to generate documentation from source files

    main

    AutoDuck is a command-line utility designed to extract specially tagged comment blocks from programming source files. It generates rich text files containing these blocks, which can be used to document programming APIs.

    Key capabilities include:

    • Extracting documentation directly from source code comments.
    • Generating online Help files with full hypertext, including links and keyword lists.
    • Integration into build processes to automatically regenerate Help databases during each build.
  3. Use the Python ISAPI extension

    main
    The isapi module provides a Python ISAPI (Internet Server Application Programming Interface) extension. To learn how to implement and use this extension, refer to the code examples provided in the samples directory of the repository, specifically samples\README.txt.
  4. Set up build environment for Visual Studio 2022

    main

    To build pywin32 using Visual Studio 2022, install Visual Studio 2022.

    In the Visual Studio Installer, select Visual Studio Build Tools 2022, click Modify, and ensure the following are checked under Desktop development with C++:

    • MSVC v143 - VS 2022 C++ x64/x86 build tools
    • Windows 10 SDK
    • C++ MFC for latest v143 build tools (x86 & x64)
    • C++ ATL for latest v143 build tools

    For ARM64 cross-compilation, select these from the "Individual Components" tab:

    • MSVC v143 - VS 2022 C++ ARM64/ARM64EC build tools (Latest)
    • C++ MFC for latest v143 build tools (ARM64/ARM64EC)
    • C++ ATL for latest v143 build tools (ARM64/ARM64EC)
  5. Set up build environment for Visual Studio 2019

    main

    To build pywin32 using Visual Studio 2019, install the Build Tools for Visual Studio 2019 (Version 16.0).

    In the Visual Studio Installer, select Visual Studio Build Tools 2019, click Modify, and ensure the following are checked under C++ build tools:

    • MSVC v142 - VS 2019 C++ x64/x86 build tools
    • Windows 10 SDK
    • C++ MFC for latest v142 build tools (x86 & x64)
    • C++ ATL for latest v142 build tools

    For ARM64 cross-compilation, select these from the "Individual Components" tab:

    • MSVC v142 - VS 2019 C++ ARM64 build tools
    • C++ MFC for latest v142 build tools (ARM64)
    • C++ ATL for latest v142 build tools (ARM64)
  6. Create an ISAPI extension module

    main

    An ISAPI extension module in pywin32 requires two specific files to function within IIS:

    1. A loader DLL: A special Python loader DLL that IIS loads. By convention, this filename typically starts with a leading underscore (e.g., _MyIISModule.dll).
    2. A Python module: The actual implementation file. The loader DLL identifies which module to load by removing the first character of its own base name (e.g., MyIISModule.py).

    This dual-file mechanism ensures that different Python extensions on the same server remain isolated, each receiving its own thread-pool and avoiding conflicts with IIS filter ordering semantics.

  7. Access ISAPI documentation via PyWin32.chm

    main

    Detailed documentation for the ISAPI extension is contained within the PyWin32.chm help file. You can access this documentation through the following methods:

    1. Via Pythonwin: Open the application and navigate to Pythonwin -> Help.
    2. Via Windows Start Menu: Search for the PyWin32 help file in your Start menu.