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 Torgersen39.118.71813750male  2007 │
│ Adelie Torgersen39.517.41863800female2007 │
│ Adelie Torgersen40.318.01953250female2007 │
│ Adelie Torgersen │           NULL │          NULL │              NULL │        NULL │ NULL   │  2007 │
│ Adelie Torgersen36.719.31933450female2007 │
│ Adelie Torgersen39.320.61903650male  2007 │
│ Adelie Torgersen38.917.81813625female2007 │
│ Adelie Torgersen39.219.61954675male  2007 │
│ Adelie Torgersen34.118.11933475 │ NULL   │  2007 │
│ Adelie Torgersen42.020.21904250 │ 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