# Ship it

> Package, install, and call your inferlets.

Source: https://pie-project.org/docs/program/ship  

An inferlet is a single `.py` or `.js` file, or a Rust crate compiled to WebAssembly. You can run it directly with `pie run`, or install it on a server and call it by name.

## Python and JavaScript

A script inferlet is a single file (`main.py` or `index.js`). Pie runs it inside the WebAssembly language runtime installed in `$PIE_HOME`. To list installed language runtimes or install one manually:

```bash
pie language list
pie language install pie-language-python.tar.gz
```

## Rust

A Rust inferlet is a `cdylib` crate compiled for `wasm32-wasip3`:

```rust
use inferlet::eta::prelude::*;

#[inferlet::main]
async fn main(input: String) -> Result<String, String> {
    // ...
    Ok(output)
}
```

```bash
cargo build --release --target wasm32-wasip3
pie run target/wasm32-wasip3/release/my_inferlet.wasm -- --prompt "Hi"
```

Rust inferlets produce small `.wasm` binaries with fast startup and expose the full SDK, including `session::send_to` and `inferlet::speculative`.

## Install on a server

```bash
pie inferlet install main.py
pie inferlet list
pie inferlet remove my-inferlet
```

An installed inferlet is named after its file (`main.py` and `index.js` use their parent directory's name instead). Pass `--version` to set a version tag, and `--force` to overwrite an existing inferlet of the same name and version.

## Call an inferlet

| Caller                | Command or API                                                       |
| --------------------- | -------------------------------------------------------------------- |
| Local terminal        | `pie run <name-or-file> -- --key value`                              |
| Remote terminal       | `pie-client submit --path main.py -- --key value`                    |
| Python (`pie-client`) | `PieClient`: `install_program`, `launch_process`                     |
| HTTP                  | `POST /v1/generate` (single request over REST or server-sent events) |
| WebSocket             | `GET /v1/ws` (multi-turn [sessions](https://pie-project.org/docs/program/sessions))         |
| Embedded app          | `server.connect()` on the [embedded server](https://pie-project.org/docs/serve/embed)       |

Arguments after `--` become the JSON `input` object passed to `main`: `--max-tokens 16 --verbose` arrives as `{"max_tokens": 16, "verbose": true}`.

## Outputs

`main` returns a JSON object as the final result. Text sent with `session.send()` streams to the caller as messages during execution, and binary files sent with `session.send_file()` are written to the directory specified by `pie run -o DIR`.
