Creating a behavior in elixir for an erlang library


I am using an erlang library( in my elixir code. I need to define the callback behavior of erlang library in elixir code. Are there any references to do the same and what is the syntax?

Srikanth V

It’s the same syntax as with an elixir behaviour.


In Elixir, you will use @behaviour behaviour_name attribute to specify that the current module adheres to that behaviour. behaviour_name is an atom, and if it’s an Erlang behaviour, you will need to use their lowecase name, i.e., @behaviour :gen_spider.

For callbacks, you just define the functions normally, just make sure they are public.

Also, as of newer Elixir version, you need to put @impl true before each callback functions to indicate that this is the implementation of the callback.

For a more general documentation, see

1 Like

Thanks @NobbZ and @sntran