Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

dynwinrt-codegen

Generate typed Python bindings for Windows Runtime (WinRT) APIs from .winmd metadata.

dynwinrt-codegen reads the metadata shipped by the Windows SDK, WinAppSDK, and other Windows components. It emits Python modules that use dynwinrt to invoke those APIs at runtime. The generated API uses Python naming, values, collections, type annotations, and asyncio-compatible operations.

Why use this?

Calling a WinRT API without an existing Python projection normally requires a native extension or handwritten metadata, COM ABI, and marshaling code. dynwinrt-codegen derives that information from .winmd files and generates:

  • Python classes with snake_case properties and methods
  • type-checked overloads and .pyi type stubs
  • asyncio-compatible WinRT operations
  • Python-native collections, GUIDs, dates, times, and byte arrays
  • enums, structs, delegates, and event helpers
  • a package manifest pinned to the matching dynwinrt runtime version

The generator is a standalone Windows executable. Installing or running it does not require Cargo or Rust.

Install and generate

python -m pip install --pre dynwinrt-codegen

# Generate one Windows SDK class.
dynwinrt-codegen generate `
  --namespace Windows.Foundation `
  --class-name Uri `
  --lang py `
  --output .\generated_uri

# Install the generated package and its exact dynwinrt runtime dependency.
python -m pip install .\generated_uri

The generated package can then be imported normally:

from dynwinrt import RoApartment, projected_lifetime_scope
from generated_uri.windows.foundation import Uri

with RoApartment(1), projected_lifetime_scope():
    uri = Uri("https://example.com/path")
    print(uri.host)

CLI options

Option Description
--winmd PATH[;PATH...] Metadata file paths. Sibling .winmd files are discovered automatically. The Windows SDK is auto-detected when no input supplies Windows.* metadata.
--winmd-list FILE Newline-separated metadata paths to emit; blank lines and # comments are ignored.
--folder DIR Load every .winmd file directly inside a directory.
--namespace NS Generate one namespace. Without it, generate all non-Windows.* namespaces in the input.
--class-name NAME[,NAME...] Generate specific classes or public interfaces. Use fully qualified names, or unqualified names together with --namespace.
--ref PATH[;PATH...] Metadata used only for type resolution. Sibling discovery is disabled for references.
--ref-list FILE Newline-separated reference metadata paths; blank lines and # comments are ignored.
--output DIR Dedicated codegen-owned output directory (default ./generated). Existing contents may be replaced or removed.
--dry-run Validate metadata and dependencies without writing files.
--pyi Explicitly request the default Python type stubs; retained for compatibility.
--no-pyi Omit .pyi files and the py.typed marker.

Use --lang py for every Python generation command. Run dynwinrt-codegen generate --help for the complete command reference.

More examples

Generate two classes from the Windows SDK:

dynwinrt-codegen generate `
  --namespace Windows.Storage `
  --class-name StorageFile,StorageFolder `
  --lang py `
  --output .\storage_bindings

Generate all non-system namespaces from a restored metadata folder:

dynwinrt-codegen generate `
  --folder C:\path\to\metadata `
  --lang py `
  --output .\component_bindings

Use explicit reference metadata for a reproducible generation:

dynwinrt-codegen generate `
  --winmd-list .\winmd-inputs.txt `
  --ref-list .\winmd-references.txt `
  --lang py `
  --output .\component_bindings

Validate a request without changing its output directory:

dynwinrt-codegen generate `
  --folder C:\path\to\metadata `
  --lang py `
  --output .\component_bindings `
  --dry-run

Generated output

The output is an installable Python package. Its generated pyproject.toml pins dynwinrt to the generator's exact version and requires CPython 3.11–3.14. .pyi files and a py.typed marker are emitted by default.

Transitive metadata dependencies are resolved automatically. Namespace packages and imports mirror the metadata hierarchy, while public members use Python snake_case naming. XML documentation found beside the input metadata is included when available.

Generated async methods return typed awaitable objects. WinRT collections implement standard collections.abc protocols, flags use enum.IntFlag, and compatible method inputs accept native Python sequences, mappings, bytes, bytearray, uuid.UUID, datetime.datetime, and datetime.timedelta.

The output directory belongs to codegen; do not store handwritten files in it. After changing metadata files, SDK versions, or reference inputs, regenerate the complete output.

Platform and limitations

  • The standalone generator has py3-none-win_amd64 and py3-none-win_arm64 wheels for Python 3.8–3.14.
  • Generated bindings and the dynwinrt runtime require CPython 3.11–3.14 on Windows x64 or ARM64.
  • Python generation currently supports WinRT metadata. Classic COM generation from Windows.Win32.winmd is currently available only for JavaScript and TypeScript.
  • Some APIs require their Windows component, package identity, or framework bootstrap to be present at runtime.

Python module components longer than 120 characters are shortened with a stable readable prefix and hash suffix while public type names remain unchanged.

Links

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

dynwinrt_codegen-0.1.0rc21-py3-none-win_arm64.whl (1.9 MB view details)

Uploaded Python 3Windows ARM64

dynwinrt_codegen-0.1.0rc21-py3-none-win_amd64.whl (2.1 MB view details)

Uploaded Python 3Windows x86-64

File details

Details for the file dynwinrt_codegen-0.1.0rc21-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for dynwinrt_codegen-0.1.0rc21-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 d0253e9f3d37862028ef369d204b9a6cbb14bfed7646c0653f7884717483dafe
MD5 a6060336e98be654e923a833c6b2f7e2
BLAKE2b-256 8cec17dd33ea13734dcf6678e3ef35f32555563449c1605e3ada78a07c6085f4

See more details on using hashes here.

File details

Details for the file dynwinrt_codegen-0.1.0rc21-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for dynwinrt_codegen-0.1.0rc21-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 59fe82c158a90dc458434f6a3f2f82bc06c2693b9be1d64bec9441083d30464d
MD5 05d35cf65015464bd94738e93a8bcbd2
BLAKE2b-256 ccd8f9a38174bbb2da1b98852896d3f4a9fee5439db772b2d8c5429ab582267d

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0rc21 This release

2 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