Skip to content

Python with Elide

Add Python to Elide, run a Python 3.13 program with the standard library, and test it with unittest; then add packages or JavaScript interop.

On this page

Python support is experimental. This quickstart runs a program using the bundled standard library, then tests it with unittest. No third-party packages are needed.

No CPython install

Elide runs Python 3.13 and its standard library itself.

Install

Install Elide using a method that supports Python, then add the Python component if it is not already included:

Terminal
bash
elide setup python
elide info

elide info should list python on its Languages: line. If the shell cannot find elide, follow Verify the install. If Python support is missing, see Python is not installed.

elide setup python --channel=release or --channel=nightly picks the channel; --force reinstalls the component.

Run Python

Create a directory for this example:

Terminal
bash
mkdir hello-python
cd hello-python

Save this as greeting.py:

python
import json


def greeting(name: str) -> str:
    return f"Hello, {name}!"


if __name__ == "__main__":
    print(json.dumps({"message": greeting("Ada")}))
utf-8 · python · Lines: 9
Terminal
bash
elide python greeting.py
{"message": "Hello, Ada!"}

The json import uses the standard library included with the Python component.

Tests

Create test_greeting.py in the same directory:

python
import unittest

from greeting import greeting


class GreetingTest(unittest.TestCase):
    def test_names_the_caller(self):
        self.assertEqual(greeting("Ada"), "Hello, Ada!")
utf-8 · python · Lines: 8

Run unittest as a module:

Terminal
bash
elide python -m unittest -v test_greeting

The runner should report one test and OK. If it cannot import greeting or test_greeting, check the filenames and run the command from hello-python.

elide test does not discover Python tests. For discovery across several files or pytest, see Python tests.

Next steps

Command-line arguments

elide python takes Python interpreter arguments before the script or module. For an existing app.py:

Terminal
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 -

Tokens after the script, -c CMD, or -m MODULE go to the program. Bare elide python starts the REPL in a terminal and reads standard input otherwise.

Running a Python program with command-line arguments in Elide
 ~/demo  bat hello.py
───────┬────────────────────────────────────────────────────────────────────────────────────────────
       │ File: hello.py
       │ Size: 95 B
───────┼────────────────────────────────────────────────────────────────────────────────────────────
   1   │ import json
   2   │ import sys
   3   │ 
   4   │ print(json.dumps({"name": sys.argv[1], "runtime": "Elide"}, indent=2))
───────┴────────────────────────────────────────────────────────────────────────────────────────────
 ~/demo  elide python hello.py Ada
{
  "name": "Ada",
  "runtime": "Elide"
}
 

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

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

Interpreter options

Put these before the script, -c, or -m. elide --help-all lists them under “Python interpreter options”.

FlagEffect
-c CMDRun CMD as the program; trailing tokens become sys.argv[1:].
-m MODULERun a library module as __main__.
-sDon’t add the user site directory to sys.path.
-IIsolated mode.
-EIgnore PYTHON* environment variables.
-SDon’t import site on startup.
-PDon’t prepend a potentially unsafe path to sys.path.
-BDon’t write bytecode files.
-uUnbuffered standard output and error.
-OOptimization level; repeat for -OO.
-bWarn on bytes/str comparisons; repeat to raise errors.
-W ARGWarning control; repeatable.
-xAccepted for compatibility; no effect.

Two flags are on by default: -S, because Elide builds sys.path itself and skips site for startup time, and -B. sys.flags reports both. To import site (.pth files, sitecustomize), pass -X polyglot.python.NoSiteFlag=false; to write bytecode, pass -X polyglot.python.DontWriteBytecodeFlag=false.

Standard library

The standard library includes json, pathlib, sqlite3, ssl, zlib, and ctypes. bz2 and lzma need no system libbz2 or liblzma. For the database drivers Elide includes, see Databases.

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)"))
utf-8 · python · Lines: 4
Terminal
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());
utf-8 · javascript · Lines: 3
Terminal
bash
elide --interop run main.mjs

Without --interop, these calls fail. See Languages and Interop.

Third-party packages

Package installation requires pytools, the optional package tooling installed with the Python component. Use elide uv install PACKAGE, or elide install --ecosystems=pypi for declared dependencies. Plain elide install retains its Maven default.

Packages installed through Elide use the project’s automatic environment. A compatible Python 3.13 external virtual environment can also supply packages through VIRTUAL_ENV.

Only compatible wheels can be installed; source builds and arbitrary CPython native wheels are not supported. See Packages and virtual environments for setup, commands and limitations.

Tracing and metrics

The opentelemetry API and logging export traces, metrics, and logs through Elide, with no SDK installed; see OpenTelemetry in Python.

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.
  • CPython differences: some edge cases behave differently from CPython 3.13; see the Compatibility Matrix.

Samples

Was this page helpful?