Elixir has four ways to access functionality from other modules

alias

This allows us to the short version especially for nested name spaces.

alias MyApp.Accounts.User let us use just User rather than the full name.

It also allows us to define our own short names. e.g. alias MyApp.LattitudeAndLongitude as latlong

python supports the second use case via import module as shortname syntax

import

Import functionality from other modules. This is similar to python's import and from module import syntax.

In python, if you want to import a few functions, you use from module import func1, func2 etc. But if you want to use most but not all functions, you end up with a long from statement. Elixir provides only and except options to make such importing easier.

use

use adds the functionality from other modules into the current one.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
defmodule Module2 do
  def func2 do
    IP.puts "func2"
  end
end

defmodule Module1 do
  use Module2
end

Module1.func2

Here, func2 became available to Module1

python does not have similar functionality.

require

This is similar to use except for macros. It makes a macro from an external module available to the compiler at compile time.