Documentation
Getting Started with Arx
Getting Started with Arx
This guide installs the Arx compiler and compiles a small program. See the compiler CLI for inspection and output modes.
Requirements
- A supported Python interpreter
pipfor a published installation, or Mamba/Conda and Poetry for a source checkout- LLVM/Clang-compatible tools for object and executable generation
- a C++ compiler when a program activates native Apache Arrow features
Token, ASTx, and most LLVM translation workflows do not invoke the system linker. Building or running an executable does.
Install from PyPI
pip install arxlang
arx --version
The arxlang distribution installs the arx Python package and the arx
command. Its IRx dependency provides the analysis, LLVM, and native runtime
layers.
Install a development checkout
git clone https://github.com/arxlang/arx.git
cd arx
mamba env create --file conda/dev.yaml
conda activate arx
poetry install
The repository is a monorepo containing Arx, ASTx, IRx, ArxPy, ArxJIT, and the low-profile AIX experiment.
Compile a program
Create hello.x:
```
title: Hello module
summary: Compiles a small typed Arx program.
```
fn add(a: i32, b: i32) -> i32:
```
title: add
summary: Adds two values.
```
return a + b
fn main() -> i32:
```
title: main
summary: Prints one result and returns success.
```
print(add(20, 22))
return 0
Inspect the compiler stages:
arx --show-tokens hello.x
arx --show-ast hello.x
arx --show-llvm-ir hello.x
Build and run:
arx hello.x --output-file hello
./hello
# Equivalent one-step forms
arx --run hello.x
arx run hello.x
An executable normally defines main() -> i32 and returns 0 on success. A
single main(n: i32) parameter follows the native C main ABI and receives
argc.
Compile an Arrow-backed value
Arx tensors, DataFrames, and Series activate IRx's native Apache Arrow C++ runtime:
```
title: Arrow-backed collections
summary: Uses a Tensor, DataFrame, and Series.
```
fn main() -> i32:
grid: tensor[i32, 2, 2] = [[1, 2], [3, 4]]
rows: dataframe[id: i32, score: f64] = dataframe({
id: [1, 2, 3],
score: [0.5, 0.8, 1.0],
})
scores: series[f64] = rows.score
assert grid[1, 0] == 3
assert rows.nrows() == 3
assert scores[2] == 1.0
return 0
The corresponding native runtime sources and linker inputs are included only when the compilation unit uses those features.
Exchange Arrow data with Python
stdlib.arrow adds runtime-schema RecordBatches, IPC file/stream readers and
writers, and TCP clients. No new language syntax or Python serialization is
needed in the Arx producer. C++20 and the installed Arrow libraries are required
at build/link time. From a checkout, run all compiled interoperability examples:
python examples/arrow/run.py --directory .tmp/arrow-demo
See the Arrow interoperability guide for schema types, nullable values, C Data/C Stream ownership and network limitations.
Connect over TCP
Import socket from stdlib to connect to a TCP service or listen on an
explicit local address. Use with to release streams and listeners. A listener
bound with port 0 reports its assigned port through local_port().
read_bytes may return fewer bytes than requested and returns empty bytes at
EOF. send_all can send part of the data before raising an error. Read, send,
and accept timeouts raise OSError. A connection deadline covers the address
attempts after hostname resolution. The socket shim ships with Arx and uses the
platform's socket API.
Serve HTTP with a typed handler
Run the synchronous item example, then use the loopback URL it prints. The program asks the OS for an available port.
arx run examples/http-items.x
curl http://127.0.0.1:PORT/items/42
Replace PORT with the printed port. The response is {"id":42}. The router
matches GET /items/{id} and its Callable[[Request], Response] adapter
converts the path segment to i64 before calling the handler. Invalid IDs
return 400 and unmatched paths return 404.
For another application, import Request, Response, and serve from
stdlib.http. Pass an open TcpListener and a function of type
Callable[[Request], Response] to serve. The handler reads the method, path,
and query from the request and constructs a response whose text is sent as
UTF-8.
The server handles one body-free HTTP/1.1 request per connection. It limits
headers to 8 KiB and applies one deadline across all header reads. Set
header_timeout_ms to change the default of five seconds. Press Ctrl-C to stop
the example.
Next steps
- Compiler CLI
- Language syntax
- Language reference
- Projects and imports
- Compiled tests
- Apache Arrow runtime
Workflow guides
- Text files: shared references, checked UTF-8, and explicit
close. Run
examples/file-io.xin a scratch directory; it creates or truncates its output file. - Classes: identity, construction, and final-reference cleanup.
- CSV and Parquet: eager DataFrames or explicit bounded streams, exact schema checks, and safe output publication.
- Nullable collections: validity, checked arithmetic, and mutation ownership.
- Native packages: explicit external C ABI dependencies.
The complete programs above are compiled and run from this page by
packages/arx/tests/python/test_documentation.py.