Ibis Birdbrain

# Attachments

Ibis Birdbrain passes Python objects as `Attachments` to `Messages`. This allows the user, itself, and (eventually) other bots to interact with data, code, and more.

## Usage

    from ibis_birdbrain.attachments import Attachment, Attachments

    a1 = Attachment(content="Hello, world!")
    a1

    Attachment
        **guid**: 80dffb16-2493-49cd-ba74-819512179b32
        **time**: 2024-03-05 09:07:29.230828
        **name**: None
        **desc**: None

## TableAttachment

A `TableAttachment` contains an Ibis table:

    import ibis

    from ibis_birdbrain.attachments import TableAttachment

    ibis.options.interactive = True

    t = ibis.examples.penguins.fetch()

    a2 = TableAttachment(content=t)
    a2

    INFO:pins.cache:cache file: /Users/cody/Library/Caches/pins-py/gcs_332a30997e141da0e08f15fbfae8b3c3ec90463922d117a96fa3b1bef85a2a4c/penguins/20230905T090411Z-9aae2/data.txt
    INFO:pins.cache:cache file: /Users/cody/Library/Caches/pins-py/gcs_332a30997e141da0e08f15fbfae8b3c3ec90463922d117a96fa3b1bef85a2a4c/penguins/20230905T090411Z-9aae2/penguins.csv.gz

    TableAttachment
        **guid**: 95374920-3a86-4287-86dd-7e33e2410091
        **time**: 2024-03-05 09:07:29.724794
        **name**: penguins
        **desc**:
    ibis.Schema {
      species            string
      island             string
      bill_length_mm     float64
      bill_depth_mm      float64
      flipper_length_mm  int64
      body_mass_g        int64
      sex                string
      year               int64
    }
                    **table**:
    ┏━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━┓
    ┃ species ┃ island    ┃ bill_length_mm ┃ bill_depth_mm ┃ flipper_length_mm ┃ body_mass_g ┃ sex    ┃ year  ┃
    ┡━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━┩
    │ string  │ string    │ float64        │ float64       │ int64             │ int64       │ string │ int64 │
    ├─────────┼───────────┼────────────────┼───────────────┼───────────────────┼─────────────┼────────┼───────┤
    │ Adelie  │ Torgersen │           39.1 │          18.7 │               181 │        3750 │ male   │  2007 │
    │ Adelie  │ Torgersen │           39.5 │          17.4 │               186 │        3800 │ female │  2007 │
    │ Adelie  │ Torgersen │           40.3 │          18.0 │               195 │        3250 │ female │  2007 │
    │ Adelie  │ Torgersen │           NULL │          NULL │              NULL │        NULL │ NULL   │  2007 │
    │ Adelie  │ Torgersen │           36.7 │          19.3 │               193 │        3450 │ female │  2007 │
    │ Adelie  │ Torgersen │           39.3 │          20.6 │               190 │        3650 │ male   │  2007 │
    │ Adelie  │ Torgersen │           38.9 │          17.8 │               181 │        3625 │ female │  2007 │
    │ Adelie  │ Torgersen │           39.2 │          19.6 │               195 │        4675 │ male   │  2007 │
    │ Adelie  │ Torgersen │           34.1 │          18.1 │               193 │        3475 │ NULL   │  2007 │
    │ Adelie  │ Torgersen │           42.0 │          20.2 │               190 │        4250 │ NULL   │  2007 │
    │ …       │ …         │              … │             … │                 … │           … │ …      │     … │
    └─────────┴───────────┴────────────────┴───────────────┴───────────────────┴─────────────┴────────┴───────┘

Notice the name, description (schema), and preview are automatically populated.

## CodeAttachment

A `CodeAttachment` contains code – typically Python or SQL:

    from ibis_birdbrain.attachments import CodeAttachment

    a3 = CodeAttachment(content="select 1 as id", language="sql")
    a3

    CodeAttachment
        **guid**: 155834a3-a1c1-4b93-9f71-fea15100e9c1
        **time**: 2024-03-05 09:07:29.756722
        **name**: None
        **desc**: None
        **language**: sql
        **code**:
    select 1 as id

Back to top