> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encodebox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Register a connector, connect, build an EventFrame, and optionally define a Cohort.

Default path: **register → connect → EventFrame → (optional) Cohort → `.to_df()`**.

## Prerequisites

* Python 3.10+
* EncodeBox installed (`pixi install` or `pip install encodebox`)
* Sample database running: `pixi run db-up` (PostgreSQL on port 5433)

## Get started

<Steps>
  <Step title="Register and connect">
    Load the Sentinel mapping YAML, then open a connection bound to that connector. `db.diagnosis` / `db.medication` / … are domain tables.

    ```python theme={null}
    import encodebox as eb

    eb.register_connector("connectors/postgres_local_sentinel/connector.yml")

    db = eb.connect(
        "postgres",
        host="localhost",
        port=5433,
        database="encodebox_sample",
        username="postgres",
        password="postgres",
        connector="postgres_local_sentinel",
    )
    ```
  </Step>

  <Step title="Build an index with EventFrame">
    Find people with repeated E11\* diagnoses spaced far enough apart, and treat the first qualifying visit as their index.

    ```python theme={null}
    index = (
        db.diagnosis
        .matching("E11", code_type="10", match="starts_with")
        .occurring(at_least=2, gap_days=30)
        .with_index_date()
        .first_per_patient()
    )
    ```

    Inspect without running: `print(index.to_sql())`. Run: `index.to_df()`.
  </Step>

  <Step title="Apply study criteria with Cohort">
    Start from the index cohort, keep demographics/enrollment rules, optionally require another event definition, exclude washout events, then look at attrition.

    ```python theme={null}
    other = (
        db.diagnosis
        .matching("E10", code_type="10", match="starts_with")
        .occurring(at_least=2, gap_days=30)
        .first_per_patient()
    )

    cohort = (
        eb.Cohort("t2dm", database=db)
        .entry(index, index="first")
        .include(db.demographic.age_at_index(18, 89))
        .include(db.enrollment.covering_index(days_before=365, days_after=0))
        .include(other, window=(-365, 0))
        .exclude(db.diagnosis.matching("C", match="starts_with"), window=(-365, 0))
    )

    print(cohort.attrition())
    final = cohort.to_df()
    ```
  </Step>
</Steps>

## Shortcuts

| Shortcut                          | Meaning                                              |
| --------------------------------- | ---------------------------------------------------- |
| `db.diagnosis.matching(...)`      | Code appears (optional `window=` on include/exclude) |
| `cohort.include(frame, window=…)` | Reuse a full EventFrame as a criterion               |

## Which API?

| Goal                      | Use                |
| ------------------------- | ------------------ |
| Find events / index dates | **EventFrame**     |
| Study + attrition         | **Cohort**         |
| Odd predicates            | **Table / Column** |

Full verb and criterion guide: [Which API?](/which-api).
