# Python with Elide

> Run Python 3.13 with elide python: CPython-style arguments, the bundled stdlib, and JS interop

Python support is experimental in 1.6.0.

Elide runs Python 3.13 with its standard library; no CPython install is needed. Python is an optional component:

```bash
elide setup python
```

`--channel=release` or `--channel=nightly` picks the channel, and `--force` reinstalls. apt and RPM installs cannot
add it; [Installation](https://elide.help/docs/installation#python) lists the methods that can. Without the component, a Python command
prints `Python support is not installed. Run 'elide setup python' to add it.` and exits `2`.

## Run Python

`elide python` takes the same arguments as `python`:

```bash
elide python app.py --name Elide --count 2   # sys.argv: ['app.py', '--name', 'Elide', '--count', '2']
elide python -c 'import sys; print(sys.version)'
elide python -m json.tool input.json
echo 'print("from stdin")' | elide python -
```

Every token after the script, `-c CMD`, or `-m MODULE` is a program argument. Bare `elide python` starts the REPL
in a terminal and reads standard input otherwise.

<img src="https://elide.help/assets/demos/python-cli.gif" alt="Running a Python program with command-line arguments in Elide" width="1591" height="764" loading="lazy" decoding="async" class="rounded-lg border border-border my-6 w-full" />

The general commands also run `.py` files, with the same `sys.argv`:

```bash
elide app.py
elide run app.py
elide -l python -s 'print(1 + 1)'
```

### Interpreter options

These go before the script, `-c`, or `-m`. `elide --help-all` lists them under "Python interpreter options".

| Flag | Effect |
| --- | --- |
| `-c CMD` | Run `CMD` as the program; trailing tokens become `sys.argv[1:]`. |
| `-m MODULE` | Run a library module as `__main__`. |
| `-s` | Don't add the user site directory to `sys.path`. |
| `-I` | Isolated mode. |
| `-E` | Ignore `PYTHON*` environment variables. |
| `-S` | Don't `import site` on startup. |
| `-P` | Don't prepend a potentially unsafe path to `sys.path`. |
| `-B` | Don't write bytecode files. |
| `-u` | Unbuffered standard output and error. |
| `-O` | Optimization level; repeat for `-OO`. |
| `-b` | Warn on `bytes`/`str` comparisons; repeat to raise errors. |
| `-W ARG` | Warning control; repeatable. |
| `-x` | Accepted for compatibility; no effect. |

## Standard library

The Python 3.13 standard library is included, among it `json`, `pathlib`, `sqlite3`, `ssl`, `zlib`, and
`ctypes`. `bz2` and `lzma` need no system `libbz2` or `liblzma`.

## JavaScript interop

With `--interop`, Python evaluates JavaScript through the built-in `elide` module:

```python
# sum.py
from elide import js

print(js("[1, 2, 3].reduce((a, b) => a + b, 0)"))
```

```bash
elide --interop python sum.py
```

JavaScript and TypeScript import a Python module's default export:

```javascript
// main.mjs
import mod from "./mod.py";
console.log(mod.hello());
```

```bash
elide --interop run main.mjs
```

Without `--interop`, these calls fail. See [Languages and Interop](https://elide.help/docs/languages).

## Third-party packages

Elide does not install PyPI packages: `elide install` skips `dependencies.pypi`, and
`elide install --ecosystems=pypi` exits `2`. Packages in a Python 3.13 virtual environment load when `VIRTUAL_ENV`
points at it:

```bash
export VIRTUAL_ENV=/path/to/venv
elide python app.py
```

Elide reads the environment's `lib/python3.13/site-packages`.

## Known limitations

- **C extensions**: some C extension modules do not load.
- **macOS**: native module isolation is not available.
- **WebAssembly SIMD**: installing Python disables it; see [WebAssembly with Elide](https://elide.help/docs/wasm#limits).
- **CPython differences**: some edge cases behave differently from CPython 3.13; see the
  [Compatibility Matrix](https://elide.help/docs/compatibility).
