Metadata-Version: 2.4
Name: litexpy
Version: 0.0.5
Summary: Python runner for an interactive litex terminal session.
Project-URL: Homepage, https://github.com/litexlang/litexpy
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# litexpy

Python runner for an interactive `litex` terminal session.

## Links

- PyPI: https://pypi.org/project/litexpy/
- GitHub: https://github.com/litexlang/litexpy

## Prerequisites

`litexpy` starts the local `litex` command in an interactive terminal session.
It does not bundle the Litex executable, so install Litex first if `litex` is
not already available in your terminal.

Full setup guide:

- https://litexlang.com/doc/Setup

### If you already have Litex

If `litex -version` works in your terminal, install only the Python package:

```bash
pip install litexpy
```

### If you have not installed Litex

Install Litex first, then install `litexpy`.

macOS:

```bash
brew install litexlang/tap/litex
pip install litexpy
litex -version
```

Linux (Ubuntu/Debian, amd64):

```bash
tag=$(curl -fsSL https://api.github.com/repos/litexlang/golitex/releases/latest | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
wget "https://github.com/litexlang/golitex/releases/download/${tag}/litex_${tag}_amd64.deb"
sudo dpkg -i "litex_${tag}_amd64.deb"
pip install litexpy
litex -version
```

Windows PowerShell:

```powershell
$ErrorActionPreference = 'Stop'
$repo = 'litexlang/golitex'
$tag = (Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/releases/latest" -Headers @{ 'User-Agent' = 'litex-install' }).tag_name
$name = "litex_${tag}_windows_amd64.exe"
$url = "https://github.com/$repo/releases/download/$tag/$name"
$dir = Join-Path $env:LOCALAPPDATA 'litex'
$exe = Join-Path $dir 'litex.exe'
New-Item -ItemType Directory -Force -Path $dir | Out-Null
Invoke-WebRequest -Uri $url -OutFile $exe
$userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
if (-not $userPath) { $userPath = '' }
if ($userPath -notlike "*$dir*") {
    $newPath = if ($userPath) { "$userPath;$dir" } else { $dir }
    [Environment]::SetEnvironmentVariable('Path', $newPath, 'User')
}
$env:Path = "$dir;$env:Path"
pip install litexpy
litex -version
```

## Usage

```python
import litexpy

runner = litexpy.Runner()

results = runner.run("1 = 1\n0 = 0")
clear_result = runner.clear()
runner.quit()
```

`litexpy.Runner()` starts the `litex` command in an interactive terminal
process. `run(script)` sends script to that process and returns the JSON
results as a list of Python `dict` objects, `clear()` is equivalent to
`run("clear")`, and `quit()` closes the running `litex` process.
