# How to get all the symbols within a module?

**URL:** <https://discourse.julialang.org/t/how-to-get-all-the-symbols-within-a-module/31539>\
**Category:** General Usage\
**Tags:** module\
**Created:** [November 26, 2019, 5:56pm UTC](https://discourse.julialang.org/t/how-to-get-all-the-symbols-within-a-module/31539 "2019-11-26T17:56:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [November 26, 2019, 5:56pm UTC](https://discourse.julialang.org/t/how-to-get-all-the-symbols-within-a-module/31539/1 "2019-11-26T17:56:48Z")

</div>

is there a way to list all the symbols in a module?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [November 26, 2019, 5:59pm UTC](https://discourse.julialang.org/t/how-to-get-all-the-symbols-within-a-module/31539/2 "2019-11-26T17:59:17Z")

</div>

```julia
help?> names
  
  names(x::Module; all::Bool = false, imported::Bool = false)

  Get an array of the names exported by a Module, excluding deprecated
  names. If all is true, then the list also includes non-exported names
  defined in the module, deprecated names, and compiler-generated names.
  If imported is true, then names explicitly imported from other
  modules are also included.

  As a special case, all names defined in Main are considered "exported",
  since it is not idiomatic to explicitly export names from Main.

```

---

<div class="post-metadata">

**Author:** ![pontus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pontus/32/10438_2.png) [@pontus](https://discourse.julialang.org/u/pontus)\
**Post date:** [November 27, 2019, 1:13am UTC](https://discourse.julialang.org/t/how-to-get-all-the-symbols-within-a-module/31539/3 "2019-11-27T01:13:24Z")

</div>

Thanks for highlighting this @fredrikekre. Ran into this couple nights ago, was having trouble with `attrs` function in the `Gumbo.jl` module and wanted to see the functions list (before _finally_ finding the `names` function!). Had searched and adapted other solutions, such as this from 4 yrs ago on SO:  
[https://stackoverflow.com/questions/28731902/any-way-to-get-a-list-of-functions-defined-in-a-module](https://stackoverflow.com/questions/28731902/any-way-to-get-a-list-of-functions-defined-in-a-module)

```julia
using REPL
function functions_in(m::Module)
    s = string(m)
    out = REPL.REPLCompletions.completions(s * ".", length(s)+1)
    return out[1]
end
functions_in (generic function with 1 method)

```

this provided the result:

```julia
println("List length = ", length(functions_in(Gumbo)))
Base.print_matrix(stdout, functions_in(Gumbo))
# the following one-liner probably better than Base.print_matrix
# show(stdout, "text/plain", functions_in(Gumbo))
# Output:
List length = 29
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "@writeandcheck")      
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "CGumbo")              
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "HTMLDocument")        
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "HTMLElement")         
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "HTMLNode")            
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "HTMLText")            
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "InvalidHTMLException")
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "NullNode")            
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "attributes")          
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "attrs")               
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "breadthfirst")        
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "check_deps")          
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "children")            
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "document_from_gumbo") 
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "elem_tag")            
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "eval")                
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "getattr")             
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "gumbo_to_jl")         
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "gvector_to_jl")       
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "include")             
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "libgumbo")            
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "load_node")           
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "parsehtml")           
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "postorder")           
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "preorder")            
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "prettyprint")         
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "setattr!")            
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "tag")                 
 REPL.REPLCompletions.ModuleCompletion(Gumbo, "text")

```

interesting that the basic `names` function without setting `all=true` or `imported=true` provides:

```julia
names(Gumbo)
# Output:
17-element Array{Symbol,1}:
 :Gumbo       
 :HTMLDocument
 :HTMLElement 
 :HTMLNode    
 :HTMLText    
 :NullNode    
 :attrs       
 :breadthfirst
 :children    
 :getattr     
 :parsehtml   
 :postorder   
 :preorder    
 :prettyprint 
 :setattr!    
 :tag         
 :text        

```

5 more are shown with `imported=true`, and those five are unique to those added using the `all=true`, so the two modifiers provide independent additions to the base list. Setting both modifiers to true provides the full list of 61 for Gumbo:

```julia
show(stdout, "text/plain", names(Gumbo; all=true, imported=true)) 
# Output:
61-element Array{Symbol,1}:
 Symbol("##parsehtml#4")       
 Symbol("##print#1")           
 Symbol("##print#2")           
 Symbol("##print#3")           
 Symbol("#@writeandcheck")     
 Symbol("#attributes")         
 Symbol("#attrs")              
 Symbol("#check_deps")         
 Symbol("#document_from_gumbo")
 Symbol("#elem_tag")           
 Symbol("#eval")               
 Symbol("#getattr")            
 Symbol("#gumbo_to_jl")        
 Symbol("#gvector_to_jl")      
 Symbol("#include")            
 Symbol("#kw##parsehtml")      
 Symbol("#load_node")          
 Symbol("#parsehtml")          
 Symbol("#parsehtml#4")        
 Symbol("#prettyprint")        
 Symbol("#print#1")            
 Symbol("#print#2")            
 Symbol("#print#3")            
 Symbol("#setattr!")           
 Symbol("#tag")                
 Symbol("#text")               
 :(==)                         
 Symbol("@writeandcheck")      
 :AbstractTrees                
 :CGumbo                       
 :Gumbo                        
 :HTMLDocument                 
 :HTMLElement                  
 :HTMLNode                     
 :HTMLText                     
 :InvalidHTMLException         
 :Libdl                        
 :NullNode                     
 :attributes                   
 :attrs                        
 :breadthfirst                 
 :check_deps                   
 :children                     
 :document_from_gumbo          
 :elem_tag                     
 :eval                         
 :getattr                      
 :gumbo_to_jl                  
 :gvector_to_jl                
 :hash                         
 :include                      
 :isequal                      
 :libgumbo                     
 :load_node                    
 :parsehtml                    
 :postorder                    
 :preorder                     
 :prettyprint                  
 :setattr!                     
 :tag                          
 :text                         

```

I don’t understand yet how similar items such as `Symbol("#getattr")` and `Symbol("#getattr")` work or would be called differently.

Will have to look at the source more to see how `Symbol("#kw##parsehtml"`, `Symbol("#parsehtml")`, and `Symbol("#parsehtml#4")` are defined as well.

Thanks @Qiyamah for asking the question!

ps - it was nice to see in the Stack Overflow comments, updated info being provided such as:

```julia
You need to use names(M, true) to get unexported symbols. – Isaiah Norton Feb 26 '15 at 3:14
--
@Isaiah, great comment. I didn't know about that option. – spencerlyon2 Feb 26 '15 at 17:51
--
For Julia 1.2 @IsaiahNorton's useful comment should read names(M, all = true) – Philip Swannell Nov 19 at 13:38

```
