2021-10-19 04:32:09 +08:00
< h1 > < img src = "https://github.com/livebook-dev/livebook/raw/main/static/images/logo-with-text.png" alt = "Livebook" width = "400" > < / h1 >
2021-01-08 03:55:45 +08:00
2021-12-30 05:06:19 +08:00
[![Hex.pm ](https://img.shields.io/hexpm/v/livebook?color=3e64ff )](https://hex.pm/packages/livebook)
2021-08-28 23:44:36 +08:00
2021-07-15 17:19:59 +08:00
Livebook is a web application for writing interactive and collaborative code notebooks for Elixir, built with [Phoenix LiveView ](https://github.com/phoenixframework/phoenix_live_view ). It features:
2021-01-08 03:55:45 +08:00
2021-06-18 05:32:36 +08:00
* Code notebooks with Markdown support and Elixir cells where code is evaluated on demand.
2021-01-08 03:55:45 +08:00
2022-01-20 17:07:27 +08:00
* Shareable: notebooks are stored in the `.livemd` format, which is a subset of Markdown with support for diagrams via [Mermaid ](https://mermaid-js.github.io/mermaid ) and for mathematical formulas via [KaTex ](https://katex.org/ ). `.livemd` files can be easily shared and play well with version control.
2021-01-08 03:55:45 +08:00
2021-08-25 17:57:18 +08:00
* Interactive widgets via [Kino ](https://github.com/elixir-nx/kino ): manipulate [Vega-Lite charts ](https://vega.github.io/vega-lite/ ), tables, and more.
2021-06-18 05:32:36 +08:00
2021-07-15 17:23:22 +08:00
* Rich code editor through [Monaco ](https://microsoft.github.io/monaco-editor/ ): with support for autocompletion, inline documentation, code formatting, etc.
2021-01-08 03:55:45 +08:00
2021-08-25 17:57:18 +08:00
* Reproducible: Livebook ensures your code runs in a predictable order, all the way down to package management. It also tracks your notebook state, annotating which parts are stale.
2021-07-15 17:23:22 +08:00
2021-08-25 17:57:18 +08:00
* Persistence: persist your notebooks to disk or any S3-compatible cloud storage.
2021-07-15 17:23:22 +08:00
* Collaboration: multiple users can work on the same notebook at once. It works out-of-the-box either in single-node or multi-node deployments - without a need for additional tooling.
2021-04-05 22:46:17 +08:00
2021-10-21 14:02:16 +08:00
* Decentralized: Livebook is open-source and you can run it anywhere. The ["Run in Livebook" badges ](https://livebook.dev/badge ) makes it easy to import any Livebook into your preferred Livebook instance.
* Custom runtimes: when executing Elixir code, you can either start a fresh Elixir instance, connect to an existing node, or run it inside an existing Elixir project, with access to all of its modules and dependencies. This means Livebook can be a great tool to introspect and document existing projects too.
2021-06-18 05:32:36 +08:00
We are actively working on Livebook and you can consult the issues tracker to see some of the features we are exploring. We also want to thank [Jupyter ](https://jupyter.org/ ) and [Deepnote ](https://deepnote.com/ ) for inspiring some of our features.
## Getting started
Livebook comes with a series of introductory notebooks to get you up and running. Just head down to the "Usage" section below to install it. Here is a peek at the "Welcome to Livebook" introductory notebook:
2021-04-05 22:46:17 +08:00
2021-08-18 21:55:07 +08:00
![Screenshot ](https://github.com/livebook-dev/livebook/raw/main/.github/imgs/welcome.png )
2021-04-05 22:46:17 +08:00
2021-06-18 05:32:36 +08:00
From time to time, we also publish some videos for new Livebook releases:
* [Livebook's initial announcement by José Valim ](https://www.youtube.com/watch?v=RKvqc-UEe34 ), also featuring [Nx ](https://github.com/elixir-nx/nx ) and [Axon ](https://github.com/elixir-nx/axon )
2021-10-21 13:57:10 +08:00
* [New in Livebook v0.2 by José Valim ](https://www.youtube.com/watch?v=MOTEgF-wIEI ), exploring inputs, charts of mathematical formulas, and live display of runtime metrics
2021-04-05 22:46:17 +08:00
## Usage
2021-04-27 22:34:02 +08:00
We provide several distinct methods of running Livebook,
pick the one that best fits your use case.
2021-10-19 19:30:23 +08:00
### Running on the cloud
* [Launch a Livebook instance close to you on Fly.io ](https://fly.io/launch/livebook )
2021-09-10 16:36:25 +08:00
### Running locally
You can run Livebook on your own machine. You will need
2021-12-08 15:08:23 +08:00
[Elixir v1.13 ](https://elixir-lang.org/install.html ) or later.
2021-06-24 13:27:58 +08:00
Livebook also requires the following Erlang applications: `inets` ,
2021-11-12 19:39:58 +08:00
`os_mon` , `runtime_tools` , `ssl` and `xmerl` . Those applications come
with most Erlang distributions but certain package managers may split
2021-06-24 13:27:58 +08:00
them apart. For example, on Ubuntu, these Erlang applications could
be installed as follows:
```shell
2021-11-12 19:39:58 +08:00
sudo apt install erlang-inets erlang-os-mon erlang-runtime-tools erlang-ssl erlang-xmerl erlang-dev erlang-parsetools
2021-06-24 13:27:58 +08:00
```
2021-04-05 22:46:17 +08:00
2021-09-10 16:36:25 +08:00
#### Escript
2021-04-27 22:34:02 +08:00
Running Livebook using Escript makes for a very convenient option
for local usage and provides easy configuration via CLI options.
```shell
2021-10-17 01:54:10 +08:00
mix escript.install hex livebook
2021-04-27 22:34:02 +08:00
# Start the Livebook server
2021-05-20 05:30:53 +08:00
livebook server
2021-04-27 22:34:02 +08:00
# See all the configuration options
2021-05-20 05:30:53 +08:00
livebook server --help
2021-04-27 22:34:02 +08:00
```
2021-05-20 05:30:53 +08:00
After you install the escript, make sure you add the directory where
Elixir keeps escripts to your [$PATH ](https://en.wikipedia.org/wiki/PATH_(variable )).
2021-05-20 18:27:30 +08:00
If you installed Elixir with `asdf` , you'll need to run `asdf reshim elixir`
once the escript is built.
2021-05-20 05:30:53 +08:00
2021-06-25 00:02:24 +08:00
To try out features from the main branch you can alternatively
install the escript directly from GitHub like this:
```shell
2021-08-18 21:55:07 +08:00
mix escript.install github livebook-dev/livebook
2021-06-25 00:02:24 +08:00
```
2021-09-10 16:36:25 +08:00
#### Docker
2021-04-27 22:34:02 +08:00
Running Livebook using Docker is a great option for cloud deployments
and also for local usage in case you don't have Elixir installed.
```shell
# Running with the default configuration
2021-07-05 06:33:29 +08:00
docker run -p 8080:8080 --pull always livebook/livebook
2021-04-27 22:34:02 +08:00
# In order to access and save notebooks directly to your machine
# you can mount a local directory into the container.
# Make sure to specify the user with "-u $(id -u):$(id -g)"
# so that the created files have proper permissions
2021-08-29 04:44:54 +08:00
docker run -p 8080:8080 --pull always -u $(id -u):$(id -g) -v $(pwd):/data livebook/livebook
2021-04-27 22:34:02 +08:00
# You can configure Livebook using environment variables,
# for all options see the dedicated "Environment variables" section below
2021-07-05 06:33:29 +08:00
docker run -p 8080:8080 --pull always -e LIVEBOOK_PASSWORD="securesecret" livebook/livebook
2021-04-27 22:34:02 +08:00
```
2021-04-05 22:46:17 +08:00
2021-06-25 00:02:24 +08:00
To try out features from the main branch you can alternatively
use the `livebook/livebook:edge` image.
See [Livebook on Docker Hub ](https://hub.docker.com/r/livebook/livebook/tags?page=1&ordering=last_updated ).
2021-09-10 16:36:25 +08:00
#### Mix
2021-05-20 05:30:53 +08:00
You can run latest Livebook directly with Mix.
```shell
2021-08-18 21:55:07 +08:00
git clone https://github.com/livebook-dev/livebook.git
2021-05-20 05:30:53 +08:00
cd livebook
mix deps.get --only prod
# Run the Livebook server
MIX_ENV=prod mix phx.server
```
2021-09-21 19:47:45 +08:00
### Embedded devices
2021-04-14 03:37:04 +08:00
2021-09-21 19:47:45 +08:00
If you want to run Livebook on embedded devices, such as Raspberry Pi, BeagleBone, etc.,
check out [our Livebook firmware ](https://github.com/livebook-dev/nerves_livebook ) built
with [Nerves ](https://www.nerves-project.org/ ).
2021-04-14 03:37:04 +08:00
2021-09-21 19:47:45 +08:00
## Security considerations
2021-04-14 03:37:04 +08:00
2021-09-21 19:47:45 +08:00
Livebook is built to document and execute code. Anyone with access to a Livebook instance
will be able to access any file and execute any code in the machine Livebook is running.
For this reason, Livebook only binds to the 127.0.0.1, allowing access to happen only within
the current machine. When running Livebook in the production environment - the recommended
environment - we also generate a token on initialization and we only allow access to the
Livebook if said token is supplied as part of the URL.
## Environment variables
2021-04-15 21:50:29 +08:00
<!-- Environment variables -->
The following environment variables configure Livebook:
2021-12-04 23:29:14 +08:00
* LIVEBOOK_AUTOSAVE_PATH - sets the directory where notebooks with no file are
saved. Defaults to livebook/notebooks/ under the default user cache location.
You can pass "none" to disable this behaviour.
2021-04-27 22:34:02 +08:00
* LIVEBOOK_COOKIE - sets the cookie for running Livebook in a cluster.
Defaults to a random string that is generated on boot.
2021-06-25 00:03:00 +08:00
* LIVEBOOK_DEFAULT_RUNTIME - sets the runtime type that is used by default
when none is started explicitly for the given notebook. Must be either
"standalone" (Elixir standalone), "mix[:PATH]" (Mix standalone),
2021-07-12 23:05:28 +08:00
"attached:NODE:COOKIE" (Attached node) or "embedded" (Embedded).
2021-06-25 00:03:00 +08:00
Defaults to "standalone".
2021-05-10 20:37:38 +08:00
2021-08-18 20:41:57 +08:00
* LIVEBOOK_FILE_SYSTEM_1, LIVEBOOK_FILE_SYSTEM_2, ... - configures additional
file systems. Each variable should hold a configuration string, which must
be of the form: "s3 BUCKET_URL ACCESS_KEY_ID SECRET_ACCESS_KEY".
2021-06-25 00:03:00 +08:00
* LIVEBOOK_IP - sets the ip address to start the web application on.
Must be a valid IPv4 or IPv6 address.
2021-04-27 22:34:02 +08:00
2021-06-25 00:03:00 +08:00
* LIVEBOOK_PASSWORD - sets a password that must be used to access Livebook.
Must be at least 12 characters. Defaults to token authentication.
2021-04-15 21:50:29 +08:00
2021-06-25 00:03:00 +08:00
* LIVEBOOK_PORT - sets the port Livebook runs on. If you want multiple instances
2021-08-18 20:41:57 +08:00
to run on the same domain but different ports, you also need to set LIVEBOOK_SECRET_KEY_BASE.
2021-06-25 00:03:00 +08:00
Defaults to 8080.
2021-04-15 21:50:29 +08:00
2021-11-12 18:32:03 +08:00
* LIVEBOOK_ROOT_PATH - sets the root path to use for file selection. This does
not restrict access to upper directories unless the operating system user is
also restricted.
2021-04-15 21:50:29 +08:00
2021-06-25 00:03:00 +08:00
* LIVEBOOK_SECRET_KEY_BASE - sets a secret key that is used to sign and encrypt
the session and other payloads used by Livebook. Must be at least 64 characters
long and it can be generated by commands such as: 'openssl rand -base64 48'.
Defaults to a random secret on every boot.
2021-04-20 01:50:09 +08:00
2021-11-10 20:54:50 +08:00
* LIVEBOOK_TOKEN_ENABLED - controls whether token authentication is enabled.
Enabled by default unless `LIVEBOOK_PASSWORD` is set.
2021-05-21 08:01:54 +08:00
<!-- Environment variables -->
2021-07-31 16:09:21 +08:00
If running Livebook as a Docker image or an Elixir release, [the environment
2021-08-01 08:05:04 +08:00
variables used by Elixir releases are also available](
https://hexdocs.pm/mix/Mix.Tasks.Release.html#module-environment-variables).
2021-07-31 16:09:21 +08:00
The notables ones are `RELEASE_NODE` and `RELEASE_DISTRIBUTION` .
2021-11-05 01:50:53 +08:00
## Rendering notebooks as Markdown on GitHub
By default GitHub renders the `.livemd` notebooks as regular text files. Depending
on your use case and the target audience, you may find it useful to render notebooks
content as Markdown files instead. There is an option to override how a particular
file gets rendered on GitHub, so all you need to do is add a magic comment in every
such notebook:
```
2021-12-08 23:15:07 +08:00
<!-- vim: set syntax=markdown: -->
2021-11-05 01:50:53 +08:00
# My notebook
...
```
For more details see [the documentation ](https://github.com/github/linguist/blob/master/docs/overrides.md#using-emacs-or-vim-modelines ).
2021-05-20 05:30:53 +08:00
## Development
Livebook is primarily a Phoenix web application and can be setup as such:
```shell
2021-07-24 04:48:24 +08:00
git clone https://github.com/livebook-dev/livebook.git
2021-05-20 05:30:53 +08:00
cd livebook
2021-12-23 01:52:17 +08:00
mix dev.setup
2021-05-20 05:30:53 +08:00
# Run the Livebook server
mix phx.server
# To test escript
MIX_ENV=prod mix escript.build
./livebook server
```
2021-09-10 16:36:25 +08:00
## Sponsors
Livebook development is sponsored by:
< a href = "https://fly.io" > < img src = "https://fly.io/public/images/brand/logo.svg" width = "320" / > < / a >
2021-04-05 22:46:17 +08:00
## License
Copyright (C) 2021 Dashbit
2021-12-13 14:33:34 +08:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at [http://www.apache.org/licenses/LICENSE-2.0 ](http://www.apache.org/licenses/LICENSE-2.0 )
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.