Skip to content

Execution Python

Truong Giang Vu edited this page May 31, 2026 · 1 revision

Modern Python Scripting

Use Python 3.13 scripting when you want fast automation, data extraction, computational geometry, reporting, debugger support, or package-heavy workflows inside the host.

This page covers the modern CPython path: Python 3.13 plus PythonNet. It is one part of the broader Execution scripting support, alongside IronPython, F# scripts, and C# scripts.

Entry File

Python 3.13 script folders are discovered through files ending with:

*script.py

Example:

Samples/PythonDemo/commands/data_analysis_script.py

Dependency Metadata

Dependencies are declared with PEP 723 metadata:

# /// script
# dependencies = ["polars", "numpy"]
# ///

The runtime parses metadata before execution and prepares the environment.

Environment Strategy

The current runtime is Pixi-first:

%APPDATA%\RevitDevTool\pixi-env

If Pixi cannot run, the runtime can fall back to a pip-based pyRevit CPython provider. That fallback is intended for constrained enterprise machines and depends on pyrevit.exe being discoverable on PATH.

This is a v3.0 change from older UV-centric docs.

Revit Context

In Revit, scripts can access the active Revit application/document context provided by RevitDevTool. In other hosts, use the matching host context. For modeless UI or background work, route host API calls through the supported host execution path.

Debugging

Python debugging uses debugpy and the debugger bridge.

Typical flow:

  1. Configure VSCode attach to the RevitDevTool debug port.
  2. Start the debugger.
  3. Run the script from RevitDevTool.
  4. Breakpoints hit when debugpy is active and attached.

If debugging fails, check the active Python environment, debugpy installation, configured port, and local firewall/security rules.

For the full workflow, see Python Debugging.

Examples

Current Python samples live under:

Samples/PythonDemo/commands/

Notable examples:

  • data_analysis_script.py
  • dashboard_script.py
  • debugpy_script.py
  • selectionfilter_script.py
  • visualization_curve_script.py
  • visualization_solid_script.py
  • visualization_xyz_script.py
  • logging_format_script.py
  • modeless_script.py

Caveats

  • Package installation can be blocked by local policy or network access.
  • Revit API calls still require valid Revit context.
  • PythonNet behavior can differ from IronPython behavior, especially around .NET interop.
  • Current automated tests do not fully cover real host execution.

Related

Clone this wiki locally