EScript, Application, or Distillery

When would you use escript, an application, or a distillery release?

The “application” I am referring to is in the accepted answer:

I assume each one is better for certain tasks, but I am lost as to when I should use what.

An escript is a command line tool. I was playing with an text adventure game where I wanted the user to interact with the Elixir code on the terminal. That was implemented as an escript. An escript contains everything you need to run the Elixir code so it could be used on other machines with the same architecture.

A distillery release is a packaged, stand-alone application. It includes the compiled beam files and assets, but not the source code. If you want to write a web application (with an HTML front end, and or a REST/JSON API, and/or a GraphQL API, etc.) and put it into production by running it on a VM, or in a Kubernetes cluster, you might package it up using distillery and run it that way. Distillery also adds handy tools to the resulting package that allow you to start and stop the application, get remote shells on the application and things like that. A distillery release may, or may not, contain the Erlang runtime system (the VM).

You would run your code using mix during development - and some people run their applications in production using Mix. If you create an application as mentioned in that Stackoverflow answer it is simply because want to designate a module to give you a starting point. An OTP Application is a collection of modules that can be loaded and executed separately, can have dependencies on other applications, and can be bundled up using tools like distillery.

Another execution model that you didn’t mention was simply an Elixir script (usually in a file given with a .exs extension). I create those for small, one-off tasks like combing through the files in a directory and applying some simple logic to processing them. In that case I don’t need the formality of a mix project and a full blown escript. They are also used to create the unit tests in an Elixir project.


Maybe this is the right place to bring this up… Will the upcoming mix release feature be similar to distillery? If so, will it completely replace it?

As I understand it the tools are based in the work of distillery. There is an ElixirConf 2018 presentation about the topic:


Wow, wonderful answer, that really cleared things up for me. Thank you so much!