Get up and running with TCLpy in your Python applications and interactive terminal shells.
Install the package from PyPI or set it up locally for development:
# Standard PyPI Installation
pip install ASTpytcl
# Or editable local development install
git clone https://github.com/TCLpy/TCLpy.git
cd TCLpy
pip install -e .
Once installed, launch the interactive shell directly from your terminal (featuring full readline history navigation and multi-line brace balancing):
tclpy
Inside the shell, write Tcl commands naturally:
tclpy> set message "Hello from TCLpy!"
tclpy> puts $message
Hello from TCLpy!
tclpy provides a clean top-level API allowing Python programs to evaluate Tcl code and share state dictionaries seamlessly.
import tclpy
env = {"x": 10, "y": 20}
tclpy.eval('set total [expr {$x + $y}]', env)
print("Total:", env["total"]) # Output: 30
import tclpy
env = {}
tclpy.source("workflow.tcl", env)
print("Result from sourced file:", env.get("result"))
You can import any Python module and invoke its functions directly using Tcl's double-colon namespace syntax:
# Import the math module and compute square root
py::import math
set root [math::sqrt 144]
puts "Square root: $root"