{"id":14817,"library":"powerfx","title":"Power Fx Python Bridge","description":"The `powerfx` Python library (current version 0.0.34) acts as a bridge to invoke the C# implementation of Microsoft Power Fx, a low-code, general-purpose programming language. It enables Python applications to evaluate Power Fx expressions. This library is actively maintained by Microsoft and sees releases periodically, often tied to updates within the broader Power Platform ecosystem.","status":"active","version":"0.0.34","language":"en","source_language":"en","source_url":"https://github.com/microsoft/agent-framework/issues?q=powerfx","tags":["microsoft","powerfx","low-code",".net","interop","declarative"],"install":[{"cmd":"pip install powerfx","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"The `powerfx` library is a C# bridge and relies on `pythonnet` to interoperate with the .NET runtime. This is an implicit dependency and often causes runtime errors if the .NET runtime is not correctly configured.","package":"pythonnet","optional":false},{"reason":"As a bridge to a C# implementation, `powerfx` requires a compatible .NET runtime to be installed and accessible on the system. Without it, the library will fail to initialize.","package":"dotnet-runtime","optional":false}],"imports":[{"note":"The `Engine` class is the primary entry point for evaluating Power Fx expressions.","symbol":"Engine","correct":"from powerfx import Engine"}],"quickstart":{"code":"import os\nfrom powerfx import Engine\n\n# Ensure DOTNET_ROOT is set if .NET runtime is not in standard paths\n# Example: os.environ['DOTNET_ROOT'] = '/usr/local/share/dotnet'\n\n# Initialize the Power Fx engine\nengine = Engine()\n\n# Define variables that can be used in Power Fx expressions\nengine.add_host_object('Name', 'Alice')\nengine.add_host_object('Age', 30)\n\n# Evaluate a simple Power Fx expression\nexpression = '\"Hello \" & Name & \", you are \" & Text(Age) & \" years old!\"'\nresult = engine.eval(expression)\n\nprint(f\"Power Fx Expression: {expression}\")\nprint(f\"Result: {result.to_string()}\")\n\n# Example with a conditional expression\nconditional_expression = 'If(Age >= 18, \"Adult\", \"Minor\")'\nconditional_result = engine.eval(conditional_expression)\n\nprint(f\"\\nPower Fx Conditional Expression: {conditional_expression}\")\nprint(f\"Conditional Result: {conditional_result.to_string()}\")","lang":"python","description":"This quickstart demonstrates how to initialize the `powerfx.Engine`, register Python objects as host objects, and evaluate Power Fx expressions. It includes an example of string concatenation and a conditional statement. Note the crucial importance of a correctly installed and discoverable .NET runtime for `powerfx` to function."},"warnings":[{"fix":"Always check the official Microsoft Power Fx documentation and any related .NET/C# interop documentation for compatibility. Pin `powerfx` versions in production environments.","message":"The `powerfx` library is a Python bridge to a C# implementation. Major updates to the underlying Power Fx language or the C# runtime it depends on may introduce breaking changes not directly reflected in the Python package versioning.","severity":"breaking","affected_versions":"All versions"},{"fix":"Ensure the appropriate .NET SDK or runtime is installed for your operating system (e.g., via `sudo apt install dotnet-sdk-8.0` on Linux, or `brew install --cask dotnet-sdk` on macOS). Set the `DOTNET_ROOT` environment variable if the runtime is not in a standard location.","message":"Requires .NET Runtime: The `powerfx` Python package will not function without a compatible .NET runtime installed and correctly configured on the system. This is a common point of failure for users.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Familiarize yourself with Power Fx language concepts and syntax, which are distinct from Python. Use the `powerfx.Engine` for evaluating Power Fx expressions, not as a general-purpose Python utility library.","message":"Power Fx is a declarative, Excel-like language. Trying to use it with imperative Python programming paradigms or expecting direct object manipulation as in Python will lead to unexpected results. It's not a Pythonic library in its core logic.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the .NET SDK or runtime for your operating system and architecture. If it's not installed in a default path, set the `DOTNET_ROOT` environment variable to the path where .NET is installed (e.g., `export DOTNET_ROOT=/usr/local/share/dotnet`).","cause":"The `pythonnet` library, used by `powerfx` to bridge to the C# implementation, cannot locate the .NET runtime installation on your system.","error":"RuntimeError: Can not determine dotnet root"},{"fix":"Verify that your .NET runtime version is compatible with the `powerfx` library. Try updating your .NET runtime to the latest stable version or reinstalling it. Also, consider reinstalling `powerfx` and its dependencies (`pip uninstall powerfx pythonnet` then `pip install powerfx`).","cause":"This typically indicates an incompatibility between the installed .NET runtime and the version of the `powerfx` library's C# components, or a corrupted .NET installation.","error":"FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=..., Culture=neutral, PublicKeyToken=...' or one of its dependencies."}],"ecosystem":"pypi"}