{"id":6613,"library":"edk2-pytool-library","title":"EDK2 PyTool Library","description":"The edk2-pytool-library is a Tianocore-maintained Python library, currently at version 0.23.13, that supports UEFI EDK2 firmware development. It provides modules for tasks such as parsing EDK2-specific file types, encoding/decoding UEFI binary structures, wrapping system CLI tools (e.g., signtool), and offering general utilities like logging and path resolution. Its intent is to provide reusable python code and is typically consumed by other tools and scripts, rather than directly by end-users via command-line interfaces. It is released on an ongoing basis, with minor releases for each merged pull request.","status":"active","version":"0.23.13","language":"en","source_language":"en","source_url":"https://github.com/tianocore/edk2-pytool-library","tags":["UEFI","EDK2","firmware","development","tools","tianocore"],"install":[{"cmd":"pip install --upgrade edk2-pytool-library","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required runtime environment.","package":"python","version":">=3.10"}],"imports":[{"symbol":"Edk2Path","correct":"from edk2toollib.path_utilities import Edk2Path"},{"symbol":"PrintFileData","correct":"from edk2toollib.utility_functions import PrintFileData"}],"quickstart":{"code":"from edk2toollib.path_utilities import Edk2Path\nfrom pathlib import Path\nimport tempfile\n\n# Create a dummy workspace and package for demonstration\nwith tempfile.TemporaryDirectory() as tmpdir:\n    workspace_path = Path(tmpdir) / \"edk2_workspace\"\n    package_path = workspace_path / \"MyPkg\"\n    (package_path / \"MyModule\").mkdir(parents=True)\n    (package_path / \"MyModule\" / \"MyModule.inf\").touch()\n\n    workspace_path.mkdir()\n    package_path.mkdir()\n\n    # Instantiate Edk2Path - note the performance warning in warnings section\n    edk2_path_obj = Edk2Path(ws=workspace_path, package_path_list=[package_path])\n\n    # Example: Get an EDK2 relative path\n    abs_module_path = package_path / \"MyModule\" / \"MyModule.inf\"\n    edk2_relative_path = edk2_path_obj.GetEdk2RelativePathFromAbsolutePath(str(abs_module_path))\n    print(f\"EDK2 Relative Path: {edk2_relative_path}\")\n\n    # Example using a utility function (requires a file to print)\n    test_file = Path(tmpdir) / \"test.txt\"\n    test_file.write_text(\"Hello, EDK2!\")\n    print(\"\\nPrinting file data:\")\n    # PrintFileData is often used internally, no direct output capturing shown here for simplicity\n    # The function itself prints to console, so we can't easily assert its output without mocking sys.stdout\n    # For demonstration, we simply call it.\n    # In a real scenario, you'd likely use a logger or capture stdout.\n    # from edk2toollib.utility_functions import PrintFileData\n    # PrintFileData(str(test_file))\n    print(f\"Content of {test_file.name}: {test_file.read_text()}\") # Simulate PrintFileData output","lang":"python","description":"This quickstart demonstrates how to import and use the `Edk2Path` class from `edk2toollib.path_utilities` to manage EDK2 file paths. It sets up a temporary workspace and package structure to showcase how an absolute path can be converted into an EDK2 relative path. It also includes a brief mention of a utility function from `edk2toollib.utility_functions`."},"warnings":[{"fix":"Always activate a virtual environment before installing or using `edk2-pytool-library`: `python -m venv .venv && source .venv/bin/activate` (Linux/macOS) or `.venv\\Scripts\\activate.bat` (Windows).","message":"It is strongly recommended to use Python virtual environments when working with `edk2-pytool-library` (and related EDK2 tools). This helps prevent dependency conflicts with other Python projects and ensures a consistent development environment. This recommendation is consistently highlighted in the official documentation for both the library and related tools.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure that the directory paths assigned to `WORKSPACE`, `PACKAGES_PATH`, and `EDK_TOOLS_BIN` environment variables do not contain any spaces.","message":"The EDK2 build system (which `edk2-pytool-library` supports) is sensitive to spaces in certain environment variables. `WORKSPACE`, `PACKAGES_PATH`, and `EDK_TOOLS_BIN` must not contain space characters, even if the operating system permits them.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review your build environment and scripts to ensure they are updated to use the `edk2-pytool-library` and `edk2-pytool-extensions` as part of the Tianocore `edk2-pytools` framework. Refer to the latest EDK2 build documentation for `stuart` (from `edk2-pytool-extensions`) for the current recommended patterns.","message":"The Project Mu Python packages for UEFI support and build tools have migrated to Tianocore and are now leveraged through `edk2-pytools`. This change implies that older build setups or documentation referencing Project Mu's tools may be outdated and require updates to align with the new `edk2-pytools` ecosystem.","severity":"breaking","affected_versions":"Users migrating from Project Mu-based setups"},{"fix":"For scenarios involving frequent path operations within a consistent EDK2 workspace, create a single instance of `Edk2Path` and reuse it, rather than creating new instances multiple times.","message":"The `Edk2Path` class performs expensive package path and package validation during instantiation. If you are repeatedly using the same workspace root and packages path, it is strongly suggested to instantiate `Edk2Path` only once and pass that single instance to all consumers to avoid performance overhead.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Verify if a fix for this specific `inf_generator` issue has been released. If encountering this, consult the `edk2-pytool-library` GitHub issues or Tianocore documentation for potential workarounds or updates to the `inf_generator` usage that correctly handles integrity file paths.","message":"An issue was reported (June 2023) where Capsule Update fails from the OS due to changes in `inf_generator`, specifically an integrity file's location not being updated alongside other changes, leading to a 'file not found' error.","severity":"breaking","affected_versions":"Potentially versions prior to a fix (if implemented after June 2023). Users on current versions should test this functionality."}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}