# Quickstart

> Write a contract for a small CSV file, run Floe on it, and read the three outputs: accepted rows, rejected rows with their reasons, and the run report. It…

Source: https://openlakeforge.dev/floe/get-started/quickstart/

Write a contract for a small CSV file, run Floe on it, and read the three
outputs: accepted rows, rejected rows with their reasons, and the run report.
It takes about five minutes and needs only Python 3.11 or later.

## 1. Install Floe

```bash
python -m venv .venv
. .venv/bin/activate
pip install floe-python
floe --version
```

[Installation](https://openlakeforge.dev/floe/get-started/installation/) covers uv, Docker and the optional extras for
S3, Iceberg and Excel.

## 2. Add a raw file

Create `in/orders.csv`. Three of its five rows are wrong: an amount that is not
a number, an order id seen twice, and a missing order id.

```text
order_id,amount
1001,19.90
1002,not_a_number
1003,42.00
1003,7.50
,5.00
```

## 3. Write the contract

Create `floe.yml` next to the `in` folder:

```yaml
version: "1.0"
entities:
  - name: orders
    source:
      format: csv
      path: ./in
      options:
        separator: ","     # Floe reads ";" unless told otherwise
    sink:
      accepted:
        format: parquet
        path: ./out/accepted/orders
      rejected:
        format: csv
        path: ./out/rejected/orders
    policy:
      severity: reject     # reject the bad rows, keep the good ones
    schema:
      unique_keys: [[order_id]]   # no duplicates
      columns:
        - name: order_id
          type: string
          nullable: false   # required
        - name: amount
          type: "decimal(10,2)"
```

The contract says: read every CSV file in `./in` as the `orders` entity; each
row must have an `order_id` that is present and unique, and an `amount` that is
a decimal with two digits after the point. Rows that pass go to Parquet, rows
that fail go to a CSV quarantine.

## 4. Validate the contract

```bash
floe validate -c floe.yml
```

```text
Config valid: /path/to/quickstart/floe.yml
Version: 1.0
Report: report
Entities: 1
Entity: orders
  Source: csv (./in)
  Sink accepted: parquet (./out/accepted/orders)
  Sink rejected: csv (./out/rejected/orders)
  Severity: reject
Next: floe run -c /path/to/quickstart/floe.yml
```

Floe prints the absolute path to your config. `floe validate` reads no data.
Run it in CI on every change to a contract.

## 5. Run it

```bash
floe run -c floe.yml
```

The run summarizes the files and rows processed.

```text
Totals: files=1 rows=5 accepted=2 rejected=3
Overall: rejected (exit_code=0)
```

Two rows were accepted and three rejected. A run with rejected rows still
exits `0`: rejecting rows is the contract working, not a failure.

## 6. Read the results

**Accepted rows** are a Parquet dataset, typed as the contract declares:

```bash
python -c "import polars as pl; print(pl.read_parquet('out/accepted/orders'))"
```

```text
shape: (2, 2)
┌──────────┬───────────────┐
│ order_id ┆ amount        │
│ ---      ┆ ---           │
│ str      ┆ decimal[10,2] │
╞══════════╪═══════════════╡
│ 1001     ┆ 19.90         │
│ 1003     ┆ 42.00         │
└──────────┴───────────────┘
```

**Rejected rows** keep their raw values, row position, rule failures, run ID and
source URI. Read the generated part file to inspect them.

```bash
cat out/rejected/orders/part-*.csv
```

```text
order_id,amount,__floe_row_index,__floe_errors,__floe_run_id,__floe_source_uri
1002,not_a_number,1,"[{""rule"":""cast_error"",""column"":""amount"",""message"":""invalid value for target type""}]",<run_id>,local:///path/to/quickstart/in/orders.csv
1003,7.50,3,"[{""rule"":""unique"",""column"":""order_id"",""message"":""duplicate value""}]",<run_id>,local:///path/to/quickstart/in/orders.csv
,5.00,4,"[{""rule"":""not_null"",""column"":""order_id"",""message"":""required value missing""}]",<run_id>,local:///path/to/quickstart/in/orders.csv
```

The first `1003` was accepted; the second is the duplicate.

**The run report** is JSON under `report/run_<run_id>/`: a
`run.summary.json` for the run and one `run.json` per entity, with counts,
statuses, timings and the files written.

```text
report/run_<run_id>/run.summary.json
report/run_<run_id>/orders/run.json
```

[Run report](https://openlakeforge.dev/floe/reference/report/) documents every key.

## 7. Try another severity

Change `severity: reject` to `warn` and run again: all five rows are accepted
(the bad amount becomes null), and the run ends `success_with_warnings`. Change
it to `abort`: the whole file is rejected, nothing is accepted, and the run
exits `2`, which an orchestrator treats as a failure. The severity is how a
contract says how strict to be; [Checks and severity](https://openlakeforge.dev/floe/concepts/checks/)
gives the full rules.

## Next

- [Data contracts](https://openlakeforge.dev/floe/concepts/data-contracts/): every part of a contract,
  and how to design one.
- [Config reference](https://openlakeforge.dev/floe/reference/config/): every field.
- [`example/`](https://github.com/OpenLakeForge/floe/tree/v1.1.0/example/): a larger project with several entities,
  profiles and S3.

---

<small>Synced from floe @ `v1.1.0` (`313b534`), [docs/get-started/quickstart.md](https://github.com/OpenLakeForge/floe/blob/313b53441b3b088290403ed1adb2f3894833b6c5/docs/get-started/quickstart.md).</small>
