Skip to main content

Install Codon

Markdown

Codon runs natively on Linux, macOS, and Windows x86-64. Choose the command-line tool to compile programs, or the Python package to use @codon.jit in an existing Python application.

Install the Codon CLI with:

/bin/bash -c "$(curl -fsSL https://exaloop.io/install.sh)"

Follow the prompts to add the codon command to your path.

Run your first program​

With the codon command installed, we can compile and run a simple hello-world program:

print('Hello, World!')

If we save this simple program to a file called hello.py, we can compile and run with the codon run subcommand:

codon run hello.py

This prints the Hello, World! message as expected.

Enable optimizations​

By default, codon runs programs without optimizations enabled. You can enable optimizations with the -release flag. Let's look at a slightly more involved example to see the effect of this flag:

from time import time

def fib(n):
return n if n < 2 else fib(n - 1) + fib(n - 2)

t0 = time()
ans = fib(40)
t1 = time()
print(f'Computed fib(40) = {ans} in {t1 - t0} seconds.')

This program computes the 40th Fibonacci number using simple recursion. We can run the program with optimizations enabled like this:

codon run -release fib.py

The following measurements illustrate the difference between Python, Codon debug mode and Codon release mode on an M1 MacBook Pro1:

CommandTime taken (sec.)Speedup
python3.13 fib.py14.261×\times
codon run fib.py0.4333×\times
codon run -release fib.py0.3146×\times

These are elapsed times reported by the program around fib(40), not the total time spent compiling and launching it. The example illustrates native execution and the release flag, rather than an efficient Fibonacci algorithm; an iterative or memoized implementation would be more suitable when the goal is simply to calculate the result. Performance on other workloads and machines will differ.

The usage guide explains how to separate compilation from execution when measuring an application. From here, functions and generators provide a practical introduction to writing native code, while Python interoperability shows how to use Codon within an existing Python project.

Footnotes​

  1. Times were measured on an M1 MacBook Pro. ↩