by Brian Duggan
bduggan
Basic concept
-- python import this -- duckdb select st_buffer(...) as ring -- R plot(...) -- llm What latitude is the northernmost point in Belgium?
Terminology
Basic concept
-- python:location.json
import json
print(json.dumps({...})) # find lat/lon
-- duckdb:rows.csv
select st_buffer(...) as ring
-- R:plot.png
plot(...)
-- llm:response.txt
What latitude is the northernmost point in Belgium?
Cells can also have:
Share data between cells by interpolating into code
-- python:location.json
import json
print(json.dumps(..) ) # find lat/lon
-- duckdb:rows.csv
select st_buffer( st_makepoint(〈 cell("location").res<lon lat>.join(',') 〉), 1) as ring
-- R:plot.png
plot(...)
-- llm:response.txt
What latitude is the northernmost point in Belgium?
Angle brackets contain Raku expressions.
Expressions can get output or content from other cells, after the cell is executed.
Share data between cells by interpolating into code
--
my $country = 'belgium';
-- python:location.json
import json
print(json.dumps(..) ) # find lat/lon
-- duckdb:rows.csv
select st_buffer( st_makepoint(〈 cell("location").res<lon lat>.join(',') 〉), 1) as ring
-- R:plot.png
plot( ... )
-- llm:response.txt
What latitude is the northernmost point in 〈 $country.uc 〉?
You can also have Raku code outside of the cells.
Execution context is shared.
A file named belgium.samaki may contain a cell :
-- duckdb:circles.csv
SELECT
ST_BUFFER( .. ) as circle, *
FROM y
WHERE
latitude >〈 ..raku expression.. 〉
and latitude <〈 ..raku expression.. 〉
Cells are delimited by
-- type:name.extension and will be handled by
and the contents are generated by interpolating
run sam for the console UI
Use [m] to toggle betwen eval and raw mode.
Select cells to run them
Select output files to view them
All plugouts are available to view the file.
CSVGeo is a plugout reads GeoJSON, WKT, EWKB, EWKT, uses JS DataTables to view CSV content, auto detects spatial columns and has options for tiles and color schemes.
c(...).out
to
get
the
raw
output
(c
is
short
for
cell).c(0)
)
python3
uses
a
python
plugin
to
run
this
as
a
script.c('bbox').json
.
ggplot
is
called.
The ChartJS plugout is a DWIM interface to Chart.js
claude
cli
commandlines
and
and
expression
to
trim
them.d.mon
grass
command
opens
a
window.
-- python:bbox
...
-- url:data.osm
https://api.openstreetmap.org/api/0.6/map?bbox=〈c('bbox').out 〉
-- bash
ogr2ogr -f GeoJSON buildings.geojson data.osm multipolygons -where "building IS NOT NULL"
ogr2ogr -f GeoJSON roads.geojson data.osm lines -where "highway IS NOT NULL"
-- raku:style.xml
use Map::Mapnik;
my $map = Mapnik::Map.new:
background-color => '#f8f4f0', fontsets => [ ... ], styles => [ ...]
data-sources => [
... buildings.geojson ...
... roads.geojson ...
];
say $map.to-xml
-- bash
mapnik-render --xml style.xml --img out.png
open
(or
xdg-open
)
for
image
(or
other
files).Configuration file :
plugins => [ / duck / => 'Samaki::Plugin::DuckDB', / something_else / => ...plugin... ... ]
somewhere else
class Samaki::Plugin::DuckDB does Samaki::Plugin {
method execute(...) {
...
}
}
type
to
a
plugin
class.execute
method.Plugin classes can inherit from common ones.
class Samaki::Plugin::Postgres does Samaki::Plugin::Process {
has $.cmd = 'psql';
}
class Samaki::Plugin::R does Samaki::Plugin::REPL {
has $.cmd = 'R';
}
expect
).Make classes right in the config file easily:
plugins => [
/ grass / => Samaki::Plugin::Repl[cmd => 'grass'],
/ claude / => Samaki::Plugin::Process[
cmd => 'claude',
args => [ '--permission-mode','dontAsk' ],
:use-stdin,
],
with built-in Raku syntax
plugouts => [
/ html / => 'Samaki::Plugout::HTML',
/ csv / => 'Samaki::Plugout::CSVGeo',
/ csv / => 'Samaki::Plugout::DeckGLBin',
/ geojson / => 'Samaki::Plugout::Geojson',
/ .* / => 'Samaki::Plugout::Open',
...
Somewhere else
class Samaki::Plugout::Open does Samaki::Plugout {
method execute( IO::Path :$path!, ... ) {
shell <<open $path>>;
}
}
Plugouts also implement execute.
Plugin | Type | Description ========================|==========|============================================ Bash | Process | Execute contents as a bash program Code | | Evaluate raku code in the current process Duck | Process | Run SQL queries via duckdb executable Duckie | inline | Run SQL queries via L<Duckie> inline driver File | | Display file metadata and info HTML | | Generate HTML from contents LLM | inline | Send contents to LLM via LLM::DWIM Markdown | inline | Generate HTML from markdown Postgres | Process | Execute SQL via psql process Raku | Process | Run raku in a separate process Repl::Raku | Repl | Interactive raku REPL (persistent session) Repl::Python | Repl | Interactive python REPL (persistent session) Repl::R | Repl | Interactive R REPL (persistent session) Text | | Write contents to a text file
Plugout | Description ========================|============================================ ChartJS | Display CSV as interactive charts in browser (via Chart.js) CSVGeo | Display CSV that has geojson data using a map in browser (via leaflet) D3 | Display CSV as D3.js visualizations in browser DataTable | Display CSV in browser with sorting/pagination/search Duckview | Show CSV summary in bottom pane (via duckdb) Geojson | Display GeoJSON on map in browser (via leaflet) HTML | Open HTML content in browser JSON | Display prettified JSON in bottom pane Plain | Display plain text in browser Raw | Open file with system default application TJLess | View JSON in new tmux window (requires jless)
Why Raku?
In progress
--watch
)sam import
)sam export
)sam run
)Not yet implemented :
bduggan/raku-samakiThis presentation:
The end!