All Projects → babashka → Babashka

babashka / Babashka

Licence: epl-1.0
Native, fast starting Clojure interpreter for scripting

Programming Languages

clojure
4091 projects
shell
77523 projects
Batchfile
5799 projects
HTML
75241 projects
BlitzBasic
18 projects
Dockerfile
14818 projects
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Babashka

holy-lambda
The extraordinary simple, performant, and extensible custom AWS Lambda runtime for Clojure.
Stars: ✭ 318 (-87.08%)
Mutual labels:  graalvm, babashka
Enso
Hybrid visual and textual functional programming.
Stars: ✭ 5,238 (+112.75%)
Mutual labels:  graalvm
BashConfig
BASH configuration files.
Stars: ✭ 46 (-98.13%)
Mutual labels:  shell-scripting
ubuntu-2004
🔵 Curso GRÁTIS de GNU/Linux Ubuntu Server 20.04.x LTS - DevOps utilizando Shell Script
Stars: ✭ 70 (-97.16%)
Mutual labels:  shell-scripting
http4s-graal
An experiment running http4s as native image with Graal (+ Substrate)
Stars: ✭ 27 (-98.9%)
Mutual labels:  graalvm
smoosh
The Symbolic, Mechanized, Observable, Operational SHell: an executable formalization of the POSIX shell standard.
Stars: ✭ 86 (-96.51%)
Mutual labels:  shell-scripting
ScriptableMC-Engine
Create TypeScript/JavaScript plugins for Minecraft 1.16 Bukkit/Spigot/Paper
Stars: ✭ 36 (-98.54%)
Mutual labels:  graalvm
Spring Native
Spring Native provides beta support for compiling Spring applications to native executables using GraalVM native-image compiler.
Stars: ✭ 2,282 (-7.31%)
Mutual labels:  graalvm
Picocli
Picocli is a modern framework for building powerful, user-friendly, GraalVM-enabled command line apps with ease. It supports colors, autocompletion, subcommands, and more. In 1 source file so apps can include as source & avoid adding a dependency. Written in Java, usable from Groovy, Kotlin, Scala, etc.
Stars: ✭ 3,286 (+33.47%)
Mutual labels:  graalvm
furipota
(unmaintained) A discrete FRP DSL for describing better build pipelines.
Stars: ✭ 22 (-99.11%)
Mutual labels:  shell-scripting
HackerRank-LinuxShell
HackerRank-LinuxShell Solutions 💻
Stars: ✭ 26 (-98.94%)
Mutual labels:  shell-scripting
datatools
A set of tools for working with JSON, CSV and Excel workbooks
Stars: ✭ 68 (-97.24%)
Mutual labels:  shell-scripting
kotlin-graalvm-custom-runtime-demo
Demo for a AWS Lambda functions written in Kotlin using GraalVM and custom runtimes
Stars: ✭ 23 (-99.07%)
Mutual labels:  graalvm
lucene-grep
Grep-like utility based on Lucene Monitor compiled with GraalVM native-image
Stars: ✭ 160 (-93.5%)
Mutual labels:  graalvm
Okhttp
Square’s meticulous HTTP client for the JVM, Android, and GraalVM.
Stars: ✭ 41,306 (+1577.74%)
Mutual labels:  graalvm
azure-native-spring-function
Tutorial on running Spring Boot + GraalVM native images on Azure Functions
Stars: ✭ 56 (-97.73%)
Mutual labels:  graalvm
spring-cloud-stream-event-sourcing-testcontainers
Goal: create a Spring Boot application that handles users using Event Sourcing. So, whenever a user is created, updated, or deleted, an event informing this change is sent to Kafka. Also, we will implement another application that listens to those events and saves them in Cassandra. Finally, we will use Testcontainers for integration testing.
Stars: ✭ 16 (-99.35%)
Mutual labels:  graalvm
ipolyglot
A polyglot kernel for Jupyter notebooks based on GraalVM.
Stars: ✭ 59 (-97.6%)
Mutual labels:  graalvm
Script
Making it easy to write shell-like scripts in Go
Stars: ✭ 1,946 (-20.96%)
Mutual labels:  shell-scripting
Spring Fu
KoFu and JaFu configuration DSLs for Spring Boot
Stars: ✭ 1,567 (-36.35%)
Mutual labels:  graalvm

CircleCI project chat Financial Contributors on Open Collective Clojars Project twitter docs

Life's too short to remember how to write Bash code. I feel liberated.

@laheadle on Clojurians Slack

Introduction

Babashka is a native Clojure interpreter for scripting with fast startup. Its main goal is to leverage Clojure in places where you would be using bash otherwise.

As one user described it:

I’m quite at home in Bash most of the time, but there’s a substantial grey area of things that are too complicated to be simple in bash, but too simple to be worth writing a clj/s script for. Babashka really seems to hit the sweet spot for those cases.

Goals

  • Fast starting Clojure scripting alternative for JVM Clojure
  • Easy installation: grab the self-contained binary and run. No JVM needed.
  • Familiar: targeted at JVM Clojure users
  • Cross-platform: supports linux, macOS and Windows
  • Interop with commonly used classes (System, File, java.time.*, java.nio.*)
  • Multi-threading support (pmap, future)
  • Batteries included (tools.cli, cheshire, ...)

Non-goals

  • Provide a mixed Clojure/Bash DSL (see portability).
  • Replace existing shells. Babashka is a tool you can use inside existing shells like bash and it is designed to play well with them. It does not aim to replace them.

Quickstart

For installation options check Installation. For quick installation use:

$ bash < <(curl -s https://raw.githubusercontent.com/babashka/babashka/master/install)

or grab a binary from Github releases yourself and place it anywhere on the path.

Then you're ready to go:

$ ls | bb -i '(filter #(-> % io/file .isDirectory) *input*)'
("doc" "resources" "sci" "script" "src" "target" "test")
bb took 4ms.

Babashka users

See companies for a list of companies using babashka.

Are you using babashka in your company or personal projects? Let us know here.

Setting expectations

Babashka uses SCI for interpreting Clojure. SCI implements a substantial subset of Clojure. Interpreting code is in general not as performant as executing compiled code. If your script takes more than a few seconds to run or has lots of loops, Clojure on the JVM may be a better fit as the performance on JVM is going to outweigh its startup time penalty. Read more about the differences with Clojure here.

Status

Functionality regarding clojure.core and java.lang can be considered stable and is unlikely to change. Changes may happen in other parts of babashka, although we will try our best to prevent them. Always check the release notes or CHANGELOG.md before upgrading.

Talk

To get an overview of babashka, you can watch this talk (slides):

Babashka at ClojureD 2020

Babashka book

The babashka book contains detailed information about how to get the most out of babashka scripting.

Examples

Read the output from a shell command as a lazy seq of strings:

$ ls | bb -i '(take 2 *input*)'
("CHANGES.md" "Dockerfile")

Read EDN from stdin and write the result to stdout:

$ bb '(vec (dedupe *input*))' <<< '[1 1 1 1 2]'
[1 2]

Read more about input and output flags here.

Execute a script. E.g. print the current time in California using the java.time API:

File pst.clj:

#!/usr/bin/env bb

(def now (java.time.ZonedDateTime/now))
(def LA-timezone (java.time.ZoneId/of "America/Los_Angeles"))
(def LA-time (.withZoneSameInstant now LA-timezone))
(def pattern (java.time.format.DateTimeFormatter/ofPattern "HH:mm"))
(println (.format LA-time pattern))
$ pst.clj
05:17

More examples can be found here.

Try online

You can try babashka online with Nextjournal's babashka notebook environment.

Installation

Brew

Linux and macOS binaries are provided via brew.

Install:

brew install borkdude/brew/babashka

Upgrade:

brew upgrade babashka

Arch (Linux)

babashka is available in the Arch User Repository. It can be installed using your favorite AUR helper such as yay, yaourt, apacman and pacaur. Here is an example using yay:

yay -S babashka-bin

asdf

asdf is an extendable version manager for linux and macOS.

Babashka can be installed using a plugin as follows:

asdf plugin add babashka
asdf install babashka latest

Windows

On Windows you can install using scoop and the scoop-clojure bucket.

Or just follow these concrete steps:

# Note: if you get an error you might need to change the execution policy (i.e. enable Powershell) with
# Set-ExecutionPolicy RemoteSigned -scope CurrentUser
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')

scoop bucket add scoop-clojure https://github.com/littleli/scoop-clojure
scoop bucket add extras
scoop install babashka

Installer script

Install via the installer script:

$ curl -sLO https://raw.githubusercontent.com/babashka/babashka/master/install
$ chmod +x install
$ ./install

By default this will install into /usr/local/bin (you may need sudo for this). To change this, provide the directory name:

$ ./install --dir .

To install a specific version, the script also supports --version:

$ ./install --dir . --version 0.4.1

To force the download of the zip archive to a different directory than /tmp use the --download-dir argument:

$ ./install --dir . --version 0.4.1 --download-dir .

On Linux, if you want to install the static binary version:

$ ./install --dir . --version 0.4.1 --download-dir . --static

In case you want to check the download, you can use the --checksum option. This maybe useful for unattended installations:

$ sha256sum babashka-0.4.1-linux-amd64-static.tar.gz
ab70fb39fdbb5206c0a2faab178ffb54dd9597991a4bc13c65df2564e8f174f6  babashka-0.4.1-linux-amd64-static.tar.g
$ ./install --dir /tmp --checksum ab70fb39fdbb5206c0a2faab178ffb54dd9597991a4bc13c65df2564e8f174f6 --static --version 0.4.1

Note that the --checksum option only works when --version option is also provided. This is to avoid breakage when a new version of Babashka is released.

Github releases

You may also download a binary from Github. For linux there is a static binary available which can be used on Alpine.

Docker

Check out the image on Docker hub.

News

Check out the news page to keep track of babashka-related news items.

Built-in namespaces

Go here to see the full list of built-in namespaces.

Projects

A list of projects (scripts, libraries, pods and tools) known to work with babashka.

Pods

Pods are programs that can be used as a Clojure library by babashka. Documentation is available in the pod library repo.

A list of available pods can be found here.

Differences with Clojure

Babashka is implemented using the Small Clojure Interpreter. This means that a snippet or script is not compiled to JVM bytecode, but executed form by form by a runtime which implements a substantial subset of Clojure. Babashka is compiled to a native binary using GraalVM. It comes with a selection of built-in namespaces and functions from Clojure and other useful libraries. The data types (numbers, strings, persistent collections) are the same. Multi-threading is supported (pmap, future).

Differences with Clojure:

  • A pre-selected set of Java classes are supported. You cannot add Java classes at runtime.

  • Interpretation comes with overhead. Therefore loops are slower than in Clojure on the JVM. In general interpretation yields slower programs than compiled programs.

  • No deftype, definterface and unboxed math.

  • defprotocol and defrecord are implemented using multimethods and regular maps. Ostensibly they work the same, but under the hood there are no Java classes that correspond to them.

  • Currently reify works only for one class at a time

  • The clojure.core.async/go macro is not (yet) supported. For compatibility it currently maps to clojure.core.async/thread. More info here.

Package babashka script as a AWS Lambda

AWS Lambda runtime doesn't support signals, therefore babashka has to disable handling of SIGINT and SIGPIPE. This can be done by setting BABASHKA_DISABLE_SIGNAL_HANDLERS to true.

Articles, podcasts and videos

Building babashka

Developing Babashka

Including new libraries or classes

Before new libraries or classes go into the standardly distributed babashka binary, these evaluation criteria are considered:

  • The library or class is useful for general purpose scripting.
  • Adding the library or class would make babashka more compatible with Clojure libraries relevant to scripting.
  • The library cannot be interpreted by with babashka using --classpath.
  • The functionality can't be met by shelling out to another CLI or can't be written as a small layer over an existing CLI (like babashka.curl) instead.
  • The library cannot be implemented a pod.

If not all of the criteria are met, but adding a feature is still useful to a particular company or niche, adding it behind a feature flag is still a possibility. This is currently the case for next.jdbc and the PostgresQL and HSQLDB database drivers. Companies interested in these features can compile an instance of babashka for their internal use. Companies are also free to make forks of babashka and include their own internal libraries. If their customized babashka is interesting to share with the world, they are free to distribute it using a different binary name (like bb-sql, bb-docker, bb-yourcompany, etc.). See the feature flag documentation and the implementation of the existing feature flags (example commit).

Related projects

Contributors

Thanks to all the people that contributed to babashka:

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Github Sponsors

OpenCollective

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

Copyright © 2019-2020 Michiel Borkent

Distributed under the EPL License. See LICENSE.

This project contains code from:

  • Clojure, which is licensed under the same EPL License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].