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**: aefa7dd8-1504-466e-afa8-fa0053ef087e
    **time**: 2024-03-05 11:22:38.343515
    **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**: 5992ed9a-8a14-46c6-9da8-afdb3644a23d
    **time**: 2024-03-05 11:22:40.051587
    **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**: 8138742b-dcef-4735-b452-8481468e12da
    **time**: 2024-03-05 11:22:40.087917
    **name**: None
    **desc**: None
    **language**: sql
    **code**:
select 1 as id
Back to top