Skip to main content

nrevah-pytcl: Pure Python TCL interpreter

Project description

pytcl

Pure Python TCL interpreter and parser library.

Installation

pip install pytcl

Usage

Interpreter

from pytcl.interpreter import Interpreter

i = Interpreter()
i.substitute_string("set x 42")         # "42"
i.substitute_string("expr {$x * 2}")    # "84"
i.substitute_string("set x")            # "84"

Evaluate a .tcl file:

from pathlib import Path
from pytcl.interpreter import Interpreter

i = Interpreter()
i.substitute_file(Path("script.tcl"))

Custom commands

Commands are plain callables stored in the namespace:

from pytcl.interpreter import Interpreter

i = Interpreter()
i.namespace["double"] = lambda args, ns: str(int(args[0]) * 2)
i.substitute_string("double 21")  # "42"

Parser

Parse Tcl source into a typed tree without executing it:

from pytcl.words import TCLScript

script = TCLScript.read(iter("set x [expr {1 + 2}]"))
for command in script.commands:
    print(command.name, command.args)

Built-in commands

set, unset, expr, if / elseif / else, while, foreach, proc, return, break, continue, incr, append, puts, error

Development

uv sync --all-extras        # install dependencies
uv run pytest               # unit tests
uv run pytest integrations/ # integration tests (requires Docker)
uv run ruff check .         # lint
uv run pre-commit run --all-files

Project details


Download files

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

Source Distribution

nrevah_pytcl-0.0.4.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

nrevah_pytcl-0.0.4-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file nrevah_pytcl-0.0.4.tar.gz.

File metadata

  • Download URL: nrevah_pytcl-0.0.4.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nrevah_pytcl-0.0.4.tar.gz
Algorithm Hash digest
SHA256 4ef7d9954e33c623d45098691f4f756f75f0b278a4c32dfa26a53076964008a2
MD5 809826fb37edbe0356a7470332f40f86
BLAKE2b-256 7603b0ef791071499281e0fb2296d31591b1171925d630d4d1ed214106c9f9c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for nrevah_pytcl-0.0.4.tar.gz:

Publisher: release.yml on netanelrevah/pytcl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nrevah_pytcl-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: nrevah_pytcl-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nrevah_pytcl-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e24a336aec2a67f40978f2fd32064cb9008cd537b17ad837d2a0ee3a16f8f426
MD5 3f09178649b51851cdb584e1e9c2ad0a
BLAKE2b-256 ae3ae88869a5d5d95e7bdceed2cdce5e9dc8cba5cedb31cd50e81bb364a95f8a

See more details on using hashes here.

Provenance

The following attestation bundles were made for nrevah_pytcl-0.0.4-py3-none-any.whl:

Publisher: release.yml on netanelrevah/pytcl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page